diff --git a/src/BD.WTTS.Client.Avalonia/UI/App.axaml.cs b/src/BD.WTTS.Client.Avalonia/UI/App.axaml.cs index 7424f16e3f3..abaef4165b6 100644 --- a/src/BD.WTTS.Client.Avalonia/UI/App.axaml.cs +++ b/src/BD.WTTS.Client.Avalonia/UI/App.axaml.cs @@ -1,4 +1,5 @@ using AngleSharp.Dom; +using Avalonia.Input; using BD.WTTS.Client.Resources; using LiveChartsCore; using LiveChartsCore.SkiaSharpView; @@ -17,14 +18,94 @@ public App() OpenBrowserCommand = ReactiveCommand.Create(OpenBrowserCommandCore); CopyToClipboardCommand = ReactiveCommand.Create(CopyToClipboardCommandCore); #if MACOS + InitializeMacOSNativeMenu(); +#endif + } + +#if MACOS + void InitializeMacOSNativeMenu() + { + var appMenu = new NativeMenu(); + appMenu.Add(new NativeMenuItem + { + Header = Strings.Settings, + Command = ReactiveCommand.Create(() => INavigationService.Instance.Navigate(typeof(SettingsPage))), + }); + appMenu.Add(new NativeMenuItemSeparator()); + appMenu.Add(new NativeMenuItem + { + Header = string.Format(GetMacMenuString("HideApp_", "Hide {0}"), Name), + Gesture = KeyGesture.Parse("CMD+H"), + Command = ReactiveCommand.Create(HideAllWindows), + }); + appMenu.Add(new NativeMenuItem + { + Header = Strings.Exit, + Gesture = KeyGesture.Parse("CMD+Q"), + Command = ReactiveCommand.Create(() => Shutdown()), + }); + + var windowMenu = new NativeMenu(); + windowMenu.Add(new NativeMenuItem + { + Header = GetMacMenuString("HideWindow", "Hide Window"), + Gesture = KeyGesture.Parse("CMD+W"), + Command = ReactiveCommand.Create(HideActiveWindow), + }); + var menus = new NativeMenu(); - menus.Add(new NativeMenuItem { Header = Strings.Settings, Command = ReactiveCommand.Create(() => { INavigationService.Instance.Navigate(typeof(SettingsPage)); }) }); - menus.Add(new NativeMenuItemSeparator()); - menus.Add(new NativeMenuItem { Header = Strings.Exit, Command = ReactiveCommand.Create(() => { Shutdown(); }) }); + menus.Add(new NativeMenuItem + { + Header = Name, + Menu = appMenu, + }); + menus.Add(new NativeMenuItem + { + Header = GetMacMenuString("WindowMenu", "Window"), + Menu = windowMenu, + }); + NativeMenu.SetMenu(this, menus); -#endif } + static string GetMacMenuString(string key, string fallback) + => Strings.ResourceManager.GetString(key, Strings.Culture) ?? fallback; + + void HideAllWindows() + { + MainThread2.BeginInvokeOnMainThread(() => + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + foreach (var window in desktop.Windows.Where(x => x.IsVisible)) + { + window.Hide(); + } + return; + } + + MainWindow?.Hide(); + }); + } + + void HideActiveWindow() + { + MainThread2.BeginInvokeOnMainThread(() => + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + var window = desktop.Windows.FirstOrDefault(x => x.IsActive) ?? + MainWindow ?? + desktop.Windows.FirstOrDefault(); + window?.Hide(); + return; + } + + MainWindow?.Hide(); + }); + } +#endif + /// /// 获取当前主窗口 /// diff --git a/src/BD.WTTS.Client/Resources/Strings.en.resx b/src/BD.WTTS.Client/Resources/Strings.en.resx index 153a65769d7..9db900dfe38 100644 --- a/src/BD.WTTS.Client/Resources/Strings.en.resx +++ b/src/BD.WTTS.Client/Resources/Strings.en.resx @@ -3136,14 +3136,20 @@ The system will {1} after {0} seconds. On Author=kotovasia5120 - - Close - Author=kotovasia5120 - - - Minimize - Author=kotovasia5120 - + + Close + Author=kotovasia5120 + + + Hide {0} + + + Hide Window + + + Minimize + Author=kotovasia5120 + Maximize Author=kotovasia5120 @@ -3152,14 +3158,17 @@ The system will {1} after {0} seconds. Restore Author=kotovasia5120 - - Back - Author=kotovasia5120 - - - LoginVerify - Author=kotovasia5120 - + + Back + Author=kotovasia5120 + + + Window + + + LoginVerify + Author=kotovasia5120 + Steam2FACode Author=kotovasia5120 @@ -4823,4 +4832,4 @@ or switch the Steam client login account to the same as the card hanging account Welcome to Watt Toolkit Author=kotovasia5120 - \ No newline at end of file + diff --git a/src/BD.WTTS.Client/Resources/Strings.resx b/src/BD.WTTS.Client/Resources/Strings.resx index 29ec94ede42..32accc9a766 100644 --- a/src/BD.WTTS.Client/Resources/Strings.resx +++ b/src/BD.WTTS.Client/Resources/Strings.resx @@ -298,6 +298,12 @@ 关闭 + + + 隐藏 {0} + + + 隐藏窗口 最小化 @@ -310,6 +316,9 @@ 返回 + + + 窗口 确定 @@ -3030,4 +3039,4 @@ 打开 Steam App 绑定令牌后在此页面输入验证 - \ No newline at end of file +