Files
GeekDesk/Thread/UpdateThread.cs

69 lines
2.1 KiB
C#
Raw Permalink Normal View History

2021-07-20 13:37:11 +08:00
using GeekDesk.Constant;
2021-07-20 17:30:12 +08:00
using GeekDesk.Control.Windows;
2021-07-20 13:37:11 +08:00
using GeekDesk.Util;
using GeekDesk.ViewModel;
using Newtonsoft.Json.Linq;
using System;
2021-07-16 17:34:16 +08:00
using System.Collections.Generic;
2021-07-20 13:37:11 +08:00
using System.Configuration;
2021-07-16 17:34:16 +08:00
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
2021-07-20 17:30:12 +08:00
using System.Windows;
2021-07-16 17:34:16 +08:00
namespace GeekDesk.Thread
{
public class UpdateThread
{
2021-07-20 13:37:11 +08:00
private static AppConfig appConfig = MainWindow.appData.AppConfig;
2021-07-16 17:34:16 +08:00
public static void Update()
{
2021-07-20 13:37:11 +08:00
System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(UpdateApp))
{
IsBackground = true
};
2021-07-16 17:34:16 +08:00
t.Start();
}
2021-07-20 13:37:11 +08:00
private static void UpdateApp()
2021-07-16 17:34:16 +08:00
{
2021-07-20 13:37:11 +08:00
try
{
2021-07-29 17:09:25 +08:00
//等待1分钟后再检查更新 有的网络连接过慢
System.Threading.Thread.Sleep(60 * 1000);
2021-07-29 17:09:25 +08:00
2021-07-20 13:37:11 +08:00
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)
2021-07-20 13:37:11 +08:00
{
2021-07-20 17:30:12 +08:00
App.Current.Dispatcher.Invoke((Action)(() =>
{
//检测到版本更新
UpdateWindow.Show(jo);
}));
2021-07-20 13:37:11 +08:00
}
}
2021-07-20 17:30:12 +08:00
} catch (Exception e)
2021-07-20 13:37:11 +08:00
{
2021-12-22 13:14:54 +08:00
LogUtil.WriteErrorLog(e, "检测更新失败!");
2021-07-20 13:37:11 +08:00
}
2021-07-16 17:34:16 +08:00
}
}
}