Add release packaging and automatic update support
This commit is contained in:
parent
94cd6b984b
commit
f971c374f8
20 changed files with 722 additions and 16 deletions
47
src/AstroFrame.Desktop/MainWindow.Updates.cs
Normal file
47
src/AstroFrame.Desktop/MainWindow.Updates.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using Avalonia.Controls;
|
||||
using Avalonia.Threading;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
|
||||
namespace AstroFrame.Desktop;
|
||||
|
||||
public sealed partial class MainWindow
|
||||
{
|
||||
readonly AppUpdates updates = new();
|
||||
readonly Button settingsButton = Button("Settings");
|
||||
readonly DispatcherTimer updateTimer = new() { Interval = TimeSpan.FromHours(6) };
|
||||
SettingsWindow? settingsWindow;
|
||||
|
||||
void InitializeUpdates()
|
||||
{
|
||||
settingsButton.Click += (_, _) => ShowSettings();
|
||||
updates.Changed += () =>
|
||||
{
|
||||
settingsButton.Content = updates.AvailableVersion == null ? "Settings" : "Settings · Update available";
|
||||
if (updates.Applying) { analyze.IsEnabled = false; export.IsEnabled = false; }
|
||||
};
|
||||
bool diagnostic = Program.Arguments.Any(a => a.StartsWith("--capture") || a == "--smoke");
|
||||
if (!diagnostic)
|
||||
{
|
||||
Opened += async (_, _) => await updates.Check(automatic: true);
|
||||
updateTimer.Tick += async (_, _) => await updates.Check(automatic: true);
|
||||
updateTimer.Start();
|
||||
}
|
||||
Closed += (_, _) => { updateTimer.Stop(); updates.Dispose(); settingsWindow?.Close(); };
|
||||
}
|
||||
public SettingsWindow ShowSettings()
|
||||
{
|
||||
if (settingsWindow != null) { settingsWindow.Activate(); return settingsWindow; }
|
||||
settingsWindow = new SettingsWindow(updates, InstallUpdate);
|
||||
settingsWindow.Closed += (_, _) => settingsWindow = null;
|
||||
settingsWindow.Show(this);
|
||||
return settingsWindow;
|
||||
}
|
||||
async Task InstallUpdate()
|
||||
{
|
||||
bool analyzeEnabled = analyze.IsEnabled, exportEnabled = export.IsEnabled;
|
||||
bool restarting = await updates.Install(() => !busy && !saving, async () => project == null || await Save(),
|
||||
project == null ? [] : ["--project", projectDirectory]);
|
||||
if (restarting && Avalonia.Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) desktop.Shutdown();
|
||||
else { analyze.IsEnabled = analyzeEnabled; export.IsEnabled = exportEnabled; }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue