mirror of
https://github.com/ckaczor/WorldClockStatusWindow.git
synced 2026-01-14 10:00:12 -05:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a189986da | |||
| adab62394b | |||
| da388bf953 |
@@ -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;
|
||||
|
||||
@@ -22,6 +20,8 @@ internal class WindowSource : IWindowSource, IDisposable
|
||||
private readonly Timer _timer;
|
||||
private readonly Dispatcher _dispatcher;
|
||||
|
||||
private readonly UpdateManager _updateManager;
|
||||
|
||||
private List<TimeZoneEntry> _timeZoneEntries;
|
||||
|
||||
internal WindowSource()
|
||||
@@ -31,34 +31,40 @@ 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());
|
||||
Task.Factory.StartNew(UpdateApp).ContinueWith(task => Start(task.Result.Result));
|
||||
}
|
||||
|
||||
private async Task<bool> UpdateApp()
|
||||
{
|
||||
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..."));
|
||||
Log.Logger.Information("Checking for update");
|
||||
|
||||
var newVersion = await updateManager.CheckForUpdatesAsync();
|
||||
await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Checking for update..."));
|
||||
|
||||
var newVersion = await _updateManager.CheckForUpdatesAsync();
|
||||
|
||||
if (newVersion == null)
|
||||
return false;
|
||||
|
||||
_dispatcher.Invoke(() => _floatingStatusWindow.SetText("Downloading update..."));
|
||||
Log.Logger.Information("Downloading update");
|
||||
|
||||
await updateManager.DownloadUpdatesAsync(newVersion);
|
||||
await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Downloading update..."));
|
||||
|
||||
_dispatcher.Invoke(() => _floatingStatusWindow.SetText("Installing update..."));
|
||||
await _updateManager.DownloadUpdatesAsync(newVersion);
|
||||
|
||||
updateManager.ApplyUpdatesAndRestart(newVersion);
|
||||
Log.Logger.Information("Installing update");
|
||||
|
||||
await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Installing update..."));
|
||||
|
||||
_updateManager.ApplyUpdatesAndRestart(newVersion);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -68,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;
|
||||
}
|
||||
@@ -117,7 +132,7 @@ internal class WindowSource : IWindowSource, IDisposable
|
||||
|
||||
text.AppendLine();
|
||||
text.AppendLine();
|
||||
text.Append($"Version: {Assembly.GetEntryAssembly()!.GetName().Version!.ToString()}");
|
||||
text.Append(_updateManager.CurrentVersion);
|
||||
|
||||
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(text.ToString()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user