Browse Source

自动更新

liufei 4 năm trước cách đây
mục cha
commit
ee395a61d5

+ 5 - 5
App.config

@@ -12,10 +12,10 @@
     </assemblyBinding>
   </runtime>
 	<appSettings>
-		<add key="version" value="1.0-beta"/>
-		<add key="GitHubUrl" value="1.0 beta"/>
-		<add key="MYUrl" value="1.0 beta"/>
-		<add key="GitHubUpdateUrl" value="1.0 beta"/>
-		<add key="MYUpdateUrl" value="1.0 beta"/>
+		<add key="Version" value="1.0-beta"/>
+		<add key="GitHubUrl" value="https://github.com/Demo-Liu/GeekDesk"/>
+		<add key="GiteeUrl" value="https://gitee.com/demo_liu/GeekDesk/tree/master"/>
+		<add key="GitHubUpdateUrl" value="https://github.com/Demo-Liu/GeekDesk/blob/master/Update.json"/>
+		<add key="GiteeUpdateUrl" value="https://gitee.com/demo_liu/GeekDesk/blob/master/Update.json"/>
 	</appSettings>
 </configuration>

+ 1 - 1
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);

+ 16 - 0
Control/Windows/UpdateWindow.xaml

@@ -0,0 +1,16 @@
+<Window x:Class="GeekDesk.Control.Windows.UpdateWindow"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:local="clr-namespace:GeekDesk.Control.Windows"
+        mc:Ignorable="d"
+        Title="UpdateWindow" Height="450" Width="800"
+        WindowStyle="None"
+        AllowsTransparency="True"
+        Background="Transparent" ShowInTaskbar="False">
+    <Border Background="White">
+        
+        
+    </Border>
+</Window>

+ 27 - 0
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
+{
+    /// <summary>
+    /// UpdateWindow.xaml 的交互逻辑
+    /// </summary>
+    public partial class UpdateWindow : Window
+    {
+        public UpdateWindow()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 8 - 1
GeekDesk.csproj

@@ -163,6 +163,9 @@
     <Compile Include="Control\Windows\IconfontWindow.xaml.cs">
       <DependentUpon>IconfontWindow.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Control\Windows\UpdateWindow.xaml.cs">
+      <DependentUpon>UpdateWindow.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Converts\DoubleToGridLength.cs" />
     <Compile Include="Converts\IntToCornerRadius.cs" />
     <Compile Include="Converts\OpcityConvert.cs" />
@@ -254,6 +257,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Control\Windows\UpdateWindow.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="MainWindow.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
@@ -290,7 +297,7 @@
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
     </EmbeddedResource>
     <Resource Include="Resource\Iconfont\iconfont.json" />
-    <Resource Include="Update.json" />
+    <Content Include="index.html" />
     <None Include="packages.config" />
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>

+ 2 - 0
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()

+ 40 - 4
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)
+            {
 
+            }
+            
+            
         }
     }
 }

+ 0 - 0
Update.json → index.html