From 3a189986da8c1be9e6eb7eee6128270c2453bb66 Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Thu, 26 Sep 2024 20:53:27 -0400 Subject: [PATCH] Adjust startup --- WindowSource.cs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/WindowSource.cs b/WindowSource.cs index 4d32459..de91b73 100644 --- a/WindowSource.cs +++ b/WindowSource.cs @@ -1,4 +1,5 @@ using ChrisKaczor.Wpf.Windows.FloatingStatusWindow; +using Serilog; using System; using System.Collections.Generic; using System.Linq; @@ -8,11 +9,8 @@ using System.Text.Json; using System.Threading.Tasks; using System.Timers; using System.Windows.Threading; -using Serilog; -using Serilog.Core; using Velopack; using Velopack.Sources; -using WorldClockStatusWindow.Properties; namespace WorldClockStatusWindow; @@ -37,7 +35,7 @@ internal class WindowSource : IWindowSource, IDisposable _timer = new Timer(1000); - Task.Factory.StartNew(UpdateApp).ContinueWith(_ => Start()); + Task.Factory.StartNew(UpdateApp).ContinueWith(task => Start(task.Result.Result)); } private async Task UpdateApp() @@ -47,6 +45,8 @@ internal class WindowSource : IWindowSource, IDisposable if (!_updateManager.IsInstalled) return false; + Log.Logger.Information("Checking for update"); + await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Checking for update...")); var newVersion = await _updateManager.CheckForUpdatesAsync(); @@ -54,10 +54,14 @@ internal class WindowSource : IWindowSource, IDisposable if (newVersion == null) return false; + Log.Logger.Information("Downloading update"); + await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Downloading update...")); await _updateManager.DownloadUpdatesAsync(newVersion); + Log.Logger.Information("Installing update"); + await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Installing update...")); _updateManager.ApplyUpdatesAndRestart(newVersion); @@ -70,10 +74,19 @@ internal class WindowSource : IWindowSource, IDisposable return true; } - private void Start() + private void Start(bool hasUpdate) { + Log.Logger.Information($"Start: hasUpdate={hasUpdate}"); + + if (hasUpdate) + return; + + Log.Logger.Information("Load"); + Load(); + Log.Logger.Information("Starting timer"); + _timer.Elapsed += HandleTimerElapsed; _timer.Enabled = true; }