Skip to content

Commit

Permalink
Merge pull request #2951 from Wox-launcher/bao
Browse files Browse the repository at this point in the history
check update manually for portable mode
  • Loading branch information
bao-qian authored May 17, 2020
2 parents 71a761d + 80cc8b7 commit 79382b4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 49 deletions.
22 changes: 8 additions & 14 deletions Wox.Core/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -99,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);
}

}

Expand All @@ -124,11 +117,12 @@ private async Task<UpdateManager> GitHubUpdateManager(string repository, bool up
var json = await Http.Get(api);

var releases = JsonConvert.DeserializeObject<List<GithubRelease>>(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() };
Expand Down
3 changes: 1 addition & 2 deletions Wox.Test/PluginManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
25 changes: 1 addition & 24 deletions Wox/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -119,7 +118,6 @@ private void OnStartup(object sender, StartupEventArgs e)
RegisterExitEvents();
AutoStartup();
AutoUpdates();
ParseCommandLineArgs(SingleInstance<App>.CommandLineArgs);
_mainVM.MainWindowVisibility = Settings.Instance.HideOnStartup ? Visibility.Hidden : Visibility.Visible;
Expand All @@ -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();
Expand Down
51 changes: 42 additions & 9 deletions Wox/ViewModel/SettingWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) =>
Expand All @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -113,11 +146,11 @@ public string Language

public bool ShouldUsePinyin
{
get
get
{
return Settings.ShouldUsePinyin;
return Settings.ShouldUsePinyin;
}
set
set
{
Settings.ShouldUsePinyin = value;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -199,7 +232,7 @@ public IList<PluginViewModel> 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;
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 79382b4

Please sign in to comment.