自动更新

This commit is contained in:
liufei
2021-07-20 13:37:11 +08:00
parent 67eae85a0b
commit ee395a61d5
8 changed files with 99 additions and 11 deletions

View File

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

View File

@@ -26,7 +26,7 @@ namespace GeekDesk.Control.UserControls.Config
public AboutControl() public AboutControl()
{ {
InitializeComponent(); InitializeComponent();
AppInfo.Text += ConfigurationManager.AppSettings["version"]; AppInfo.Text += ConfigurationManager.AppSettings["Version"];
PublicWeChat.Source = ImageUtil.Base64ToBitmapImage(Constants.PUBLIC_WE_CHAT_IMG_BASE64); PublicWeChat.Source = ImageUtil.Base64ToBitmapImage(Constants.PUBLIC_WE_CHAT_IMG_BASE64);
WeChatCode.Source = ImageUtil.Base64ToBitmapImage(Constants.WE_CHAT_CODE_IMG_BASE64); WeChatCode.Source = ImageUtil.Base64ToBitmapImage(Constants.WE_CHAT_CODE_IMG_BASE64);
ZFBCode.Source = ImageUtil.Base64ToBitmapImage(Constants.ZFB_CODE_IMG_BASE64); ZFBCode.Source = ImageUtil.Base64ToBitmapImage(Constants.ZFB_CODE_IMG_BASE64);

View File

@@ -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>

View File

@@ -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();
}
}
}

View File

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

View File

@@ -4,6 +4,7 @@ using GeekDesk.Control;
using GeekDesk.Control.UserControls.Config; using GeekDesk.Control.UserControls.Config;
using GeekDesk.Control.Windows; using GeekDesk.Control.Windows;
using GeekDesk.Task; using GeekDesk.Task;
using GeekDesk.Thread;
using GeekDesk.Util; using GeekDesk.Util;
using GeekDesk.ViewModel; using GeekDesk.ViewModel;
using GlobalHotKey; using GlobalHotKey;
@@ -45,6 +46,7 @@ namespace GeekDesk
this.Loaded += Window_Loaded; this.Loaded += Window_Loaded;
this.SizeChanged += MainWindow_Resize; this.SizeChanged += MainWindow_Resize;
ToDoTask.BackLogCheck(); ToDoTask.BackLogCheck();
UpdateThread.Update();
} }
private void LoadData() private void LoadData()

View File

@@ -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.Collections.Generic;
using System.Configuration;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
@@ -9,16 +14,47 @@ namespace GeekDesk.Thread
{ {
public class UpdateThread public class UpdateThread
{ {
private static AppConfig appConfig = MainWindow.appData.AppConfig;
public static void Update() public static void Update()
{ {
System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(updateApp)); System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(UpdateApp))
t.IsBackground = true; {
IsBackground = true
};
t.Start(); 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)
{
}
} }
} }
} }