ui(manager): use popup for app update message

This commit is contained in:
Pascal
2025-11-19 07:55:46 +01:00
parent 0ae2a780b0
commit f21e31ebcc
2 changed files with 27 additions and 14 deletions

View File

@@ -129,7 +129,10 @@ public partial class MainWindow : Window, IMainApi
private async void Window_OnLoaded(object? sender, RoutedEventArgs e) private async void Window_OnLoaded(object? sender, RoutedEventArgs e)
{ {
var updater = new AppUpdates(Program.UpdateUrl, this); var updater = new AppUpdates(Program.UpdateUrl, this)
{
UsePopups = true,
};
updater.OnDownloadProgramUpdate += (o, _) => Model.Progress.Start(); updater.OnDownloadProgramUpdate += (o, _) => Model.Progress.Start();
await updater.UpdateApp(); await updater.UpdateApp();
Model.Progress.Stop(); Model.Progress.Stop();

View File

@@ -14,6 +14,8 @@ public class AppUpdates(string updateUrl, Window mainWindow)
{ {
public event EventHandler? OnDownloadProgramUpdate; public event EventHandler? OnDownloadProgramUpdate;
public bool UsePopups { get; set; }
public async Task UpdateApp() public async Task UpdateApp()
{ {
#if DISABLE_UPDATE #if DISABLE_UPDATE
@@ -42,20 +44,28 @@ public class AppUpdates(string updateUrl, Window mainWindow)
Distro = RuntimeInformationsEx.GetRuntimeIdentifier(), Distro = RuntimeInformationsEx.GetRuntimeIdentifier(),
}; };
if (await updater.CheckForUpdate() is {} packageToInstall if (await updater.CheckForUpdate() is not { } packageToInstall || await AskForUpdate() != ButtonResult.Yes)
&& await MessageBoxManager.GetMessageBoxStandard(GeneralMsgBoxLangRes.UpdateAvailable_Title, GeneralMsgBoxLangRes.UpdateAvailable, ButtonEnum.YesNo, MsBox.Avalonia.Enums.Icon.Info).ShowWindowDialogAsync(mainWindow) == ButtonResult.Yes) return;
{
OnDownloadProgramUpdate?.Invoke(this, EventArgs.Empty); OnDownloadProgramUpdate?.Invoke(this, EventArgs.Empty);
mainWindow.IsEnabled = false; mainWindow.IsEnabled = false;
if (await updater.DownloadPackageAsync(packageToInstall)
&& await updater.InstallPackageAsync(packageToInstall, myAppPath)) if (await updater.DownloadPackageAsync(packageToInstall) && await updater.InstallPackageAsync(packageToInstall, myAppPath))
{ {
mainWindow.IsVisible = false; mainWindow.IsVisible = false;
await Process.Start(myAppPath).WaitForExitAsync(); await Process.Start(myAppPath).WaitForExitAsync();
Environment.Exit(0); Environment.Exit(0);
return; return;
} }
mainWindow.IsEnabled = true; mainWindow.IsEnabled = true;
} }
private Task<ButtonResult> AskForUpdate()
{
var msgBox = MessageBoxManager.GetMessageBoxStandard(GeneralMsgBoxLangRes.UpdateAvailable_Title, GeneralMsgBoxLangRes.UpdateAvailable, ButtonEnum.YesNo, Icon.Info);
if (UsePopups)
return msgBox.ShowAsPopupAsync(mainWindow);
return msgBox.ShowWindowDialogAsync(mainWindow);
} }
} }