diff --git a/BetterGenshinImpact/Helpers/RuntimeHelper.cs b/BetterGenshinImpact/Helpers/RuntimeHelper.cs index a6a98895..a729264c 100644 --- a/BetterGenshinImpact/Helpers/RuntimeHelper.cs +++ b/BetterGenshinImpact/Helpers/RuntimeHelper.cs @@ -16,6 +16,12 @@ internal static class RuntimeHelper public static bool IsElevated { get; } = GetElevated(); public static bool IsDebuggerAttached => Debugger.IsAttached; public static bool IsDesignMode { get; } = GetDesignMode(); + public static bool IsDebug => +#if DEBUG + true; +#else + false; +#endif private static bool GetElevated() { diff --git a/BetterGenshinImpact/View/MainWindow.xaml.cs b/BetterGenshinImpact/View/MainWindow.xaml.cs index 72d1e5ef..e1553d7a 100644 --- a/BetterGenshinImpact/View/MainWindow.xaml.cs +++ b/BetterGenshinImpact/View/MainWindow.xaml.cs @@ -32,9 +32,15 @@ public partial class MainWindow : FluentWindow, INavigationWindow TryApplySystemBackdrop(); } + protected override void OnClosed(EventArgs e) + { + base.OnClosed(e); + App.GetService()?.Exit(); + } + private void OnNotifyIconLeftDoubleClick(NotifyIcon sender, RoutedEventArgs e) { - NotifyIconViewModel.ShowOrHide(); + App.GetService()?.ShowOrHide(); } public INavigationView GetNavigation() => RootNavigation; diff --git a/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs b/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs index 9370cb3c..08a461ef 100644 --- a/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs +++ b/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs @@ -22,7 +22,7 @@ public partial class MainWindowViewModel : ObservableObject { private readonly ILogger _logger; private readonly IConfigService _configService; - public string Title { get; set; } = $"BetterGI · 更好的原神 · {Global.Version}"; + public string Title => $"BetterGI · 更好的原神 · {Global.Version}{(RuntimeHelper.IsDebug ? " · Dev" : string.Empty)}"; [ObservableProperty] public bool _isVisible = true; @@ -37,9 +37,6 @@ public partial class MainWindowViewModel : ObservableObject _configService = configService; Config = _configService.Get(); _logger = App.GetLogger(); -#if DEBUG - Title += " · Dev"; -#endif } [RelayCommand] diff --git a/BetterGenshinImpact/ViewModel/NotifyIconViewModel.cs b/BetterGenshinImpact/ViewModel/NotifyIconViewModel.cs index 01f94344..957fe9c7 100644 --- a/BetterGenshinImpact/ViewModel/NotifyIconViewModel.cs +++ b/BetterGenshinImpact/ViewModel/NotifyIconViewModel.cs @@ -11,7 +11,7 @@ namespace BetterGenshinImpact.ViewModel; public partial class NotifyIconViewModel : ObservableObject { [RelayCommand] - public static void ShowOrHide() + public void ShowOrHide() { if (Application.Current.MainWindow.Visibility == Visibility.Visible) { @@ -27,7 +27,7 @@ public partial class NotifyIconViewModel : ObservableObject } [RelayCommand] - public static void Exit() + public void Exit() { App.GetService()?.Save(); Application.Current.Shutdown();