Răsfoiți Sursa

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

BookerLiu 1 an în urmă
părinte
comite
60238ddb17
5 a modificat fișierele cu 34 adăugiri și 33 ștergeri
  1. 1 1
      App.config
  2. 1 1
      GeekDesk.csproj
  3. 2 2
      MainWindow.xaml.cs
  4. 29 28
      Task/UpdateTask.cs
  5. 1 1
      Update.json

+ 1 - 1
App.config

@@ -66,7 +66,7 @@
 		<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="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="CustomIconTeachUrl" value="https://mp.weixin.qq.com/s/LxoHAekho9HBVl4FRw_Law" />
 		<add key="ShowPublicWeChat" value="Y" />

+ 1 - 1
GeekDesk.csproj

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

+ 2 - 2
MainWindow.xaml.cs

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

+ 29 - 28
MyThread/UpdateThread.cs → Task/UpdateTask.cs

@@ -4,47 +4,47 @@ using GeekDesk.Util;
 using GeekDesk.ViewModel;
 using Newtonsoft.Json.Linq;
 using System;
+using System.Collections.Generic;
 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;
-        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
             {
-
-                //等待1分钟后再检查更新  有的网络连接过慢
-                int sleepTime = 60 * 1000;
-                if (Constants.DEV)
-                {
-                    sleepTime = 1;
-                }
-
-                System.Threading.Thread.Sleep(sleepTime);
-
-                string updateUrl;
+                string updateUrl = ConfigurationManager.AppSettings["GiteeUpdateUrl"];
                 string nowVersion = ConfigurationManager.AppSettings["Version"];
-                switch (appConfig.UpdateType)
+                if (appConfig != null)
                 {
-                    case UpdateType.GitHub:
-                        updateUrl = ConfigurationManager.AppSettings["GitHubUpdateUrl"];
-                        break;
-                    default:
-                        updateUrl = ConfigurationManager.AppSettings["GiteeUpdateUrl"];
-                        break;
+                    switch (appConfig.UpdateType)
+                    {
+                        case UpdateType.GitHub:
+                            updateUrl = ConfigurationManager.AppSettings["GitHubUpdateUrl"];
+                            break;
+                        default:
+                            updateUrl = ConfigurationManager.AppSettings["GiteeUpdateUrl"];
+                            break;
+                    }
                 }
                 string updateInfo = HttpUtil.Get(updateUrl);
                 if (!StringUtil.IsEmpty(updateInfo))
@@ -63,9 +63,10 @@ namespace GeekDesk.MyThread
                                 HttpUtil.Get(statisticUrl);
                             }
                         }
-                    } catch (Exception){}
+                    }
+                    catch (Exception) { }
+
 
-                   
 
                     string onlineVersion = jo["version"].ToString();
                     if (onlineVersion.CompareTo(nowVersion) > 0)

+ 1 - 1
Update.json

@@ -2,7 +2,7 @@
 	"title": "GeekDesk版本更新",
 	"subTitle": "V2.5.15",
 	"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",
 	"giteeUrl": "https://gitee.com/BookerLiu/GeekDesk/releases",
 	"statisticUrl": "http://43.138.23.39:8989/bookerService/geekDeskController/userCountStatistic",