Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 85 additions & 4 deletions src/BD.WTTS.Client.Avalonia/UI/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AngleSharp.Dom;
using Avalonia.Input;
using BD.WTTS.Client.Resources;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
Expand All @@ -17,14 +18,94 @@ public App()
OpenBrowserCommand = ReactiveCommand.Create<object?>(OpenBrowserCommandCore);
CopyToClipboardCommand = ReactiveCommand.Create<object?>(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

/// <summary>
/// 获取当前主窗口
/// </summary>
Expand Down
43 changes: 26 additions & 17 deletions src/BD.WTTS.Client/Resources/Strings.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3136,14 +3136,20 @@ The system will {1} after {0} seconds.</value>
<value>On</value>
<comment>Author=kotovasia5120</comment>
</data>
<data name="Close" xml:space="preserve">
<value>Close</value>
<comment>Author=kotovasia5120</comment>
</data>
<data name="Minimize" xml:space="preserve">
<value>Minimize</value>
<comment>Author=kotovasia5120</comment>
</data>
<data name="Close" xml:space="preserve">
<value>Close</value>
<comment>Author=kotovasia5120</comment>
</data>
<data name="HideApp_" xml:space="preserve">
<value>Hide {0}</value>
</data>
<data name="HideWindow" xml:space="preserve">
<value>Hide Window</value>
</data>
<data name="Minimize" xml:space="preserve">
<value>Minimize</value>
<comment>Author=kotovasia5120</comment>
</data>
<data name="Maximize" xml:space="preserve">
<value>Maximize</value>
<comment>Author=kotovasia5120</comment>
Expand All @@ -3152,14 +3158,17 @@ The system will {1} after {0} seconds.</value>
<value>Restore</value>
<comment>Author=kotovasia5120</comment>
</data>
<data name="Back" xml:space="preserve">
<value>Back</value>
<comment>Author=kotovasia5120</comment>
</data>
<data name="LoginVerify" xml:space="preserve">
<value>LoginVerify</value>
<comment>Author=kotovasia5120</comment>
</data>
<data name="Back" xml:space="preserve">
<value>Back</value>
<comment>Author=kotovasia5120</comment>
</data>
<data name="WindowMenu" xml:space="preserve">
<value>Window</value>
</data>
<data name="LoginVerify" xml:space="preserve">
<value>LoginVerify</value>
<comment>Author=kotovasia5120</comment>
</data>
<data name="Steam2FACode" xml:space="preserve">
<value>Steam2FACode</value>
<comment>Author=kotovasia5120</comment>
Expand Down Expand Up @@ -4823,4 +4832,4 @@ or switch the Steam client login account to the same as the card hanging account
<value>Welcome to Watt Toolkit</value>
<comment>Author=kotovasia5120</comment>
</data>
</root>
</root>
11 changes: 10 additions & 1 deletion src/BD.WTTS.Client/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@
</data>
<data name="Close" xml:space="preserve">
<value>关闭</value>
</data>
<data name="HideApp_" xml:space="preserve">
<value>隐藏 {0}</value>
</data>
<data name="HideWindow" xml:space="preserve">
<value>隐藏窗口</value>
</data>
<data name="Minimize" xml:space="preserve">
<value>最小化</value>
Expand All @@ -310,6 +316,9 @@
</data>
<data name="Back" xml:space="preserve">
<value>返回</value>
</data>
<data name="WindowMenu" xml:space="preserve">
<value>窗口</value>
</data>
<data name="Confirm" xml:space="preserve">
<value>确定</value>
Expand Down Expand Up @@ -3030,4 +3039,4 @@
<data name="LocalAuth_JoinSteamAuthenticator_InputSteamAppAuthenticatorCodeTips" xml:space="preserve">
<value>打开 Steam App 绑定令牌后在此页面输入验证</value>
</data>
</root>
</root>