mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-22 00:54:26 +08:00
0.5.14
二次启动拦截,统一了生命进程API
This commit is contained in:
@@ -17,6 +17,15 @@ sealed class Program
|
||||
AppLogger.Initialize();
|
||||
RegisterGlobalExceptionLogging();
|
||||
|
||||
using var singleInstance = SingleInstanceService.CreateDefault();
|
||||
if (!singleInstance.IsPrimaryInstance)
|
||||
{
|
||||
AppLogger.Warn("Startup", "A secondary launch was blocked because another instance is already running.");
|
||||
var notified = singleInstance.TryNotifyPrimaryInstance(TimeSpan.FromSeconds(2));
|
||||
ShowAlreadyRunningNotice(notified);
|
||||
return;
|
||||
}
|
||||
|
||||
var diagnostics = StartupDiagnosticsService.Run(args);
|
||||
StartupDiagnosticsService.ShowLegacyExecutableWarningIfNeeded(diagnostics);
|
||||
|
||||
@@ -24,6 +33,7 @@ sealed class Program
|
||||
{
|
||||
var renderMode = LoadConfiguredRenderMode();
|
||||
AppLogger.Info("Startup", $"Resolved render mode '{renderMode}'.");
|
||||
App.CurrentSingleInstanceService = singleInstance;
|
||||
BuildAvaloniaApp(renderMode).StartWithClassicDesktopLifetime(args);
|
||||
AppLogger.Info("Startup", "Application exited normally.");
|
||||
}
|
||||
@@ -32,6 +42,10 @@ sealed class Program
|
||||
AppLogger.Critical("Startup", "Application terminated during startup.", ex);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
App.CurrentSingleInstanceService = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Avalonia configuration, don't remove; also used by visual designer.
|
||||
@@ -71,6 +85,16 @@ sealed class Program
|
||||
}
|
||||
}
|
||||
|
||||
private static void ShowAlreadyRunningNotice(bool notifiedPrimaryInstance)
|
||||
{
|
||||
const string caption = "LanMountainDesktop";
|
||||
var message = notifiedPrimaryInstance
|
||||
? "应用已打开,不需要多开了。\r\n\r\n已为你切换到正在运行的阑山桌面。"
|
||||
: "应用已打开,不需要多开了。\r\n\r\n请切换到正在运行的阑山桌面。";
|
||||
|
||||
WindowsNativeDialogService.ShowInformation(caption, message);
|
||||
}
|
||||
|
||||
private static void RegisterGlobalExceptionLogging()
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += (_, eventArgs) =>
|
||||
|
||||
Reference in New Issue
Block a user