Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/App.Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public static bool IsCheckForUpdateCommandVisible
}
}

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()));
Expand Down
37 changes: 36 additions & 1 deletion src/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Avalonia.Media.Fonts;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using Avalonia.Platform.Storage;
using Avalonia.Styling;
using Avalonia.Threading;
Expand Down Expand Up @@ -85,6 +87,7 @@ public override void Initialize()
SetLocale(pref.Locale);
SetTheme(pref.Theme, pref.ThemeOverrides);
SetFonts(pref.DefaultFontFamily, pref.MonospaceFontFamily, pref.OnlyUseMonoFontInEditor);
SetupTrayIcon(pref.SystemTrayIcon);
}

public override void OnFrameworkInitializationCompleted()
Expand Down Expand Up @@ -192,6 +195,34 @@ public static void SetTheme(string theme, string themeOverridesFile)
}
}

public static void SetupTrayIcon(bool enable)
{
if (enable)
{
var icons = new TrayIcons {
new TrayIcon {
Icon = new WindowIcon(new Bitmap(AssetLoader.Open(new Uri("avares://SourceGit/App.ico")))),
Menu = [
new NativeMenuItem(Text("Open")) {Command = Unminimize},
new NativeMenuItem(Text("Preference")) {Command = OpenPreferenceCommand},
new NativeMenuItemSeparator(),
new NativeMenuItem(Text("Quit")) {Command = QuitCommand},
]
}
};
icons[0].Clicked += (_, _) => ShowWindow();
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;
Expand Down Expand Up @@ -545,11 +576,15 @@ private void TryLaunchedAsNormal(IClassicDesktopStyleApplicationLifetime desktop
if (desktop.Args != null && desktop.Args.Length == 1 && Directory.Exists(desktop.Args[0]))
startupRepo = desktop.Args[0];

var pref = ViewModels.Preference.Instance;
if (pref.SystemTrayIcon) {
desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown;
}

_launcher = new ViewModels.Launcher(startupRepo);
desktop.MainWindow = new Views.Launcher() { DataContext = _launcher };

#if !DISABLE_UPDATE_DETECTION
var pref = ViewModels.Preference.Instance;
if (pref.ShouldCheck4UpdateOnStartup())
Check4Update();
#endif
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@
<x:String x:Key="Text.MoveRepositoryNode.Target" xml:space="preserve">Select parent node for:</x:String>
<x:String x:Key="Text.Name" xml:space="preserve">Name:</x:String>
<x:String x:Key="Text.NotConfigured" xml:space="preserve">Git has NOT been configured. Please to go [Preference] and configure it first.</x:String>
<x:String x:Key="Text.Open" xml:space="preserve">Open SourceGit</x:String>
<x:String x:Key="Text.OpenAppDataDir" xml:space="preserve">Open Data Storage Directory</x:String>
<x:String x:Key="Text.OpenWith" xml:space="preserve">Open with...</x:String>
<x:String x:Key="Text.Optional" xml:space="preserve">Optional.</x:String>
Expand Down
8 changes: 8 additions & 0 deletions src/ViewModels/Preference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ public double LastCheckUpdateTime
set => SetProperty(ref _lastCheckUpdateTime, value);
}

public bool SystemTrayIcon
{
get => _systemTrayIcon;
set => SetProperty(ref _systemTrayIcon, value);
}

public bool IsGitConfigured()
{
var path = GitInstallPath;
Expand Down Expand Up @@ -663,5 +669,7 @@ private string FixFontFamilyName(string name)
private string _externalMergeToolPath = string.Empty;

private uint _statisticsSampleColor = 0xFF00FF00;

private bool _systemTrayIcon = false;
}
}
8 changes: 7 additions & 1 deletion src/Views/Launcher.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,13 @@ protected override void OnKeyUp(KeyEventArgs e)

protected override void OnClosing(WindowClosingEventArgs e)
{
(DataContext as ViewModels.Launcher)?.Quit(Width, Height);
var pref = ViewModels.Preference.Instance;
if (pref.SystemTrayIcon) {
e.Cancel = true;
Hide();
} else {
(DataContext as ViewModels.Launcher)?.Quit(Width, Height);
}
base.OnClosing(e);
}

Expand Down
Loading