Skip to content

Commit

Permalink
Update UpdateManager to close window when starting the installer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Nov 2, 2024
1 parent 38527e3 commit fa652b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/PicView.Avalonia/Update/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Win32;
using PicView.Avalonia.UI;
using PicView.Avalonia.ViewModels;
using PicView.Avalonia.WindowBehavior;
using PicView.Core.Config;
using PicView.Core.FileHandling;

Expand Down Expand Up @@ -141,6 +142,7 @@ public static async Task UpdateCurrentVersion(MainViewModel vm)
switch (architecture)
{
case InstalledArchitecture.Arm64Install:
// Launch the installer and close the window
var fileName = Path.GetFileName(updateInfo.X64Install);
var tempFileDownloadPath = Path.Combine(tempPath, fileName);
await StartFileDownloader(vm, updateInfo.Arm64Install, tempFileDownloadPath);
Expand All @@ -153,8 +155,10 @@ public static async Task UpdateCurrentVersion(MainViewModel vm)
}
};
process.Start();
await WindowFunctions.WindowClosingBehavior();
return;
case InstalledArchitecture.Arm64Portable:
// Download the zip package in browser
process = new Process
{
StartInfo = new ProcessStartInfo(updateInfo.Arm64Portable)
Expand All @@ -167,6 +171,7 @@ public static async Task UpdateCurrentVersion(MainViewModel vm)
await process.WaitForExitAsync();
return;
case InstalledArchitecture.X64Install:
// Launch the installer and close the window
fileName = Path.GetFileName(updateInfo.X64Install);
tempFileDownloadPath = Path.Combine(tempPath, fileName);
await StartFileDownloader(vm, updateInfo.X64Install, tempFileDownloadPath);
Expand All @@ -179,8 +184,11 @@ public static async Task UpdateCurrentVersion(MainViewModel vm)
}
};
process.Start();
await WindowFunctions.WindowClosingBehavior();
return;
case InstalledArchitecture.X64Portable:

// Download the zip package in browser
process = new Process
{
StartInfo = new ProcessStartInfo(updateInfo.X64Portable)
Expand Down
8 changes: 8 additions & 0 deletions src/PicView.Avalonia/WindowBehavior/WindowFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ namespace PicView.Avalonia.WindowBehavior;

public static class WindowFunctions
{
public static async Task WindowClosingBehavior()
{
if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
{
return;
}
await WindowClosingBehavior(desktop.MainWindow);
}
public static async Task WindowClosingBehavior(Window window)
{
if (!SettingsHelper.Settings.WindowProperties.Maximized ||
Expand Down

0 comments on commit fa652b1

Please sign in to comment.