Tweak updating

This commit is contained in:
2024-09-26 20:44:25 -04:00
parent da388bf953
commit adab62394b

View File

@@ -22,6 +22,8 @@ internal class WindowSource : IWindowSource, IDisposable
private readonly Timer _timer; private readonly Timer _timer;
private readonly Dispatcher _dispatcher; private readonly Dispatcher _dispatcher;
private readonly UpdateManager _updateManager;
private List<TimeZoneEntry> _timeZoneEntries; private List<TimeZoneEntry> _timeZoneEntries;
internal WindowSource() internal WindowSource()
@@ -31,6 +33,8 @@ internal class WindowSource : IWindowSource, IDisposable
_dispatcher = Dispatcher.CurrentDispatcher; _dispatcher = Dispatcher.CurrentDispatcher;
_updateManager = new UpdateManager(new GithubSource("https://github.com/ckaczor/WorldClockStatusWindow", null, false));
_timer = new Timer(1000); _timer = new Timer(1000);
Task.Factory.StartNew(UpdateApp).ContinueWith(_ => Start()); Task.Factory.StartNew(UpdateApp).ContinueWith(_ => Start());
@@ -40,25 +44,23 @@ internal class WindowSource : IWindowSource, IDisposable
{ {
try try
{ {
var updateManager = new UpdateManager(new GithubSource("https://github.com/ckaczor/WorldClockStatusWindow", null, false)); if (!_updateManager.IsInstalled)
if (!updateManager.IsInstalled)
return false; 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) if (newVersion == null)
return false; 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) 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.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())); _dispatcher.Invoke(() => _floatingStatusWindow.SetText(text.ToString()));
} }