using Avalonia; using Avalonia.ReactiveUI; using v2rayN.Desktop.Common; namespace v2rayN.Desktop; internal class Program { public static EventWaitHandle ProgramStarted; // Initialization code. Don't use any Avalonia, third-party APIs or any // SynchronizationContext-reliant code before AppMain is called: things aren't initialized // yet and stuff might break. [STAThread] public static void Main(string[] args) { if (OnStartup(args) == false) { Environment.Exit(0); return; } BuildAvaloniaApp() .StartWithClassicDesktopLifetime(args); } private static bool OnStartup(string[]? Args) { if (Utils.IsWindows()) { var exePathKey = Utils.GetMd5(Utils.GetExePath()); var rebootas = (Args ?? []).Any(t => t == Global.RebootAs); ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, exePathKey, out var bCreatedNew); if (!rebootas && !bCreatedNew) { ProgramStarted.Set(); return false; } } else { _ = new Mutex(true, "v2rayN", out var bOnlyOneInstance); if (!bOnlyOneInstance) { return false; } } if (!AppHandler.Instance.InitApp()) { return false; } return true; } // Avalonia configuration, don't remove; also used by visual designer. public static AppBuilder BuildAvaloniaApp() { return AppBuilder.Configure() .UsePlatformDetect() //.WithInterFont() .WithFontByDefault() .LogToTrace() .UseReactiveUI() .With(new MacOSPlatformOptions { ShowInDock = AppHandler.Instance.Config.UiItem.MacOSShowInDock }); } }