|
16 | 16 | usingAvalonia.Markup.Xaml; |
17 | 17 | usingAvalonia.Media; |
18 | 18 | usingAvalonia.Media.Fonts; |
| 19 | +usingAvalonia.Media.Imaging; |
| 20 | +usingAvalonia.Platform; |
19 | 21 | usingAvalonia.Platform.Storage; |
20 | 22 | usingAvalonia.Styling; |
21 | 23 | usingAvalonia.Threading; |
@@ -169,6 +171,46 @@ public static void SetTheme(string theme, string themeOverridesFile) |
169 | 171 | } |
170 | 172 | } |
171 | 173 |
|
| 174 | +publicvoidSetupTrayIcon(boolenable) |
| 175 | +{ |
| 176 | +if(enable&&Native.OS.EnsureSingleInstance()) |
| 177 | +{ |
| 178 | +varicons=newTrayIcons{ |
| 179 | +newTrayIcon{ |
| 180 | +Icon=newWindowIcon(newBitmap(AssetLoader.Open(newUri("avares://SourceGit/App.ico")))), |
| 181 | +Menu=[ |
| 182 | +newNativeMenuItem(Text("Open")){Command=Unminimize}, |
| 183 | +newNativeMenuItem(Text("Preferences")){Command=OpenPreferencesCommand}, |
| 184 | +newNativeMenuItemSeparator(), |
| 185 | +newNativeMenuItem(Text("Quit")){Command=QuitCommand}, |
| 186 | +] |
| 187 | +} |
| 188 | +}; |
| 189 | +icons[0].Clicked+=(_,_)=>ToggleWindow(); |
| 190 | +TrayIcon.SetIcons(Current,icons); |
| 191 | +_createdSystemTrayIcon=true; |
| 192 | +} |
| 193 | +} |
| 194 | + |
| 195 | +privatestaticvoidToggleWindow(){ |
| 196 | +if(Current?.ApplicationLifetimeisIClassicDesktopStyleApplicationLifetimedesktop){ |
| 197 | +if(desktop.MainWindow.IsVisible){ |
| 198 | +desktop.MainWindow.Hide(); |
| 199 | +}else{ |
| 200 | +ShowWindow(); |
| 201 | +} |
| 202 | +} |
| 203 | +} |
| 204 | + |
| 205 | +privatestaticvoidShowWindow() |
| 206 | +{ |
| 207 | +if(Current?.ApplicationLifetimeisIClassicDesktopStyleApplicationLifetimedesktop){ |
| 208 | +desktop.MainWindow.WindowState=WindowState.Normal; |
| 209 | +desktop.MainWindow.Show(); |
| 210 | +desktop.MainWindow.BringIntoView(); |
| 211 | +desktop.MainWindow.Focus(); |
| 212 | +} |
| 213 | +} |
172 | 214 | publicstaticvoidSetFonts(stringdefaultFont,stringmonospaceFont,boolonlyUseMonospaceFontInEditor) |
173 | 215 | { |
174 | 216 | varapp=CurrentasApp; |
@@ -322,6 +364,7 @@ public override void OnFrameworkInitializationCompleted() |
322 | 364 |
|
323 | 365 | TryLaunchAsNormal(desktop); |
324 | 366 | } |
| 367 | +base.OnFrameworkInitializationCompleted(); |
325 | 368 | } |
326 | 369 | #endregion |
327 | 370 |
|
@@ -477,11 +520,17 @@ private void TryLaunchAsNormal(IClassicDesktopStyleApplicationLifetime desktop) |
477 | 520 | if(desktop.Args!=null&&desktop.Args.Length==1&&Directory.Exists(desktop.Args[0])) |
478 | 521 | startupRepo=desktop.Args[0]; |
479 | 522 |
|
480 | | -_launcher=newViewModels.Launcher(startupRepo); |
| 523 | +varpref=ViewModels.Preferences.Instance; |
| 524 | + |
| 525 | +SetupTrayIcon(pref.SystemTrayIcon); |
| 526 | +if(_createdSystemTrayIcon){ |
| 527 | +desktop.ShutdownMode=ShutdownMode.OnExplicitShutdown; |
| 528 | +} |
| 529 | + |
| 530 | +_launcher=newViewModels.Launcher(startupRepo){InterceptQuit=_createdSystemTrayIcon}; |
481 | 531 | desktop.MainWindow=newViews.Launcher(){DataContext=_launcher}; |
482 | 532 |
|
483 | 533 | #if !DISABLE_UPDATE_DETECTION |
484 | | -varpref=ViewModels.Preferences.Instance; |
485 | 534 | if(pref.ShouldCheck4UpdateOnStartup()) |
486 | 535 | Check4Update(); |
487 | 536 | #endif |
@@ -544,5 +593,6 @@ private void ShowSelfUpdateResult(object data) |
544 | 593 | privateResourceDictionary_activeLocale=null; |
545 | 594 | privateResourceDictionary_themeOverrides=null; |
546 | 595 | privateResourceDictionary_fontsOverrides=null; |
| 596 | +privatebool_createdSystemTrayIcon=false; |
547 | 597 | } |
548 | 598 | } |
0 commit comments