Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/PlanViewer.App/AboutWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,18 @@ private async void CheckUpdate_Click(object? sender, RoutedEventArgs e)
CheckUpdateButton.IsEnabled = true;
}

private bool _updateDownloaded;

private async void UpdateLink_Click(object? sender, PointerPressedEventArgs e)
{
// Velopack download + apply
// Step 3: User clicks "Restart now" after download
if (_updateDownloaded && _velopackMgr != null && _velopackUpdate != null)
{
_velopackMgr.ApplyUpdatesAndRestart(_velopackUpdate.TargetFullRelease);
return;
}

// Step 2: User clicks to download
if (_velopackMgr != null && _velopackUpdate != null)
{
try
Expand All @@ -144,8 +153,10 @@ private async void UpdateLink_Click(object? sender, PointerPressedEventArgs e)

await _velopackMgr.DownloadUpdatesAsync(_velopackUpdate);

UpdateStatusText.Text = "Update downloaded — restarting...";
_velopackMgr.ApplyUpdatesAndRestart(_velopackUpdate.TargetFullRelease);
_updateDownloaded = true;
UpdateStatusText.Text = "Update downloaded.";
UpdateLink.Text = "Restart now to apply";
UpdateLink.IsVisible = true;
}
catch (Exception ex)
{
Expand Down
51 changes: 51 additions & 0 deletions src/PlanViewer.App/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public MainWindow()

InitializeComponent();

// Check for updates on startup (non-blocking)
_ = CheckForUpdatesOnStartupAsync();

// Build the Recent Plans submenu from saved state
RebuildRecentPlansMenu();

Expand Down Expand Up @@ -1359,4 +1362,52 @@ private void ShowError(string message)
};
dialog.ShowDialog(this);
}

private async Task CheckForUpdatesOnStartupAsync()
{
try
{
await Task.Delay(5000); // Don't slow down startup

if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(
System.Runtime.InteropServices.OSPlatform.Windows))
{
try
{
var mgr = new Velopack.UpdateManager(
new Velopack.Sources.GithubSource(
"https://github.com/erikdarlingdata/PerformanceStudio", null, false));

var update = await mgr.CheckForUpdatesAsync();
if (update != null)
{
await Dispatcher.UIThread.InvokeAsync(() =>
{
Title = $"Performance Studio — Update v{update.TargetFullRelease.Version} available (Help > About)";
});
return;
}
}
catch
{
// Velopack not available — fall through
}
}

var currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version
?? new Version(0, 0, 0);
var result = await UpdateChecker.CheckAsync(currentVersion);
if (result.UpdateAvailable)
{
await Dispatcher.UIThread.InvokeAsync(() =>
{
Title = $"Performance Studio — Update {result.LatestVersion} available (Help > About)";
});
}
}
catch
{
// Never crash on update check
}
}
}
Loading