♻️ 将检测更新改为任务模式

This commit is contained in:
BookerLiu
2024-08-08 11:16:22 +08:00
parent 39251b66f6
commit 60238ddb17
5 changed files with 34 additions and 33 deletions

View File

@@ -66,7 +66,7 @@
<add key="GiteeUrl" value="https://gitee.com/BookerLiu/GeekDesk/tree/master" /> <add key="GiteeUrl" value="https://gitee.com/BookerLiu/GeekDesk/tree/master" />
<add key="GitHubUpdateUrl" value="https://raw.githubusercontent.com/BookerLiu/GeekDesk/master/Update.json" /> <add key="GitHubUpdateUrl" value="https://raw.githubusercontent.com/BookerLiu/GeekDesk/master/Update.json" />
<add key="GiteeUpdateUrl" value="https://gitee.com/BookerLiu/GeekDesk/raw/master/Update.json" /> <add key="GiteeUpdateUrl" value="https://gitee.com/BookerLiu/GeekDesk/raw/master/Update.json" />
<!--<add key="GiteeUpdateUrl" value="file:///D:/WorkSpace/workspace-VS/GeekDesk/Update.json" />--> <!--<add key="GiteeUpdateUrl" value="file:///D:/WorkSpace/VS/GeekDesk/Update.json" />-->
<add key="ClientSettingsProvider.ServiceUri" value="" /> <add key="ClientSettingsProvider.ServiceUri" value="" />
<add key="CustomIconTeachUrl" value="https://mp.weixin.qq.com/s/LxoHAekho9HBVl4FRw_Law" /> <add key="CustomIconTeachUrl" value="https://mp.weixin.qq.com/s/LxoHAekho9HBVl4FRw_Law" />
<add key="ShowPublicWeChat" value="Y" /> <add key="ShowPublicWeChat" value="Y" />

View File

@@ -294,7 +294,7 @@
<Compile Include="Task\ToDoTask.cs" /> <Compile Include="Task\ToDoTask.cs" />
<Compile Include="MyThread\MouseHookThread.cs" /> <Compile Include="MyThread\MouseHookThread.cs" />
<Compile Include="MyThread\DispatcherBuild.cs" /> <Compile Include="MyThread\DispatcherBuild.cs" />
<Compile Include="MyThread\UpdateThread.cs" /> <Compile Include="Task\UpdateTask.cs" />
<Compile Include="Util\AeroGlassHelper.cs" /> <Compile Include="Util\AeroGlassHelper.cs" />
<Compile Include="Util\BGSettingUtil.cs" /> <Compile Include="Util\BGSettingUtil.cs" />
<Compile Include="Util\BlurGlassUtil.cs" /> <Compile Include="Util\BlurGlassUtil.cs" />

View File

@@ -366,8 +366,8 @@ namespace GeekDesk
FileWatcher.EnableLinkMenuWatcher(appData); FileWatcher.EnableLinkMenuWatcher(appData);
//更新线程开启 检测更新 //更新任务开启 检测更新
UpdateThread.Update(); UpdateTask.Start();
//建立相对路径 //建立相对路径
RelativePathThread.MakeRelativePath(); RelativePathThread.MakeRelativePath();

View File

@@ -4,47 +4,47 @@ using GeekDesk.Util;
using GeekDesk.ViewModel; using GeekDesk.ViewModel;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic;
using System.Configuration; using System.Configuration;
using System.Threading; using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GeekDesk.MyThread namespace GeekDesk.Task
{ {
public class UpdateThread internal class UpdateTask
{ {
private static AppConfig appConfig = MainWindow.appData.AppConfig; private static AppConfig appConfig = MainWindow.appData.AppConfig;
public static void Update() public static void Start()
{ {
System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(UpdateApp)) System.Timers.Timer timer = new System.Timers.Timer
{ {
IsBackground = true Enabled = true,
Interval = 60 * 1000 * 60 * 12, //60秒 * 60分钟 * 12
//Interval = 6000,
}; };
t.Start(); timer.Start();
timer.Elapsed += Timer_Elapsed; ;
} }
private static void UpdateApp() private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
try try
{ {
string updateUrl = ConfigurationManager.AppSettings["GiteeUpdateUrl"];
//等待1分钟后再检查更新 有的网络连接过慢
int sleepTime = 60 * 1000;
if (Constants.DEV)
{
sleepTime = 1;
}
System.Threading.Thread.Sleep(sleepTime);
string updateUrl;
string nowVersion = ConfigurationManager.AppSettings["Version"]; string nowVersion = ConfigurationManager.AppSettings["Version"];
switch (appConfig.UpdateType) if (appConfig != null)
{ {
case UpdateType.GitHub: switch (appConfig.UpdateType)
updateUrl = ConfigurationManager.AppSettings["GitHubUpdateUrl"]; {
break; case UpdateType.GitHub:
default: updateUrl = ConfigurationManager.AppSettings["GitHubUpdateUrl"];
updateUrl = ConfigurationManager.AppSettings["GiteeUpdateUrl"]; break;
break; default:
updateUrl = ConfigurationManager.AppSettings["GiteeUpdateUrl"];
break;
}
} }
string updateInfo = HttpUtil.Get(updateUrl); string updateInfo = HttpUtil.Get(updateUrl);
if (!StringUtil.IsEmpty(updateInfo)) if (!StringUtil.IsEmpty(updateInfo))
@@ -63,9 +63,10 @@ namespace GeekDesk.MyThread
HttpUtil.Get(statisticUrl); HttpUtil.Get(statisticUrl);
} }
} }
} catch (Exception){} }
catch (Exception) { }
string onlineVersion = jo["version"].ToString(); string onlineVersion = jo["version"].ToString();
if (onlineVersion.CompareTo(nowVersion) > 0) if (onlineVersion.CompareTo(nowVersion) > 0)

View File

@@ -2,7 +2,7 @@
"title": "GeekDesk版本更新", "title": "GeekDesk版本更新",
"subTitle": "V2.5.15", "subTitle": "V2.5.15",
"msgTitle": "本次更新内容如下", "msgTitle": "本次更新内容如下",
"msg": "['鸽了挺久, 我终于又来更新了, 废话不多说, 看下本次更新内容', '增加多文件备份, 数据文件损坏会自动寻找最近的一次备份数据, 不用担心数据文件损坏了, 备份数据默认为最近7天, 可以通过打开根目录下GeekDesk.exe.config, 找到BakDays修改', '修复高分屏缩放导致的鼠标追随bug', 'UI假死的情况, 由于并不是每个用户都出现这个bug, 这次做了尝试性修复, 各位可以看下是否还会出现切换菜单出现不会出现图标的情况']", "msg": "['鸽了挺久, 我终于又来更新了, 废话不多说, 看下本次更新内容, 没有点star的记得给我star哦^_^', '增加多文件备份, 数据文件损坏会自动寻找最近的一次备份数据, 不用担心数据文件损坏了, 备份数据默认为最近7天, 可以通过打开根目录下GeekDesk.exe.config, 找到BakDays修改', '修复多块屏幕下高分屏缩放比例不同导致的鼠标追随bug, 显示时可以正确的追随鼠标位置了', '修复多块屏幕下高分屏缩放比例不同导致的拾色器bug, 可以正常拾色了', '另外UI假死的情况, 由于并不是每个用户都出现这个bug, 这次做了尝试性修复, 各位可以看下是否还会出现切换菜单出现不会出现图标的情况', '其它优化']",
"githubUrl": "https://github.com/BookerLiu/GeekDesk/releases", "githubUrl": "https://github.com/BookerLiu/GeekDesk/releases",
"giteeUrl": "https://gitee.com/BookerLiu/GeekDesk/releases", "giteeUrl": "https://gitee.com/BookerLiu/GeekDesk/releases",
"statisticUrl": "http://43.138.23.39:8989/bookerService/geekDeskController/userCountStatistic", "statisticUrl": "http://43.138.23.39:8989/bookerService/geekDeskController/userCountStatistic",