Files
2dust_v2rayN/v2rayN/v2rayN.Desktop/App.axaml.cs
T
JieXu 54a3388c99 Update App.axaml.cs (#9421)
* Update App.axaml.cs

* Update App.axaml.cs

* Create MacOSAppHelper.cs

* Update App.axaml.cs

Removed unused macOS activation policy methods and constants.

* Update and rename MacOSAppHelper.cs to MacAppUtils.cs

* Update App.axaml.cs
2026-05-31 17:57:59 +08:00

91 lines
2.7 KiB
C#

using v2rayN.Desktop.Common;
using v2rayN.Desktop.Views;
namespace v2rayN.Desktop;
public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
if (!Design.IsDesignMode)
{
AppManager.Instance.InitComponents();
DataContext = StatusBarViewModel.Instance;
}
desktop.Exit += OnExit;
desktop.MainWindow = new MainWindow();
if (OperatingSystem.IsMacOS())
{
Current?.TryGetFeature<IActivatableLifetime>()?.Activated += OnMacOSActivated;
}
}
base.OnFrameworkInitializationCompleted();
}
private void OnMacOSActivated(object? sender, ActivatedEventArgs args)
{
if (args.Kind != ActivationKind.Reopen)
{
return;
}
Dispatcher.UIThread.Post(() =>
{
((ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow as MainWindow)?.ShowHideWindow(true);
if (!AppManager.Instance.Config.UiItem.MacOSShowInDock)
{
MacAppUtils.SetActivationPolicyAccessory();
}
});
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (e.ExceptionObject != null)
{
Logging.SaveLog("CurrentDomain_UnhandledException", (Exception)e.ExceptionObject);
}
}
private void TaskScheduler_UnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
{
Logging.SaveLog("TaskScheduler_UnobservedTaskException", e.Exception);
}
private void OnExit(object? sender, ControlledApplicationLifetimeExitEventArgs e)
{
}
private async void MenuAddServerViaClipboardClick(object? sender, EventArgs e)
{
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
if (desktop.MainWindow != null)
{
AppEvents.AddServerViaClipboardRequested.Publish();
await Task.Delay(1000);
}
}
}
private async void MenuExit_Click(object? sender, EventArgs e)
{
await AppManager.Instance.AppExitAsync(false);
AppManager.Instance.Shutdown(true);
}
}