Skip to content

Commit 9be71e8

Browse files
authored
Merge pull request #1762 from Flow-Launcher/safer_updater
Safer Updater
2 parents 484df7d + dfe2c01 commit 9be71e8

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

Flow.Launcher.Core/Updater.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public Updater(string gitHubRepository)
3333

3434
public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true)
3535
{
36-
await UpdateLock.WaitAsync();
36+
await UpdateLock.WaitAsync().ConfigureAwait(false);
3737
try
3838
{
3939
if (!silentUpdate)
@@ -88,9 +88,13 @@ public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true)
8888
UpdateManager.RestartApp(Constant.ApplicationFileName);
8989
}
9090
}
91-
catch (Exception e) when (e is HttpRequestException or WebException or SocketException || e.InnerException is TimeoutException)
91+
catch (Exception e)
9292
{
93-
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
93+
if ((e is HttpRequestException or WebException or SocketException || e.InnerException is TimeoutException))
94+
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
95+
else
96+
Log.Exception($"|Updater.UpdateApp|Error Occurred", e);
97+
9498
if (!silentUpdate)
9599
api.ShowMsg(api.GetTranslation("update_flowlauncher_fail"),
96100
api.GetTranslation("update_flowlauncher_check_connection"));

Flow.Launcher/App.xaml.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using System.Text;
4+
using System.Threading;
45
using System.Threading.Tasks;
56
using System.Timers;
67
using System.Windows;
@@ -84,14 +85,14 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
8485

8586
Current.MainWindow = window;
8687
Current.MainWindow.Title = Constant.FlowLauncher;
87-
88+
8889
HotKeyMapper.Initialize(_mainVM);
8990

90-
// happlebao todo temp fix for instance code logic
91+
// todo temp fix for instance code logic
9192
// load plugin before change language, because plugin language also needs be changed
9293
InternationalizationManager.Instance.Settings = _settings;
9394
InternationalizationManager.Instance.ChangeLanguage(_settings.Language);
94-
// main windows needs initialized before theme change because of blur settigns
95+
// main windows needs initialized before theme change because of blur settings
9596
ThemeManager.Instance.Settings = _settings;
9697
ThemeManager.Instance.ChangeTheme(_settings.Theme);
9798

@@ -130,20 +131,17 @@ private void AutoStartup()
130131
//[Conditional("RELEASE")]
131132
private void AutoUpdates()
132133
{
133-
Task.Run(async () =>
134+
_ = Task.Run(async () =>
134135
{
135136
if (_settings.AutoUpdates)
136137
{
137-
// check udpate every 5 hours
138-
var timer = new Timer(1000 * 60 * 60 * 5);
139-
timer.Elapsed += async (s, e) =>
140-
{
141-
await _updater.UpdateAppAsync(API);
142-
};
143-
timer.Start();
144-
145-
// check updates on startup
138+
// check update every 5 hours
139+
var timer = new PeriodicTimer(TimeSpan.FromHours(5));
146140
await _updater.UpdateAppAsync(API);
141+
142+
while (await timer.WaitForNextTickAsync())
143+
// check updates on startup
144+
await _updater.UpdateAppAsync(API);
147145
}
148146
});
149147
}

0 commit comments

Comments
 (0)