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
@@ -41,21 +43,29 @@ public class AppUpdates(string updateUrl, Window mainWindow)
{ {
Distro = RuntimeInformationsEx.GetRuntimeIdentifier(), Distro = RuntimeInformationsEx.GetRuntimeIdentifier(),
}; };
if (await updater.CheckForUpdate() is not { } packageToInstall || await AskForUpdate() != ButtonResult.Yes)
return;
if (await updater.CheckForUpdate() is {} packageToInstall OnDownloadProgramUpdate?.Invoke(this, EventArgs.Empty);
&& await MessageBoxManager.GetMessageBoxStandard(GeneralMsgBoxLangRes.UpdateAvailable_Title, GeneralMsgBoxLangRes.UpdateAvailable, ButtonEnum.YesNo, MsBox.Avalonia.Enums.Icon.Info).ShowWindowDialogAsync(mainWindow) == ButtonResult.Yes) mainWindow.IsEnabled = false;
if (await updater.DownloadPackageAsync(packageToInstall) && await updater.InstallPackageAsync(packageToInstall, myAppPath))
{ {
OnDownloadProgramUpdate?.Invoke(this, EventArgs.Empty); mainWindow.IsVisible = false;
mainWindow.IsEnabled = false; await Process.Start(myAppPath).WaitForExitAsync();
if (await updater.DownloadPackageAsync(packageToInstall) Environment.Exit(0);
&& await updater.InstallPackageAsync(packageToInstall, myAppPath)) return;
{
mainWindow.IsVisible = false;
await Process.Start(myAppPath).WaitForExitAsync();
Environment.Exit(0);
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);
} }
} }