fix: process can't be exited by X button

#298
This commit is contained in:
ema
2024-03-10 02:58:30 +08:00
parent 24c4a021cb
commit ce89e41b60
4 changed files with 16 additions and 7 deletions

View File

@@ -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()
{

View File

@@ -32,9 +32,15 @@ public partial class MainWindow : FluentWindow, INavigationWindow
TryApplySystemBackdrop();
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
App.GetService<NotifyIconViewModel>()?.Exit();
}
private void OnNotifyIconLeftDoubleClick(NotifyIcon sender, RoutedEventArgs e)
{
NotifyIconViewModel.ShowOrHide();
App.GetService<NotifyIconViewModel>()?.ShowOrHide();
}
public INavigationView GetNavigation() => RootNavigation;

View File

@@ -22,7 +22,7 @@ public partial class MainWindowViewModel : ObservableObject
{
private readonly ILogger<MainWindowViewModel> _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<MainWindowViewModel>();
#if DEBUG
Title += " · Dev";
#endif
}
[RelayCommand]

View File

@@ -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<IConfigService>()?.Save();
Application.Current.Shutdown();