From 27f19596c69f3d5b3769d720b80bdb03db1895ff Mon Sep 17 00:00:00 2001 From: Scighost Date: Thu, 29 Aug 2024 23:18:15 +0800 Subject: [PATCH] fix the bug where may crash when install game #1051 --- src/Starward/MyWindows/MainWindow.xaml.cs | 10 +++++++++- src/Starward/Services/Download/InstallGameManager.cs | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Starward/MyWindows/MainWindow.xaml.cs b/src/Starward/MyWindows/MainWindow.xaml.cs index 6fcb7f06e..f366287b2 100644 --- a/src/Starward/MyWindows/MainWindow.xaml.cs +++ b/src/Starward/MyWindows/MainWindow.xaml.cs @@ -8,6 +8,7 @@ using Microsoft.UI.Xaml.Media.Animation; using Starward.Controls; using Starward.Models; +using Starward.Services.Download; using System; using System.Diagnostics; using System.Runtime.CompilerServices; @@ -145,7 +146,14 @@ private async void AppWindow_Closing(AppWindow sender, AppWindowClosingEventArgs } if (option is CloseWindowOption.Close) { - App.Current.CloseMainWindow(); + if (InstallGameManager.Instance.HasTask) + { + Hide(); + } + else + { + App.Current.CloseMainWindow(); + } } } catch { } diff --git a/src/Starward/Services/Download/InstallGameManager.cs b/src/Starward/Services/Download/InstallGameManager.cs index a4e47fd72..db4185b80 100644 --- a/src/Starward/Services/Download/InstallGameManager.cs +++ b/src/Starward/Services/Download/InstallGameManager.cs @@ -27,6 +27,9 @@ private InstallGameManager() public static InstallGameManager Instance => _instance ??= new(); + public bool HasTask => _services.Count > 0; + + public static TokenBucketRateLimiter RateLimiter { get; private set; }