From 35eafd6784f687c9b88b22157ec30a3eae37560e Mon Sep 17 00:00:00 2001 From: Vladimir Eremeev Date: Fri, 13 Dec 2024 16:36:44 +0300 Subject: [PATCH] Handle system tray menu items Show main window Open preferences --- src/App.Commands.cs | 3 ++- src/App.axaml.cs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/App.Commands.cs b/src/App.Commands.cs index 1a40f5ce..172c7320 100644 --- a/src/App.Commands.cs +++ b/src/App.Commands.cs @@ -37,7 +37,8 @@ namespace SourceGit } } - public static readonly Command OpenPreferenceCommand = new Command(_ => { OpenDialog(new Views.Preference()); }); + public static readonly Command Unminimize = new Command(_ => ShowWindow()); + public static readonly Command OpenPreferenceCommand = new Command(_ => { ShowWindow(); OpenDialog(new Views.Preference()); }); public static readonly Command OpenHotkeysCommand = new Command(_ => OpenDialog(new Views.Hotkeys())); public static readonly Command OpenAppDataDirCommand = new Command(_ => Native.OS.OpenInFileManager(Native.OS.DataDir)); public static readonly Command OpenAboutCommand = new Command(_ => OpenDialog(new Views.About())); diff --git a/src/App.axaml.cs b/src/App.axaml.cs index cdd7f371..7ee837a0 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -203,7 +203,7 @@ namespace SourceGit new TrayIcon { Icon = new WindowIcon(new Bitmap(AssetLoader.Open(new Uri("avares://SourceGit/App.ico")))), Menu = [ - new NativeMenuItem(Text("Open")), + new NativeMenuItem(Text("Open")) {Command = Unminimize}, new NativeMenuItem(Text("Preference")) {Command = OpenPreferenceCommand}, new NativeMenuItemSeparator(), new NativeMenuItem(Text("Quit")) {Command = QuitCommand}, @@ -214,7 +214,15 @@ namespace SourceGit TrayIcon.SetIcons(Current, icons); } } - + private static void ShowWindow() + { + if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { + desktop.MainWindow.WindowState = WindowState.Normal; + desktop.MainWindow.Show(); + desktop.MainWindow.BringIntoView(); + desktop.MainWindow.Focus(); + } + } public static void SetFonts(string defaultFont, string monospaceFont, bool onlyUseMonospaceFontInEditor) { var app = Current as App;