From 3eca063eb8f3879cf31f43d411e5e563b6e65e0b Mon Sep 17 00:00:00 2001 From: bao-qian Date: Sun, 17 May 2020 23:09:12 +0800 Subject: [PATCH 1/3] check update manually for portable mode https://github.com/Wox-launcher/Wox/issues/2933 --- Wox.Core/Updater.cs | 18 ++------- Wox/App.xaml.cs | 25 +----------- Wox/ViewModel/SettingWindowViewModel.cs | 51 ++++++++++++++++++++----- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/Wox.Core/Updater.cs b/Wox.Core/Updater.cs index e948db1e2..1aff59e4e 100644 --- a/Wox.Core/Updater.cs +++ b/Wox.Core/Updater.cs @@ -74,18 +74,7 @@ public async Task UpdateApp(bool silentIfLatestVersion = true, bool updateToPrer await updateManager.ApplyReleases(newUpdateInfo); - if (DataLocation.PortableDataLocationInUse()) - { - var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}"; - FilesFolders.Copy(DataLocation.PortableDataPath, targetDestination); - if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination)) - MessageBox.Show(string.Format("Wox was not able to move your user profile data to the new update version. Please manually" + - "move your profile data folder from {0} to {1}", DataLocation.PortableDataPath, targetDestination)); - } - else - { - await updateManager.CreateUninstallerRegistryEntry(); - } + await updateManager.CreateUninstallerRegistryEntry(); var newVersionTips = NewVersinoTips(newReleaseVersion.ToString()); @@ -124,11 +113,12 @@ private async Task GitHubUpdateManager(string repository, bool up var json = await Http.Get(api); var releases = JsonConvert.DeserializeObject>(json).AsEnumerable(); - if (!updateToPrereleases) { + if (!updateToPrereleases) + { releases = releases.Where(r => !r.Prerelease); } var latest = releases.OrderByDescending(r => r.PublishedAt).First(); - + var latestUrl = latest.HtmlUrl.Replace("/tag/", "/download/"); var client = new WebClient { Proxy = Http.WebProxy() }; diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index 50731313a..3eff663fe 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -32,7 +32,6 @@ public partial class App : IDisposable, ISingleInstanceApp private static bool _disposed; private MainViewModel _mainVM; private SettingWindowViewModel _settingsVM; - private readonly Updater _updater = new Updater(Wox.Properties.Settings.Default.GithubRepo); private readonly Portable _portable = new Portable(); private readonly Alphabet _alphabet = new Alphabet(); private StringMatcher _stringMatcher; @@ -91,7 +90,7 @@ private void OnStartup(object sender, StartupEventArgs e) ImageLoader.Initialize(); - _settingsVM = new SettingWindowViewModel(_updater, _portable); + _settingsVM = new SettingWindowViewModel(_portable); _alphabet.Initialize(); _stringMatcher = new StringMatcher(_alphabet); @@ -119,7 +118,6 @@ private void OnStartup(object sender, StartupEventArgs e) RegisterExitEvents(); AutoStartup(); - AutoUpdates(); ParseCommandLineArgs(SingleInstance.CommandLineArgs); _mainVM.MainWindowVisibility = Settings.Instance.HideOnStartup ? Visibility.Hidden : Visibility.Visible; @@ -141,27 +139,6 @@ private void AutoStartup() } } - //[Conditional("RELEASE")] - private void AutoUpdates() - { - Task.Run(async () => - { - if (Settings.Instance.AutoUpdates) - { - // check udpate every 5 hours - var timer = new System.Timers.Timer(1000 * 60 * 60 * 5); - timer.Elapsed += async (s, e) => - { - await _updater.UpdateApp(true, Settings.Instance.UpdateToPrereleases); - }; - timer.Start(); - - // check updates on startup - await _updater.UpdateApp(true, Settings.Instance.UpdateToPrereleases); - } - }).ContinueWith(ErrorReporting.UnhandledExceptionHandleTask, TaskContinuationOptions.OnlyOnFaulted); - } - private void RegisterExitEvents() { AppDomain.CurrentDomain.ProcessExit += (s, e) => Dispose(); diff --git a/Wox/ViewModel/SettingWindowViewModel.cs b/Wox/ViewModel/SettingWindowViewModel.cs index 85b8bc900..7c6fccd16 100644 --- a/Wox/ViewModel/SettingWindowViewModel.cs +++ b/Wox/ViewModel/SettingWindowViewModel.cs @@ -1,8 +1,10 @@ +using Microsoft.WindowsAPICodePack.Shell.Interop; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; +using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; @@ -24,9 +26,10 @@ public class SettingWindowViewModel : BaseModel private readonly Updater _updater; private readonly IPortable _portable; - public SettingWindowViewModel(Updater updater, IPortable portable) + public SettingWindowViewModel(IPortable portable) { - _updater = updater; + + _updater = new Updater(Wox.Properties.Settings.Default.GithubRepo); ; _portable = portable; Settings = Settings.Instance; Settings.PropertyChanged += (s, e) => @@ -36,13 +39,21 @@ public SettingWindowViewModel(Updater updater, IPortable portable) OnPropertyChanged(nameof(ActivatedTimes)); } }; + AutoUpdates(); } public Settings Settings { get; set; } public async void UpdateApp() { - await _updater.UpdateApp(false); + if (PortableMode) + { + MessageBox.Show("Portable mode need check update manually in https://github.com/Wox-launcher/Wox/releases"); + } + else + { + await _updater.UpdateApp(false); + } } // This is only required to set at startup. When portable mode enabled/disabled a restart is always required @@ -66,6 +77,28 @@ public bool PortableMode } } + private void AutoUpdates() + { + Task.Run(async () => + { + if (Settings.Instance.AutoUpdates && !PortableMode) + { + // check udpate every 5 hours + var timer = new System.Timers.Timer(1000 * 60 * 60 * 5); + timer.Elapsed += async (s, e) => + { + await _updater.UpdateApp(true, Settings.Instance.UpdateToPrereleases); + }; + timer.Start(); + + // check updates on startup + await _updater.UpdateApp(true, Settings.Instance.UpdateToPrereleases); + } + }).ContinueWith(ErrorReporting.UnhandledExceptionHandleTask, TaskContinuationOptions.OnlyOnFaulted); + } + + + public void Save() { Settings.Save(); @@ -113,11 +146,11 @@ public string Language public bool ShouldUsePinyin { - get + get { - return Settings.ShouldUsePinyin; + return Settings.ShouldUsePinyin; } - set + set { Settings.ShouldUsePinyin = value; } @@ -155,7 +188,7 @@ public string TestProxy() } HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_updater.GitHubRepository); - + if (string.IsNullOrEmpty(proxyUserName) || string.IsNullOrEmpty(Settings.Proxy.Password)) { request.Proxy = new WebProxy(proxyServer, Settings.Proxy.Port); @@ -199,7 +232,7 @@ public IList PluginViewModels var metadatas = PluginManager.AllPlugins .OrderBy(x => x.Metadata.Disabled) .ThenBy(y => y.Metadata.Name) - .Select(p => new PluginViewModel { PluginPair = p}) + .Select(p => new PluginViewModel { PluginPair = p }) .ToList(); return metadatas; } @@ -440,7 +473,7 @@ public FamilyTypeface SelectedResultHighlightFontFaces #region about public string Github => _updater.GitHubRepository; - public string ReleaseNotes => _updater.GitHubRepository + @"/releases/latest"; + public string ReleaseNotes => _updater.GitHubRepository + @"/releases/latest"; public static string Version => Constant.Version; public string ActivatedTimes => string.Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes); #endregion From 0f29b930aaeff40da00b371bdb949c5c5f4e1b39 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Sun, 17 May 2020 23:10:45 +0800 Subject: [PATCH 2/3] fixup --- Wox.Test/PluginManagerTest.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Wox.Test/PluginManagerTest.cs b/Wox.Test/PluginManagerTest.cs index 9b6307c19..041727abc 100644 --- a/Wox.Test/PluginManagerTest.cs +++ b/Wox.Test/PluginManagerTest.cs @@ -23,9 +23,8 @@ public void setUp() new App(); ImageLoader.Initialize(); - Updater updater = new Updater(""); Portable portable = new Portable(); - SettingWindowViewModel settingsVm = new SettingWindowViewModel(updater, portable); + SettingWindowViewModel settingsVm = new SettingWindowViewModel(portable); Alphabet alphabet = new Alphabet(); alphabet.Initialize(); From 80cc8b73f25d7dddf546f466fdf42ec762fca09c Mon Sep 17 00:00:00 2001 From: bao-qian Date: Sun, 17 May 2020 23:14:40 +0800 Subject: [PATCH 3/3] catch update exception --- Wox.Core/Updater.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Wox.Core/Updater.cs b/Wox.Core/Updater.cs index 1aff59e4e..3545629d3 100644 --- a/Wox.Core/Updater.cs +++ b/Wox.Core/Updater.cs @@ -88,6 +88,10 @@ public async Task UpdateApp(bool silentIfLatestVersion = true, bool updateToPrer { Logger.WoxError($"Please check your connection and proxy settings to api.github.com.", e); } + catch (Exception e) + { + Logger.WoxError($"cannot check update", e); + } }