diff --git a/src/App.Commands.cs b/src/App.Commands.cs index 56c15009..daa930b7 100644 --- a/src/App.Commands.cs +++ b/src/App.Commands.cs @@ -81,14 +81,17 @@ namespace SourceGit public static readonly Command HideAppCommand = new Command(_ => { - if (Current is App app && app.TryGetFeature(typeof(IActivatableLifetime)) is IActivatableLifetime lifetime) - lifetime.TryEnterBackground(); + Native.OS.HideSelf(); }); - public static readonly Command ShowAppCommand = new Command(_ => + public static readonly Command HideOtherApplicationsCommand = new Command(_ => { - if (Current is App app && app.TryGetFeature(typeof(IActivatableLifetime)) is IActivatableLifetime lifetime) - lifetime.TryLeaveBackground(); + Native.OS.HideOtherApplications(); + }); + + public static readonly Command ShowAllApplicationsCommand = new Command(_ => + { + Native.OS.ShowAllApplications(); }); } } diff --git a/src/App.axaml b/src/App.axaml index a7a0c17f..2fa98263 100644 --- a/src/App.axaml +++ b/src/App.axaml @@ -45,7 +45,8 @@ - + + diff --git a/src/Native/Linux.cs b/src/Native/Linux.cs index 881c9bcf..e411cbce 100644 --- a/src/Native/Linux.cs +++ b/src/Native/Linux.cs @@ -33,6 +33,21 @@ namespace SourceGit.Native } } + public void HideSelf() + { + // Do Nothing. Never used. + } + + public void HideOtherApplications() + { + // Do Nothing. Never used. + } + + public void ShowAllApplications() + { + // Do Nothing. Never used. + } + public string GetDataDir() { // AppImage supports portable mode diff --git a/src/Native/MacOS.cs b/src/Native/MacOS.cs index fe0c0475..6431d771 100644 --- a/src/Native/MacOS.cs +++ b/src/Native/MacOS.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Runtime.InteropServices; using System.Runtime.Versioning; using Avalonia; @@ -13,6 +14,18 @@ namespace SourceGit.Native [SupportedOSPlatform("macOS")] internal class MacOS : OS.IBackend { + [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_getClass")] + public static extern IntPtr objc_getClass(string name); + + [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "sel_registerName")] + public static extern IntPtr sel_registerName(string name); + + [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] + public static extern IntPtr objc_msgSend(IntPtr receiver, IntPtr selector); + + [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] + public static extern IntPtr objc_msgSendWithArg(IntPtr receiver, IntPtr selector, IntPtr arg); + public void SetupApp(AppBuilder builder) { builder.With(new MacOSPlatformOptions() @@ -44,6 +57,39 @@ namespace SourceGit.Native window.ExtendClientAreaToDecorationsHint = true; } + public void HideSelf() + { + IntPtr nsApplicationClass = objc_getClass("NSApplication"); + IntPtr nsSharedApplicationSelector = sel_registerName("sharedApplication"); + IntPtr nsApp = objc_msgSend(nsApplicationClass, nsSharedApplicationSelector); + IntPtr nsMethodSelector = sel_registerName("hide:"); + IntPtr nsDelegateSelector = sel_registerName("delegate"); + IntPtr nsDelegate = objc_msgSend(nsApp, nsDelegateSelector); + objc_msgSendWithArg(nsApp, nsMethodSelector, nsDelegate); + } + + public void HideOtherApplications() + { + IntPtr nsApplicationClass = objc_getClass("NSApplication"); + IntPtr nsSharedApplicationSelector = sel_registerName("sharedApplication"); + IntPtr nsApp = objc_msgSend(nsApplicationClass, nsSharedApplicationSelector); + IntPtr nsMethodSelector = sel_registerName("hideOtherApplications:"); + IntPtr nsDelegateSelector = sel_registerName("delegate"); + IntPtr nsDelegate = objc_msgSend(nsApp, nsDelegateSelector); + objc_msgSendWithArg(nsApp, nsMethodSelector, nsDelegate); + } + + public void ShowAllApplications() + { + IntPtr nsApplicationClass = objc_getClass("NSApplication"); + IntPtr nsSharedApplicationSelector = sel_registerName("sharedApplication"); + IntPtr nsApp = objc_msgSend(nsApplicationClass, nsSharedApplicationSelector); + IntPtr nsMethodSelector = sel_registerName("unhideAllApplications:"); + IntPtr nsDelegateSelector = sel_registerName("delegate"); + IntPtr nsDelegate = objc_msgSend(nsApp, nsDelegateSelector); + objc_msgSendWithArg(nsApp, nsMethodSelector, nsDelegate); + } + public string GetDataDir() { return Path.Combine( diff --git a/src/Native/OS.cs b/src/Native/OS.cs index 7c12287a..6f899f23 100644 --- a/src/Native/OS.cs +++ b/src/Native/OS.cs @@ -18,6 +18,10 @@ namespace SourceGit.Native void SetupApp(AppBuilder builder); void SetupWindow(Window window); + void HideSelf(); + void HideOtherApplications(); + void ShowAllApplications(); + string GetDataDir(); string FindGitExecutable(); string FindTerminal(Models.ShellOrTerminal shell); @@ -154,6 +158,21 @@ namespace SourceGit.Native _backend.SetupWindow(window); } + public static void HideSelf() + { + _backend.HideSelf(); + } + + public static void HideOtherApplications() + { + _backend.HideOtherApplications(); + } + + public static void ShowAllApplications() + { + _backend.ShowAllApplications(); + } + public static void LogException(Exception ex) { if (ex == null) diff --git a/src/Native/Windows.cs b/src/Native/Windows.cs index e71c0de7..35b8aba6 100644 --- a/src/Native/Windows.cs +++ b/src/Native/Windows.cs @@ -58,6 +58,21 @@ namespace SourceGit.Native window.BorderThickness = new Thickness(1); } + public void HideSelf() + { + // Do Nothing. Never used. + } + + public void HideOtherApplications() + { + // Do Nothing. Never used. + } + + public void ShowAllApplications() + { + // Do Nothing. Never used. + } + public string GetDataDir() { var execFile = Process.GetCurrentProcess().MainModule!.FileName; diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 07e2fcec..556f2259 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -23,6 +23,7 @@ Use AI to generate commit message Use Hide SourceGit + Hide Others Show All Patch 3-Way Merge diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 2f977a51..0d874891 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -27,7 +27,8 @@ 使用AI助手生成提交信息 应用所选 隐藏 SourceGit - 显示所有窗口 + 隐藏其他 + 显示全部 应用补丁(apply) 尝试三路合并 补丁文件 : diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index bbd0d0eb..e9db5ca0 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -27,7 +27,8 @@ 使用 AI 產生提交訊息 套用選取 隱藏 SourceGit - 顯示所有 + 隱藏其他 + 顯示全部 套用修補檔 (apply patch) 嘗試三向合併 修補檔: