From adab62394b16cedc0aa4a43dc045adff07368360 Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Thu, 26 Sep 2024 20:44:25 -0400 Subject: [PATCH] Tweak updating --- WindowSource.cs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/WindowSource.cs b/WindowSource.cs index ca005f6..4d32459 100644 --- a/WindowSource.cs +++ b/WindowSource.cs @@ -22,6 +22,8 @@ internal class WindowSource : IWindowSource, IDisposable private readonly Timer _timer; private readonly Dispatcher _dispatcher; + private readonly UpdateManager _updateManager; + private List _timeZoneEntries; internal WindowSource() @@ -31,6 +33,8 @@ internal class WindowSource : IWindowSource, IDisposable _dispatcher = Dispatcher.CurrentDispatcher; + _updateManager = new UpdateManager(new GithubSource("https://github.com/ckaczor/WorldClockStatusWindow", null, false)); + _timer = new Timer(1000); Task.Factory.StartNew(UpdateApp).ContinueWith(_ => Start()); @@ -40,25 +44,23 @@ internal class WindowSource : IWindowSource, IDisposable { try { - var updateManager = new UpdateManager(new GithubSource("https://github.com/ckaczor/WorldClockStatusWindow", null, false)); - - if (!updateManager.IsInstalled) + if (!_updateManager.IsInstalled) return false; - _dispatcher.Invoke(() => _floatingStatusWindow.SetText("Checking for update...")); + await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Checking for update...")); - var newVersion = await updateManager.CheckForUpdatesAsync(); + var newVersion = await _updateManager.CheckForUpdatesAsync(); if (newVersion == null) return false; - _dispatcher.Invoke(() => _floatingStatusWindow.SetText("Downloading update...")); + await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Downloading update...")); - await updateManager.DownloadUpdatesAsync(newVersion); + await _updateManager.DownloadUpdatesAsync(newVersion); - _dispatcher.Invoke(() => _floatingStatusWindow.SetText("Installing update...")); + await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Installing update...")); - updateManager.ApplyUpdatesAndRestart(newVersion); + _updateManager.ApplyUpdatesAndRestart(newVersion); } catch (Exception e) { @@ -115,6 +117,10 @@ internal class WindowSource : IWindowSource, IDisposable text.Append($"{timeZoneEntry.Label.PadLeft(labelLength)}: {TimeZoneInfo.ConvertTime(now, timeZone).ToString(Properties.Settings.Default.TimeFormat)}"); } + text.AppendLine(); + text.AppendLine(); + text.Append(_updateManager.CurrentVersion); + _dispatcher.Invoke(() => _floatingStatusWindow.SetText(text.ToString())); }