Handle system tray menu items

Show main window
Open preferences
This commit is contained in:
Vladimir Eremeev 2024-12-13 16:36:44 +03:00
parent dce6db3a13
commit 35eafd6784
2 changed files with 12 additions and 3 deletions

View file

@ -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()));

View file

@ -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;