mirror of
https://github.com/2dust/v2rayN.git
synced 2026-11-06 12:35:00 +03:00
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
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using v2rayN.Desktop.Common;
|
||||||
using v2rayN.Desktop.Views;
|
using v2rayN.Desktop.Views;
|
||||||
|
|
||||||
namespace v2rayN.Desktop;
|
namespace v2rayN.Desktop;
|
||||||
@@ -24,11 +25,34 @@ public partial class App : Application
|
|||||||
|
|
||||||
desktop.Exit += OnExit;
|
desktop.Exit += OnExit;
|
||||||
desktop.MainWindow = new MainWindow();
|
desktop.MainWindow = new MainWindow();
|
||||||
|
|
||||||
|
if (OperatingSystem.IsMacOS())
|
||||||
|
{
|
||||||
|
Current?.TryGetFeature<IActivatableLifetime>()?.Activated += OnMacOSActivated;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
base.OnFrameworkInitializationCompleted();
|
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)
|
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.ExceptionObject != null)
|
if (e.ExceptionObject != null)
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace v2rayN.Desktop.Common;
|
||||||
|
|
||||||
|
internal static class MacAppUtils
|
||||||
|
{
|
||||||
|
private const string LibObjC = "/usr/lib/libobjc.dylib";
|
||||||
|
private const nint ActivationPolicyAccessory = 1;
|
||||||
|
|
||||||
|
public static void SetActivationPolicyAccessory()
|
||||||
|
=> objc_msgSend(
|
||||||
|
objc_msgSend(objc_getClass("NSApplication"), sel_registerName("sharedApplication")),
|
||||||
|
sel_registerName("setActivationPolicy:"),
|
||||||
|
ActivationPolicyAccessory);
|
||||||
|
|
||||||
|
[DllImport(LibObjC)]
|
||||||
|
private static extern nint objc_getClass(string name);
|
||||||
|
|
||||||
|
[DllImport(LibObjC)]
|
||||||
|
private static extern nint sel_registerName(string name);
|
||||||
|
|
||||||
|
[DllImport(LibObjC, EntryPoint = "objc_msgSend")]
|
||||||
|
private static extern nint objc_msgSend(nint receiver, nint selector);
|
||||||
|
|
||||||
|
[DllImport(LibObjC, EntryPoint = "objc_msgSend")]
|
||||||
|
private static extern void objc_msgSend(nint receiver, nint selector, nint argument);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user