mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +02:00
Add manually check updates option
1. manually check updates 2. refactoring get http request to use async 3. remove some generic exception catch 4. remove unused code
This commit is contained in:
@@ -4,6 +4,8 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
@@ -11,16 +13,21 @@ using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using Microsoft.Win32;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NHotkey;
|
||||
using NHotkey.Wpf;
|
||||
using Squirrel;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Core.Updater;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Helper;
|
||||
using Wox.Infrastructure.Hotkey;
|
||||
using Wox.Infrastructure.Http;
|
||||
using Wox.Infrastructure.Image;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Plugin;
|
||||
using Wox.ViewModel;
|
||||
using Application = System.Windows.Forms.Application;
|
||||
@@ -56,7 +63,7 @@ namespace Wox
|
||||
_settings.ProxyEnabled = ToggleProxy.IsChecked ?? false;
|
||||
}
|
||||
|
||||
private void Setting_Loaded(object sender, RoutedEventArgs ev)
|
||||
private async void Setting_Loaded(object sender, RoutedEventArgs ev)
|
||||
{
|
||||
#region General
|
||||
cbHideWhenDeactive.Checked += (o, e) =>
|
||||
@@ -136,11 +143,10 @@ namespace Wox
|
||||
#endregion
|
||||
|
||||
#region About
|
||||
|
||||
tbVersion.Text = UpdaterManager.Instance.CurrentVersion.ToString();
|
||||
string activateTimes = string.Format(InternationalizationManager.Instance.GetTranslation("about_activate_times"),
|
||||
_settings.ActivateTimes);
|
||||
tbActivatedTimes.Text = activateTimes;
|
||||
string activateTimes = string.Format(
|
||||
InternationalizationManager.Instance.GetTranslation("about_activate_times"), _settings.ActivateTimes);
|
||||
ActivatedTimes.Text = activateTimes;
|
||||
tbVersion.Text = Infrastructure.Wox.Version;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -806,7 +812,7 @@ namespace Wox
|
||||
|
||||
private void tbWebsite_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
Process.Start("http://www.getwox.com");
|
||||
Process.Start(Infrastructure.Wox.Github);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -820,5 +826,76 @@ namespace Wox
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnCheckUpdates(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var version = await NewVersion();
|
||||
if (!string.IsNullOrEmpty(version))
|
||||
{
|
||||
var newVersion = NumericVersion(version);
|
||||
var oldVersion = NumericVersion(Infrastructure.Wox.Version);
|
||||
if (newVersion > oldVersion)
|
||||
{
|
||||
NewVersionTips.Text = string.Format(NewVersionTips.Text, version);
|
||||
NewVersionTips.Visibility = Visibility.Visible;
|
||||
using (var updater = await UpdateManager.GitHubUpdateManager(Infrastructure.Wox.Github, prerelease: true))
|
||||
{
|
||||
// todo 5/9 the return value of UpdateApp() is NULL, fucking useless!
|
||||
await updater.UpdateApp();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<string> NewVersion()
|
||||
{
|
||||
const string githubAPI = @"https://api.github.com/repos/wox-launcher/wox/releases/latest";
|
||||
var response = await HttpRequest.Get(githubAPI, HttpProxy.Instance);
|
||||
|
||||
if (!string.IsNullOrEmpty(response))
|
||||
{
|
||||
JContainer json;
|
||||
try
|
||||
{
|
||||
json = (JContainer) JsonConvert.DeserializeObject(response);
|
||||
}
|
||||
catch (JsonSerializationException e)
|
||||
{
|
||||
Log.Error(e);
|
||||
return string.Empty;
|
||||
}
|
||||
var version = json?["tag_name"]?.ToString();
|
||||
if (!string.IsNullOrEmpty(version))
|
||||
{
|
||||
return version;
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private
|
||||
int NumericVersion(string version)
|
||||
{
|
||||
var newVersion = version.Replace("v", ".").Replace(".", "").Replace("*", "");
|
||||
return int.Parse(newVersion);
|
||||
}
|
||||
private void OnRequestNavigate(object sender, RequestNavigateEventArgs e)
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user