From ee395a61d58033e0c58ab7620fd9215acfb02cd9 Mon Sep 17 00:00:00 2001 From: liufei Date: Tue, 20 Jul 2021 13:37:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.config | 10 ++--- .../UserControls/Config/AboutControl.xaml.cs | 2 +- Control/Windows/UpdateWindow.xaml | 16 +++++++ Control/Windows/UpdateWindow.xaml.cs | 27 ++++++++++++ GeekDesk.csproj | 9 +++- MainWindow.xaml.cs | 2 + Thread/UpdateThread.cs | 44 +++++++++++++++++-- Update.json => index.html | 0 8 files changed, 99 insertions(+), 11 deletions(-) create mode 100644 Control/Windows/UpdateWindow.xaml create mode 100644 Control/Windows/UpdateWindow.xaml.cs rename Update.json => index.html (100%) diff --git a/App.config b/App.config index 22df80d..881791c 100644 --- a/App.config +++ b/App.config @@ -12,10 +12,10 @@ - - - - - + + + + + diff --git a/Control/UserControls/Config/AboutControl.xaml.cs b/Control/UserControls/Config/AboutControl.xaml.cs index 825b6f3..df266f3 100644 --- a/Control/UserControls/Config/AboutControl.xaml.cs +++ b/Control/UserControls/Config/AboutControl.xaml.cs @@ -26,7 +26,7 @@ namespace GeekDesk.Control.UserControls.Config public AboutControl() { InitializeComponent(); - AppInfo.Text += ConfigurationManager.AppSettings["version"]; + AppInfo.Text += ConfigurationManager.AppSettings["Version"]; PublicWeChat.Source = ImageUtil.Base64ToBitmapImage(Constants.PUBLIC_WE_CHAT_IMG_BASE64); WeChatCode.Source = ImageUtil.Base64ToBitmapImage(Constants.WE_CHAT_CODE_IMG_BASE64); ZFBCode.Source = ImageUtil.Base64ToBitmapImage(Constants.ZFB_CODE_IMG_BASE64); diff --git a/Control/Windows/UpdateWindow.xaml b/Control/Windows/UpdateWindow.xaml new file mode 100644 index 0000000..48fe6b7 --- /dev/null +++ b/Control/Windows/UpdateWindow.xaml @@ -0,0 +1,16 @@ + + + + + + diff --git a/Control/Windows/UpdateWindow.xaml.cs b/Control/Windows/UpdateWindow.xaml.cs new file mode 100644 index 0000000..985ebb7 --- /dev/null +++ b/Control/Windows/UpdateWindow.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace GeekDesk.Control.Windows +{ + /// + /// UpdateWindow.xaml 的交互逻辑 + /// + public partial class UpdateWindow : Window + { + public UpdateWindow() + { + InitializeComponent(); + } + } +} diff --git a/GeekDesk.csproj b/GeekDesk.csproj index 1978f23..0072f1e 100644 --- a/GeekDesk.csproj +++ b/GeekDesk.csproj @@ -163,6 +163,9 @@ IconfontWindow.xaml + + UpdateWindow.xaml + @@ -254,6 +257,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + MSBuild:Compile Designer @@ -290,7 +297,7 @@ Resources.Designer.cs - + SettingsSingleFileGenerator diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 51fa335..01c9971 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -4,6 +4,7 @@ using GeekDesk.Control; using GeekDesk.Control.UserControls.Config; using GeekDesk.Control.Windows; using GeekDesk.Task; +using GeekDesk.Thread; using GeekDesk.Util; using GeekDesk.ViewModel; using GlobalHotKey; @@ -45,6 +46,7 @@ namespace GeekDesk this.Loaded += Window_Loaded; this.SizeChanged += MainWindow_Resize; ToDoTask.BackLogCheck(); + UpdateThread.Update(); } private void LoadData() diff --git a/Thread/UpdateThread.cs b/Thread/UpdateThread.cs index 92ff28a..7190959 100644 --- a/Thread/UpdateThread.cs +++ b/Thread/UpdateThread.cs @@ -1,5 +1,10 @@ -using System; +using GeekDesk.Constant; +using GeekDesk.Util; +using GeekDesk.ViewModel; +using Newtonsoft.Json.Linq; +using System; using System.Collections.Generic; +using System.Configuration; using System.Linq; using System.Text; using System.Threading; @@ -9,16 +14,47 @@ namespace GeekDesk.Thread { public class UpdateThread { + private static AppConfig appConfig = MainWindow.appData.AppConfig; public static void Update() { - System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(updateApp)); - t.IsBackground = true; + System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(UpdateApp)) + { + IsBackground = true + }; t.Start(); } - private static void updateApp() + private static void UpdateApp() { + try + { + string updateUrl; + string nowVersion = ConfigurationManager.AppSettings["Version"]; + 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)) + { + JObject jo = JObject.Parse(updateInfo); + string onlineVersion = jo["version"].ToString(); + if (onlineVersion.CompareTo(nowVersion) > 0) + { + //检测到版本更新 + } + } + } catch (Exception) + { + } + + } } } diff --git a/Update.json b/index.html similarity index 100% rename from Update.json rename to index.html