mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-13 19:19:23 +08:00
Merge update logic #1266
This commit is contained in:
parent
e66f7a206e
commit
c41035058a
@ -1,12 +1,9 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Squirrel;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Infrastructure;
|
||||
@ -64,59 +61,7 @@ namespace Wox.Core
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static async Task<string> NewVersion()
|
||||
{
|
||||
const string githubAPI = @"https://api.github.com/repos/wox-launcher/wox/releases/latest";
|
||||
|
||||
string response;
|
||||
try
|
||||
{
|
||||
response = await Http.Get(githubAPI);
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
Log.Exception("|Updater.NewVersion|Can't connect to github api to check new version", e);
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(response))
|
||||
{
|
||||
JContainer json;
|
||||
try
|
||||
{
|
||||
json = (JContainer)JsonConvert.DeserializeObject(response);
|
||||
}
|
||||
catch (JsonSerializationException e)
|
||||
{
|
||||
Log.Exception("|Updater.NewVersion|can't parse response", e);
|
||||
return string.Empty;
|
||||
}
|
||||
var version = json?["tag_name"]?.ToString();
|
||||
if (!string.IsNullOrEmpty(version))
|
||||
{
|
||||
return version;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn("|Updater.NewVersion|Can't find tag_name from Github API response");
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn("|Updater.NewVersion|Can't get response from Github API");
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static int NumericVersion(string version)
|
||||
{
|
||||
var newVersion = version.Replace("v", ".").Replace(".", "").Replace("*", "");
|
||||
return int.Parse(newVersion);
|
||||
}
|
||||
|
||||
public static string NewVersinoTips(string version)
|
||||
private static string NewVersinoTips(string version)
|
||||
{
|
||||
var translater = InternationalizationManager.Instance;
|
||||
var tips = string.Format(translater.GetTranslation("newVersionTips"), version);
|
||||
|
@ -384,8 +384,6 @@
|
||||
<Button Grid.Row="4" Grid.Column="0"
|
||||
Content="{DynamicResource checkUpdates}" Click="OnCheckUpdates"
|
||||
HorizontalAlignment="Left" Margin="10 10 10 10" />
|
||||
<TextBlock Grid.Row="4" Grid.Column="1" Text="{Binding NewVersionTips}"
|
||||
HorizontalAlignment="Left" Visibility="{Binding NewVersionTipsVisibility}" />
|
||||
</Grid>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
|
@ -306,17 +306,7 @@ namespace Wox
|
||||
|
||||
private async void OnCheckUpdates(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var version = await Updater.NewVersion();
|
||||
if (!string.IsNullOrEmpty(version))
|
||||
{
|
||||
var newVersion = Updater.NumericVersion(version);
|
||||
var oldVersion = Updater.NumericVersion(Infrastructure.Constant.Version);
|
||||
if (newVersion > oldVersion)
|
||||
{
|
||||
Updater.UpdateApp();
|
||||
_viewModel.NewVersionTips = version;
|
||||
}
|
||||
}
|
||||
await Updater.UpdateApp();
|
||||
}
|
||||
|
||||
private void OnRequestNavigate(object sender, RequestNavigateEventArgs e)
|
||||
|
@ -6,6 +6,7 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Wox.Core;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Helper;
|
||||
@ -319,18 +320,6 @@ namespace Wox.ViewModel
|
||||
public static string ReleaseNotes => @"https://github.com/Wox-launcher/Wox/releases/latest";
|
||||
public static string Version => Constant.Version;
|
||||
public string ActivatedTimes => string.Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes);
|
||||
private string _newVersionTips;
|
||||
public string NewVersionTips
|
||||
{
|
||||
get { return _newVersionTips; }
|
||||
set
|
||||
{
|
||||
_newVersionTips = string.Format(_translater.GetTranslation("newVersionTips"), value);
|
||||
NewVersionTipsVisibility = Visibility.Visible;
|
||||
}
|
||||
}
|
||||
public Visibility NewVersionTipsVisibility { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user