Skip to content

Commit 79382b4

Browse files
authored
Merge pull request #2951 from Wox-launcher/bao
check update manually for portable mode
2 parents 71a761d + 80cc8b7 commit 79382b4

File tree

4 files changed

+52
-49
lines changed

4 files changed

+52
-49
lines changed

Wox.Core/Updater.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,7 @@ public async Task UpdateApp(bool silentIfLatestVersion = true, bool updateToPrer
7474

7575
await updateManager.ApplyReleases(newUpdateInfo);
7676

77-
if (DataLocation.PortableDataLocationInUse())
78-
{
79-
var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}";
80-
FilesFolders.Copy(DataLocation.PortableDataPath, targetDestination);
81-
if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination))
82-
MessageBox.Show(string.Format("Wox was not able to move your user profile data to the new update version. Please manually" +
83-
"move your profile data folder from {0} to {1}", DataLocation.PortableDataPath, targetDestination));
84-
}
85-
else
86-
{
87-
await updateManager.CreateUninstallerRegistryEntry();
88-
}
77+
await updateManager.CreateUninstallerRegistryEntry();
8978

9079
var newVersionTips = NewVersinoTips(newReleaseVersion.ToString());
9180

@@ -99,6 +88,10 @@ public async Task UpdateApp(bool silentIfLatestVersion = true, bool updateToPrer
9988
{
10089
Logger.WoxError($"Please check your connection and proxy settings to api.github.com.", e);
10190
}
91+
catch (Exception e)
92+
{
93+
Logger.WoxError($"cannot check update", e);
94+
}
10295

10396
}
10497

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

126119
var releases = JsonConvert.DeserializeObject<List<GithubRelease>>(json).AsEnumerable();
127-
if (!updateToPrereleases) {
120+
if (!updateToPrereleases)
121+
{
128122
releases = releases.Where(r => !r.Prerelease);
129123
}
130124
var latest = releases.OrderByDescending(r => r.PublishedAt).First();
131-
125+
132126
var latestUrl = latest.HtmlUrl.Replace("/tag/", "/download/");
133127

134128
var client = new WebClient { Proxy = Http.WebProxy() };

Wox.Test/PluginManagerTest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ public void setUp()
2323
new App();
2424
ImageLoader.Initialize();
2525

26-
Updater updater = new Updater("");
2726
Portable portable = new Portable();
28-
SettingWindowViewModel settingsVm = new SettingWindowViewModel(updater, portable);
27+
SettingWindowViewModel settingsVm = new SettingWindowViewModel(portable);
2928

3029
Alphabet alphabet = new Alphabet();
3130
alphabet.Initialize();

Wox/App.xaml.cs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public partial class App : IDisposable, ISingleInstanceApp
3232
private static bool _disposed;
3333
private MainViewModel _mainVM;
3434
private SettingWindowViewModel _settingsVM;
35-
private readonly Updater _updater = new Updater(Wox.Properties.Settings.Default.GithubRepo);
3635
private readonly Portable _portable = new Portable();
3736
private readonly Alphabet _alphabet = new Alphabet();
3837
private StringMatcher _stringMatcher;
@@ -91,7 +90,7 @@ private void OnStartup(object sender, StartupEventArgs e)
9190

9291
ImageLoader.Initialize();
9392

94-
_settingsVM = new SettingWindowViewModel(_updater, _portable);
93+
_settingsVM = new SettingWindowViewModel(_portable);
9594

9695
_alphabet.Initialize();
9796
_stringMatcher = new StringMatcher(_alphabet);
@@ -119,7 +118,6 @@ private void OnStartup(object sender, StartupEventArgs e)
119118
RegisterExitEvents();
120119

121120
AutoStartup();
122-
AutoUpdates();
123121

124122
ParseCommandLineArgs(SingleInstance<App>.CommandLineArgs);
125123
_mainVM.MainWindowVisibility = Settings.Instance.HideOnStartup ? Visibility.Hidden : Visibility.Visible;
@@ -141,27 +139,6 @@ private void AutoStartup()
141139
}
142140
}
143141

144-
//[Conditional("RELEASE")]
145-
private void AutoUpdates()
146-
{
147-
Task.Run(async () =>
148-
{
149-
if (Settings.Instance.AutoUpdates)
150-
{
151-
// check udpate every 5 hours
152-
var timer = new System.Timers.Timer(1000 * 60 * 60 * 5);
153-
timer.Elapsed += async (s, e) =>
154-
{
155-
await _updater.UpdateApp(true, Settings.Instance.UpdateToPrereleases);
156-
};
157-
timer.Start();
158-
159-
// check updates on startup
160-
await _updater.UpdateApp(true, Settings.Instance.UpdateToPrereleases);
161-
}
162-
}).ContinueWith(ErrorReporting.UnhandledExceptionHandleTask, TaskContinuationOptions.OnlyOnFaulted);
163-
}
164-
165142
private void RegisterExitEvents()
166143
{
167144
AppDomain.CurrentDomain.ProcessExit += (s, e) => Dispose();

Wox/ViewModel/SettingWindowViewModel.cs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
using Microsoft.WindowsAPICodePack.Shell.Interop;
12
using System;
23
using System.Collections.Generic;
34
using System.IO;
45
using System.Linq;
56
using System.Net;
7+
using System.Threading.Tasks;
68
using System.Windows;
79
using System.Windows.Controls;
810
using System.Windows.Media;
@@ -24,9 +26,10 @@ public class SettingWindowViewModel : BaseModel
2426
private readonly Updater _updater;
2527
private readonly IPortable _portable;
2628

27-
public SettingWindowViewModel(Updater updater, IPortable portable)
29+
public SettingWindowViewModel(IPortable portable)
2830
{
29-
_updater = updater;
31+
32+
_updater = new Updater(Wox.Properties.Settings.Default.GithubRepo); ;
3033
_portable = portable;
3134
Settings = Settings.Instance;
3235
Settings.PropertyChanged += (s, e) =>
@@ -36,13 +39,21 @@ public SettingWindowViewModel(Updater updater, IPortable portable)
3639
OnPropertyChanged(nameof(ActivatedTimes));
3740
}
3841
};
42+
AutoUpdates();
3943
}
4044

4145
public Settings Settings { get; set; }
4246

4347
public async void UpdateApp()
4448
{
45-
await _updater.UpdateApp(false);
49+
if (PortableMode)
50+
{
51+
MessageBox.Show("Portable mode need check update manually in https://github.com/Wox-launcher/Wox/releases");
52+
}
53+
else
54+
{
55+
await _updater.UpdateApp(false);
56+
}
4657
}
4758

4859
// 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
6677
}
6778
}
6879

80+
private void AutoUpdates()
81+
{
82+
Task.Run(async () =>
83+
{
84+
if (Settings.Instance.AutoUpdates && !PortableMode)
85+
{
86+
// check udpate every 5 hours
87+
var timer = new System.Timers.Timer(1000 * 60 * 60 * 5);
88+
timer.Elapsed += async (s, e) =>
89+
{
90+
await _updater.UpdateApp(true, Settings.Instance.UpdateToPrereleases);
91+
};
92+
timer.Start();
93+
94+
// check updates on startup
95+
await _updater.UpdateApp(true, Settings.Instance.UpdateToPrereleases);
96+
}
97+
}).ContinueWith(ErrorReporting.UnhandledExceptionHandleTask, TaskContinuationOptions.OnlyOnFaulted);
98+
}
99+
100+
101+
69102
public void Save()
70103
{
71104
Settings.Save();
@@ -113,11 +146,11 @@ public string Language
113146

114147
public bool ShouldUsePinyin
115148
{
116-
get
149+
get
117150
{
118-
return Settings.ShouldUsePinyin;
151+
return Settings.ShouldUsePinyin;
119152
}
120-
set
153+
set
121154
{
122155
Settings.ShouldUsePinyin = value;
123156
}
@@ -155,7 +188,7 @@ public string TestProxy()
155188
}
156189

157190
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_updater.GitHubRepository);
158-
191+
159192
if (string.IsNullOrEmpty(proxyUserName) || string.IsNullOrEmpty(Settings.Proxy.Password))
160193
{
161194
request.Proxy = new WebProxy(proxyServer, Settings.Proxy.Port);
@@ -199,7 +232,7 @@ public IList<PluginViewModel> PluginViewModels
199232
var metadatas = PluginManager.AllPlugins
200233
.OrderBy(x => x.Metadata.Disabled)
201234
.ThenBy(y => y.Metadata.Name)
202-
.Select(p => new PluginViewModel { PluginPair = p})
235+
.Select(p => new PluginViewModel { PluginPair = p })
203236
.ToList();
204237
return metadatas;
205238
}
@@ -440,7 +473,7 @@ public FamilyTypeface SelectedResultHighlightFontFaces
440473
#region about
441474

442475
public string Github => _updater.GitHubRepository;
443-
public string ReleaseNotes => _updater.GitHubRepository + @"/releases/latest";
476+
public string ReleaseNotes => _updater.GitHubRepository + @"/releases/latest";
444477
public static string Version => Constant.Version;
445478
public string ActivatedTimes => string.Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes);
446479
#endregion

0 commit comments

Comments
 (0)