Skip to content

Commit 68716eb

Browse files
committed
feature: supports to use ⌘+H to hide this app on macOS (#1716)
Signed-off-by: leo <longshuang@msn.cn>
1 parent a5afe0a commit 68716eb

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

src/App.Commands.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Windows.Input;
3+
34
using Avalonia.Controls;
5+
using Avalonia.Controls.ApplicationLifetimes;
46

57
namespace SourceGit
68
{
@@ -53,5 +55,17 @@ public static bool IsCheckForUpdateCommandVisible
5355
else if (!string.IsNullOrEmpty(textBlock.Text))
5456
await CopyTextAsync(textBlock.Text);
5557
});
58+
59+
public static readonly Command HideAppCommand = new Command(_ =>
60+
{
61+
if (Current is App app && app.TryGetFeature(typeof(IActivatableLifetime)) is IActivatableLifetime lifetime)
62+
lifetime.TryEnterBackground();
63+
});
64+
65+
public static readonly Command ShowAppCommand = new Command(_ =>
66+
{
67+
if (Current is App app && app.TryGetFeature(typeof(IActivatableLifetime)) is IActivatableLifetime lifetime)
68+
lifetime.TryLeaveBackground();
69+
});
5670
}
5771
}

src/App.axaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
<NativeMenuItem Header="{DynamicResource Text.Preferences}" Command="{x:Static s:App.OpenPreferencesCommand}" Gesture="⌘+,"/>
4343
<NativeMenuItem Header="{DynamicResource Text.OpenAppDataDir}" Command="{x:Static s:App.OpenAppDataDirCommand}"/>
4444
<NativeMenuItemSeparator/>
45+
<NativeMenuItem Header="{DynamicResource Text.App.Hide}" Command="{x:Static s:App.HideAppCommand}" Gesture="⌘+H"/>
46+
<NativeMenuItem Header="{DynamicResource Text.App.ShowAll}" Command="{x:Static s:App.ShowAppCommand}"/>
47+
<NativeMenuItemSeparator/>
4548
<NativeMenuItem Header="{DynamicResource Text.Quit}" Command="{x:Static s:App.QuitCommand}" Gesture="⌘+Q"/>
4649
</NativeMenu>
4750
</NativeMenu.Menu>

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
<x:String x:Key="Text.AIAssistant.Regen" xml:space="preserve">RE-GENERATE</x:String>
2020
<x:String x:Key="Text.AIAssistant.Tip" xml:space="preserve">Use AI to generate commit message</x:String>
2121
<x:String x:Key="Text.AIAssistant.Use" xml:space="preserve">APPLY AS COMMIT MESSAGE</x:String>
22+
<x:String x:Key="Text.App.Hide" xml:space="preserve">Hide SourceGit</x:String>
23+
<x:String x:Key="Text.App.ShowAll" xml:space="preserve">Show All</x:String>
2224
<x:String x:Key="Text.Apply" xml:space="preserve">Patch</x:String>
2325
<x:String x:Key="Text.Apply.File" xml:space="preserve">Patch File:</x:String>
2426
<x:String x:Key="Text.Apply.File.Placeholder" xml:space="preserve">Select .patch file to apply</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
<x:String x:Key="Text.AIAssistant.Regen" xml:space="preserve">重新生成</x:String>
2424
<x:String x:Key="Text.AIAssistant.Tip" xml:space="preserve">使用AI助手生成提交信息</x:String>
2525
<x:String x:Key="Text.AIAssistant.Use" xml:space="preserve">应用本次生成</x:String>
26+
<x:String x:Key="Text.App.Hide" xml:space="preserve">隐藏 SourceGit</x:String>
27+
<x:String x:Key="Text.App.ShowAll" xml:space="preserve">显示所有窗口</x:String>
2628
<x:String x:Key="Text.Apply" xml:space="preserve">应用补丁(apply)</x:String>
2729
<x:String x:Key="Text.Apply.File" xml:space="preserve">补丁文件 :</x:String>
2830
<x:String x:Key="Text.Apply.File.Placeholder" xml:space="preserve">选择补丁文件</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
<x:String x:Key="Text.AIAssistant.Regen" xml:space="preserve">重新產生</x:String>
2424
<x:String x:Key="Text.AIAssistant.Tip" xml:space="preserve">使用 AI 產生提交訊息</x:String>
2525
<x:String x:Key="Text.AIAssistant.Use" xml:space="preserve">套用為提交訊息</x:String>
26+
<x:String x:Key="Text.App.Hide" xml:space="preserve">隱藏 SourceGit</x:String>
27+
<x:String x:Key="Text.App.ShowAll" xml:space="preserve">顯示所有</x:String>
2628
<x:String x:Key="Text.Apply" xml:space="preserve">套用修補檔 (apply patch)</x:String>
2729
<x:String x:Key="Text.Apply.File" xml:space="preserve">修補檔:</x:String>
2830
<x:String x:Key="Text.Apply.File.Placeholder" xml:space="preserve">選擇修補檔</x:String>

0 commit comments

Comments
 (0)