From 0d74452c6c36791520778a692bffbfd90ec64a18 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 21 Jun 2025 17:00:49 +0800 Subject: [PATCH] Added parameter MacOSShowInDock to control whether MacOS platform app is displayed in the Dock https://github.com/2dust/v2rayN/issues/7465 --- v2rayN/ServiceLib/Models/ConfigItems.cs | 1 + v2rayN/v2rayN.Desktop/App.axaml.cs | 5 ---- v2rayN/v2rayN.Desktop/Program.cs | 40 +++++++++++++++++-------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/v2rayN/ServiceLib/Models/ConfigItems.cs b/v2rayN/ServiceLib/Models/ConfigItems.cs index afd7e7cc..08ce284b 100644 --- a/v2rayN/ServiceLib/Models/ConfigItems.cs +++ b/v2rayN/ServiceLib/Models/ConfigItems.cs @@ -105,6 +105,7 @@ public class UIItem public bool Hide2TrayWhenClose { get; set; } public List MainColumnItem { get; set; } public bool ShowInTaskbar { get; set; } + public bool MacOSShowInDock { get; set; } } [Serializable] diff --git a/v2rayN/v2rayN.Desktop/App.axaml.cs b/v2rayN/v2rayN.Desktop/App.axaml.cs index 7626edfd..ebd5c29a 100644 --- a/v2rayN/v2rayN.Desktop/App.axaml.cs +++ b/v2rayN/v2rayN.Desktop/App.axaml.cs @@ -11,11 +11,6 @@ public partial class App : Application { public override void Initialize() { - if (!AppHandler.Instance.InitApp()) - { - Environment.Exit(0); - return; - } AvaloniaXamlLoader.Load(this); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; diff --git a/v2rayN/v2rayN.Desktop/Program.cs b/v2rayN/v2rayN.Desktop/Program.cs index 15efc023..805e5a50 100644 --- a/v2rayN/v2rayN.Desktop/Program.cs +++ b/v2rayN/v2rayN.Desktop/Program.cs @@ -14,13 +14,17 @@ internal class Program [STAThread] public static void Main(string[] args) { - OnStartup(args); + if (OnStartup(args) == false) + { + Environment.Exit(0); + return; + } BuildAvaloniaApp() .StartWithClassicDesktopLifetime(args); } - private static void OnStartup(string[]? Args) + private static bool OnStartup(string[]? Args) { if (Utils.IsWindows()) { @@ -30,8 +34,7 @@ internal class Program if (!rebootas && !bCreatedNew) { ProgramStarted.Set(); - Environment.Exit(0); - return; + return false; } } else @@ -39,19 +42,30 @@ internal class Program _ = new Mutex(true, "v2rayN", out var bOnlyOneInstance); if (!bOnlyOneInstance) { - Environment.Exit(0); - return; + return false; } } + + if (!AppHandler.Instance.InitApp()) + { + return false; + } + return true; } // Avalonia configuration, don't remove; also used by visual designer. public static AppBuilder BuildAvaloniaApp() - => AppBuilder.Configure() - .UsePlatformDetect() - //.WithInterFont() - .WithFontByDefault() - .LogToTrace() - .UseReactiveUI() - .With(new MacOSPlatformOptions { ShowInDock = false }); + { + return AppBuilder.Configure() + .UsePlatformDetect() + //.WithInterFont() + .WithFontByDefault() + .LogToTrace() +#if OS_OSX + .UseReactiveUI() + .With(new MacOSPlatformOptions { ShowInDock = AppHandler.Instance.Config.UiItem.MacOSShowInDock }); +#else + .UseReactiveUI(); +#endif + } }