mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 12:45:00 +00:00
optimize<AutoUpdate>: move Launcher.CheckUpdate to App.CheckUpdate; limitation for checking times
This commit is contained in:
parent
ae1224ded3
commit
4a334107e1
3 changed files with 46 additions and 38 deletions
|
@ -2,6 +2,11 @@ using Microsoft.Win32;
|
|||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace SourceGit {
|
||||
|
@ -105,8 +110,15 @@ namespace SourceGit {
|
|||
}
|
||||
|
||||
// Show main window
|
||||
Current.MainWindow = new UI.Launcher();
|
||||
Current.MainWindow.Show();
|
||||
MainWindow = new UI.Launcher();
|
||||
MainWindow.Show();
|
||||
|
||||
// Check for update.
|
||||
if (Setting.CheckUpdate && Setting.LastCheckUpdate != DateTime.Now.DayOfYear) {
|
||||
Setting.LastCheckUpdate = DateTime.Now.DayOfYear;
|
||||
SaveSetting();
|
||||
Task.Run(CheckUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -116,7 +128,7 @@ namespace SourceGit {
|
|||
/// <param name="e"></param>
|
||||
private void OnAppDeactivated(object sender, EventArgs e) {
|
||||
GC.Collect();
|
||||
SaveSetting();
|
||||
SaveSetting();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -142,5 +154,32 @@ namespace SourceGit {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check for update.
|
||||
/// </summary>
|
||||
private void CheckUpdate() {
|
||||
try {
|
||||
var web = new WebClient() { Encoding = Encoding.UTF8 };
|
||||
var raw = web.DownloadString("https://gitee.com/api/v5/repos/sourcegit/SourceGit/releases/latest");
|
||||
var ver = JsonConvert.DeserializeObject<Git.Version>(raw);
|
||||
var cur = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
|
||||
var matches = Regex.Match(ver.TagName, @"^v(\d+)\.(\d+).*");
|
||||
if (!matches.Success) return;
|
||||
|
||||
var major = int.Parse(matches.Groups[1].Value);
|
||||
var minor = int.Parse(matches.Groups[2].Value);
|
||||
if (major > cur.Major || (major == cur.Major && minor > cur.Minor)) {
|
||||
Dispatcher.Invoke(() => {
|
||||
var dialog = new UI.UpdateAvailable(ver);
|
||||
dialog.Owner = MainWindow;
|
||||
dialog.ShowDialog();
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
// IGNORE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue