Files
GeekDesk/Task/UpdateTask.cs

89 lines
3.0 KiB
C#
Raw 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;
using System.Collections.Generic;
2021-07-20 13:37:11 +08:00
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2021-07-16 17:34:16 +08:00
namespace GeekDesk.Task
2021-07-16 17:34:16 +08:00
{
internal class UpdateTask
2021-07-16 17:34:16 +08:00
{
2021-07-20 13:37:11 +08:00
private static AppConfig appConfig = MainWindow.appData.AppConfig;
public static void Start()
2021-07-16 17:34:16 +08:00
{
System.Timers.Timer timer = new System.Timers.Timer
2021-07-20 13:37:11 +08:00
{
Enabled = true,
2025-03-10 10:28:11 +08:00
Interval = 60 * 1000 * 60 * 12, //60秒 * 60 * 12 12小时触发一次
//Interval = 6000,
2021-07-20 13:37:11 +08:00
};
timer.Start();
timer.Elapsed += Timer_Elapsed; ;
2021-07-16 17:34:16 +08:00
}
private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
2021-07-16 17:34:16 +08:00
{
2021-07-20 13:37:11 +08:00
try
{
string updateUrl = ConfigurationManager.AppSettings["GiteeUpdateUrl"];
2021-07-20 13:37:11 +08:00
string nowVersion = ConfigurationManager.AppSettings["Version"];
if (appConfig != null)
2021-07-20 13:37:11 +08:00
{
switch (appConfig.UpdateType)
{
case UpdateType.GitHub:
updateUrl = ConfigurationManager.AppSettings["GitHubUpdateUrl"];
break;
default:
updateUrl = ConfigurationManager.AppSettings["GiteeUpdateUrl"];
break;
}
2021-07-20 13:37:11 +08:00
}
string updateInfo = HttpUtil.Get(updateUrl);
if (!StringUtil.IsEmpty(updateInfo))
{
JObject jo = JObject.Parse(updateInfo);
2023-04-19 22:19:44 +08:00
2023-04-21 14:16:58 +08:00
try
2023-04-19 22:19:44 +08:00
{
if (jo["statisticUrl"] != null)
2023-04-21 14:16:58 +08:00
{
string statisticUrl = jo["statisticUrl"].ToString();
if (!string.IsNullOrEmpty(statisticUrl))
{
//用户统计 只通过uuid统计用户数量 不收集任何信息
statisticUrl += "?uuid=" + CommonCode.GetUniqueUUID();
HttpUtil.Get(statisticUrl);
}
2023-04-21 14:16:58 +08:00
}
}
catch (Exception) { }
2023-04-21 14:16:58 +08:00
2023-04-19 22:19:44 +08:00
2021-07-20 13:37:11 +08:00
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
}
}
}
catch (Exception ex)
2021-07-20 13:37:11 +08:00
{
2022-01-09 17:36:15 +08:00
LogUtil.WriteErrorLog(ex, "获取更新失败!");
2021-07-20 13:37:11 +08:00
}
2021-07-16 17:34:16 +08:00
}
}
}