Compare commits

...

6 Commits

Author SHA1 Message Date
2dust
da81101cfd up 7.22.7 2026-06-12 19:15:08 +08:00
DHR60
3d4f202cd7 Metrics listen directly (#9533) 2026-06-12 09:47:59 +08:00
2dust
35fbb137e8 Add vcn and pcs properties to VmessQRCode DTO 2026-06-12 09:47:03 +08:00
sparklelcm333
1869a95700 fix: Desktop(Avalonia) 移除子对话框最小化按钮,仅禁 CanMinimize (#9526) 2026-06-10 20:45:23 +08:00
JieXu
34359885ab Update AppBuilderExtension.cs (#9514)
* Update AppBuilderExtension.cs

* Update MainWindow.axaml.cs

* Update MacAppUtils.cs

* Update App.axaml.cs

* Add regions for MacOS activation and app events

---------

Co-authored-by: 2dust <31833384+2dust@users.noreply.github.com>
2026-06-09 17:00:51 +08:00
znah
93832656dd fix: disable .net9 CET (#9507) 2026-06-09 14:06:13 +08:00
14 changed files with 98 additions and 53 deletions

View File

@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Version>7.22.6</Version>
<Version>7.22.7</Version>
</PropertyGroup>
<PropertyGroup>

View File

@@ -66,7 +66,9 @@ public class VmessFmt : BaseFmt
sni = item.Sni,
alpn = item.Alpn,
fp = item.Fingerprint,
insecure = item.GetAllowInsecure() ? "1" : "0"
insecure = item.GetAllowInsecure() ? "1" : "0",
vcn = item.VerifyPeerCertByName,
pcs = item.CertSha
};
var url = JsonUtils.Serialize(vmessQRCode);
@@ -141,6 +143,8 @@ public class VmessFmt : BaseFmt
item.Alpn = Utils.ToString(vmessQRCode.alpn);
item.Fingerprint = Utils.ToString(vmessQRCode.fp);
item.AllowInsecure = vmessQRCode.insecure == "1" ? Global.StringTrue : string.Empty;
item.VerifyPeerCertByName = Utils.ToString(vmessQRCode.vcn);
item.CertSha = Utils.ToString(vmessQRCode.pcs);
return item;
}

View File

@@ -20,7 +20,7 @@ public class Stats4Ray
public class Metrics4Ray
{
public string tag { get; set; }
public string listen { get; set; }
}
public class Policy4Ray

View File

@@ -40,4 +40,8 @@ public class VmessQRCode
public string fp { get; set; } = string.Empty;
public string insecure { get; set; } = string.Empty;
public string vcn { get; set; } = string.Empty;
public string pcs { get; set; } = string.Empty;
}

View File

@@ -17,14 +17,6 @@
],
"routing": {
"domainStrategy": "IPIfNonMatch",
"rules": [
{
"inboundTag": [
"api"
],
"outboundTag": "api",
"type": "field"
}
]
"rules": []
}
}

View File

@@ -6,45 +6,19 @@ public partial class CoreConfigV2rayService
{
if (_config.GuiItem.EnableStatistics || _config.GuiItem.DisplayRealTimeSpeed)
{
const string tag = nameof(EInboundProtocol.api);
Metrics4Ray apiObj = new();
Metrics4Ray metricsObj = new();
Policy4Ray policyObj = new();
SystemPolicy4Ray policySystemSetting = new();
_coreConfig.stats = new Stats4Ray();
apiObj.tag = tag;
_coreConfig.metrics = apiObj;
metricsObj.listen = $"{Global.Loopback}:{AppManager.Instance.StatePort}";
_coreConfig.metrics = metricsObj;
policySystemSetting.statsOutboundDownlink = true;
policySystemSetting.statsOutboundUplink = true;
policyObj.system = policySystemSetting;
_coreConfig.policy = policyObj;
if (!_coreConfig.inbounds.Exists(item => item.tag == tag))
{
Inbounds4Ray apiInbound = new();
Inboundsettings4Ray apiInboundSettings = new();
apiInbound.tag = tag;
apiInbound.listen = Global.Loopback;
apiInbound.port = AppManager.Instance.StatePort;
apiInbound.protocol = Global.InboundAPIProtocol;
apiInboundSettings.address = Global.Loopback;
apiInbound.settings = apiInboundSettings;
_coreConfig.inbounds.Add(apiInbound);
}
if (!_coreConfig.routing.rules.Exists(item => item.outboundTag == tag))
{
RulesItem4Ray apiRoutingRule = new()
{
inboundTag = new List<string> { tag },
outboundTag = tag,
type = "field"
};
_coreConfig.routing.rules.Add(apiRoutingRule);
}
}
}
}

View File

@@ -23,8 +23,8 @@ public partial class App : Application
DataContext = StatusBarViewModel.Instance;
}
desktop.Exit += OnExit;
desktop.MainWindow = new MainWindow();
var mainWindow = new MainWindow();
desktop.MainWindow = mainWindow;
if (OperatingSystem.IsMacOS())
{
@@ -35,6 +35,8 @@ public partial class App : Application
base.OnFrameworkInitializationCompleted();
}
#region MacOS Activation
private void OnMacOSActivated(object? sender, ActivatedEventArgs args)
{
if (args.Kind != ActivationKind.Reopen)
@@ -42,17 +44,69 @@ public partial class App : Application
return;
}
if ((ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow is not MainWindow mainWindow)
{
return;
}
var isMiniaturized = MacAppUtils.IsWindowMiniaturized(mainWindow);
Dispatcher.UIThread.Post(() =>
{
if (isMiniaturized)
{
RestoreMacOSAccessoryPolicyAfterMiniaturize(mainWindow);
mainWindow.ShowHideWindow(true);
return;
}
if (!AppManager.Instance.Config.UiItem.MacOSShowInDock)
{
MacAppUtils.SetActivationPolicyAccessory();
}
((ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow as MainWindow)?.ShowHideWindow(true);
mainWindow.ShowHideWindow(true);
});
}
private static void RestoreMacOSAccessoryPolicyAfterMiniaturize(MainWindow mainWindow)
{
if (AppManager.Instance.Config.UiItem.MacOSShowInDock)
{
return;
}
mainWindow
.GetObservable(Window.WindowStateProperty)
.Skip(1)
.Where(state => state != WindowState.Minimized)
.Take(1)
.ObserveOn(RxSchedulers.MainThreadScheduler)
.Subscribe(_ => QueueMacOSAccessoryPolicyRestore(mainWindow));
}
private static void QueueMacOSAccessoryPolicyRestore(MainWindow mainWindow)
{
// AppKit may keep isMiniaturized set until the Dock restore animation finishes.
DispatcherTimer.RunOnce(() => RestoreMacOSAccessoryPolicy(mainWindow), TimeSpan.FromMilliseconds(300));
}
private static void RestoreMacOSAccessoryPolicy(MainWindow mainWindow)
{
if (AppManager.Instance.Config.UiItem.MacOSShowInDock || MacAppUtils.IsWindowMiniaturized(mainWindow))
{
return;
}
MacAppUtils.SetActivationPolicyAccessory();
mainWindow.Activate();
mainWindow.Focus();
}
#endregion MacOS Activation
#region App Event
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (e.ExceptionObject != null)
@@ -66,10 +120,6 @@ public partial class App : Application
Logging.SaveLog("TaskScheduler_UnobservedTaskException", e.Exception);
}
private void OnExit(object? sender, ControlledApplicationLifetimeExitEventArgs e)
{
}
private async void MenuAddServerViaClipboardClick(object? sender, EventArgs e)
{
try
@@ -91,4 +141,6 @@ public partial class App : Application
await AppManager.Instance.AppExitAsync(false);
AppManager.Instance.Shutdown(true);
}
#endregion App Event
}

View File

@@ -6,6 +6,13 @@ public class WindowBase<TViewModel> : ReactiveWindow<TViewModel> where TViewMode
{
Initialized += OnWindowInitialized;
Loaded += OnLoaded;
Loaded += (s, e) =>
{
if (Owner != null && !ShowInTaskbar)
{
CanMinimize = false;
}
};
}
private void ReactiveWindowBase_Closed(object? sender, EventArgs e)

View File

@@ -18,18 +18,18 @@ public static class AppBuilderExtension
if (OperatingSystem.IsWindows())
{
AddFontFallback(fallbacks, "Segoe UI Symbol");
AddFontFallback(fallbacks, "Segoe UI Emoji");
AddFontFallback(fallbacks, "Segoe UI Symbol");
}
else if (OperatingSystem.IsMacOS())
{
AddFontFallback(fallbacks, "Apple Symbols");
AddFontFallback(fallbacks, "Apple Color Emoji");
AddFontFallback(fallbacks, "Apple Symbols");
}
else if (OperatingSystem.IsLinux())
{
AddFontFallback(fallbacks, "Noto Sans Symbols");
AddFontFallback(fallbacks, "Noto Color Emoji");
AddFontFallback(fallbacks, "Noto Sans Symbols");
}
return appBuilder.With(new FontManagerOptions

View File

@@ -13,6 +13,10 @@ internal static class MacAppUtils
sel_registerName("setActivationPolicy:"),
ActivationPolicyAccessory);
public static bool IsWindowMiniaturized(Window window)
=> window.TryGetPlatformHandle() is IMacOSTopLevelPlatformHandle { NSWindow: not 0 } handle
&& objc_msgSend_bool(handle.NSWindow, sel_registerName("isMiniaturized"));
[DllImport(LibObjC)]
private static extern nint objc_getClass(string name);
@@ -22,6 +26,10 @@ internal static class MacAppUtils
[DllImport(LibObjC, EntryPoint = "objc_msgSend")]
private static extern nint objc_msgSend(nint receiver, nint selector);
[DllImport(LibObjC, EntryPoint = "objc_msgSend")]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool objc_msgSend_bool(nint receiver, nint selector);
[DllImport(LibObjC, EntryPoint = "objc_msgSend")]
private static extern void objc_msgSend(nint receiver, nint selector, nint argument);
}

View File

@@ -413,7 +413,7 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
public void ShowHideWindow(bool? blShow)
{
var bl = blShow ??
(Utils.IsLinux()
(Utils.IsLinux() || Utils.IsMacOS()
? (!AppManager.Instance.ShowInTaskbar ^ (WindowState == WindowState.Minimized))
: !AppManager.Instance.ShowInTaskbar);
if (bl)

View File

@@ -18,6 +18,8 @@ public partial class MessageBoxDialog : Window
btnYes.Click += BtnYes_Click;
btnNo.Click += BtnNo_Click;
CanMinimize = false;
}
private void BtnYes_Click(object? sender, RoutedEventArgs e)

View File

@@ -7,6 +7,7 @@
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<AssemblyName>v2rayN</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CETCompat>false</CETCompat>
</PropertyGroup>
<ItemGroup>

View File

@@ -10,6 +10,7 @@
<ApplicationHighDpiMode>PerMonitorV2</ApplicationHighDpiMode>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CETCompat>false</CETCompat>
</PropertyGroup>
<ItemGroup>