diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index f0243076..41f990b7 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -1273,7 +1273,7 @@ public static class ConfigHandler } else if (node.ConfigType == EConfigType.Custom && node.PreSocksPort > 0) { - var preCoreType = config.RunningCoreType = config.TunModeItem.EnableTun ? ECoreType.sing_box : ECoreType.Xray; + var preCoreType = AppManager.Instance.RunningCoreType = config.TunModeItem.EnableTun ? ECoreType.sing_box : ECoreType.Xray; itemSocks = new ProfileItem() { CoreType = preCoreType, diff --git a/v2rayN/ServiceLib/Manager/AppManager.cs b/v2rayN/ServiceLib/Manager/AppManager.cs index c66f76df..6c20022a 100644 --- a/v2rayN/ServiceLib/Manager/AppManager.cs +++ b/v2rayN/ServiceLib/Manager/AppManager.cs @@ -31,6 +31,23 @@ public sealed class AppManager public string LinuxSudoPwd { get; set; } + public bool ShowInTaskbar { get; set; } + + public ECoreType RunningCoreType { get; set; } + + public bool IsRunningCore(ECoreType type) + { + switch (type) + { + case ECoreType.Xray when RunningCoreType is ECoreType.Xray or ECoreType.v2fly or ECoreType.v2fly_v5: + case ECoreType.sing_box when RunningCoreType is ECoreType.sing_box or ECoreType.mihomo: + return true; + + default: + return false; + } + } + #endregion Property #region App diff --git a/v2rayN/ServiceLib/Manager/CoreManager.cs b/v2rayN/ServiceLib/Manager/CoreManager.cs index 8dbff9e2..79dbdeb0 100644 --- a/v2rayN/ServiceLib/Manager/CoreManager.cs +++ b/v2rayN/ServiceLib/Manager/CoreManager.cs @@ -167,7 +167,7 @@ public class CoreManager private async Task CoreStart(ProfileItem node) { - var coreType = _config.RunningCoreType = AppManager.Instance.GetCoreType(node, node.ConfigType); + var coreType = AppManager.Instance.RunningCoreType = AppManager.Instance.GetCoreType(node, node.ConfigType); var coreInfo = CoreInfoManager.Instance.GetCoreInfo(coreType); var displayLog = node.ConfigType != EConfigType.Custom || node.DisplayLog; diff --git a/v2rayN/ServiceLib/Models/Config.cs b/v2rayN/ServiceLib/Models/Config.cs index 91b49b29..738ee286 100644 --- a/v2rayN/ServiceLib/Models/Config.cs +++ b/v2rayN/ServiceLib/Models/Config.cs @@ -8,21 +8,6 @@ public class Config public string IndexId { get; set; } public string SubIndexId { get; set; } - public ECoreType RunningCoreType { get; set; } - - public bool IsRunningCore(ECoreType type) - { - switch (type) - { - case ECoreType.Xray when RunningCoreType is ECoreType.Xray or ECoreType.v2fly or ECoreType.v2fly_v5: - case ECoreType.sing_box when RunningCoreType is ECoreType.sing_box or ECoreType.mihomo: - return true; - - default: - return false; - } - } - #endregion property #region other entities diff --git a/v2rayN/ServiceLib/Models/ConfigItems.cs b/v2rayN/ServiceLib/Models/ConfigItems.cs index 22b917a6..eeb88deb 100644 --- a/v2rayN/ServiceLib/Models/ConfigItems.cs +++ b/v2rayN/ServiceLib/Models/ConfigItems.cs @@ -99,8 +99,7 @@ public class UIItem public bool EnableDragDropSort { get; set; } public bool DoubleClick2Activate { get; set; } public bool AutoHideStartup { get; set; } - public bool Hide2TrayWhenClose { get; set; } - public bool ShowInTaskbar { get; set; } + public bool Hide2TrayWhenClose { get; set; } public bool MacOSShowInDock { get; set; } public List MainColumnItem { get; set; } public List WindowSizeItem { get; set; } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs index 76e90110..4e14c688 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs @@ -10,7 +10,7 @@ public partial class CoreConfigSingboxService singboxConfig.inbounds = []; if (!_config.TunModeItem.EnableTun - || (_config.TunModeItem.EnableTun && _config.TunModeItem.EnableExInbound && _config.RunningCoreType == ECoreType.sing_box)) + || (_config.TunModeItem.EnableTun && _config.TunModeItem.EnableExInbound && AppManager.Instance.RunningCoreType == ECoreType.sing_box)) { var inbound = new Inbound4Sbox() { diff --git a/v2rayN/ServiceLib/Services/Statistics/StatisticsSingboxService.cs b/v2rayN/ServiceLib/Services/Statistics/StatisticsSingboxService.cs index 2b0f53f1..7d663322 100644 --- a/v2rayN/ServiceLib/Services/Statistics/StatisticsSingboxService.cs +++ b/v2rayN/ServiceLib/Services/Statistics/StatisticsSingboxService.cs @@ -61,7 +61,7 @@ public class StatisticsSingboxService await Task.Delay(1000); try { - if (!_config.IsRunningCore(ECoreType.sing_box)) + if (!AppManager.Instance.IsRunningCore(ECoreType.sing_box)) { continue; } diff --git a/v2rayN/ServiceLib/Services/Statistics/StatisticsXrayService.cs b/v2rayN/ServiceLib/Services/Statistics/StatisticsXrayService.cs index b64a515d..a64fed00 100644 --- a/v2rayN/ServiceLib/Services/Statistics/StatisticsXrayService.cs +++ b/v2rayN/ServiceLib/Services/Statistics/StatisticsXrayService.cs @@ -30,7 +30,7 @@ public class StatisticsXrayService await Task.Delay(1000); try { - if (_config.RunningCoreType != ECoreType.Xray) + if (AppManager.Instance.RunningCoreType != ECoreType.Xray) { continue; } diff --git a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs index dba8190f..48500f3e 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs @@ -128,7 +128,7 @@ public class ClashConnectionsViewModel : MyReactiveObject { await Task.Delay(1000 * 5); numOfExecuted++; - if (!(AutoRefresh && _config.UiItem.ShowInTaskbar && _config.IsRunningCore(ECoreType.sing_box))) + if (!(AutoRefresh && AppManager.Instance.ShowInTaskbar && AppManager.Instance.IsRunningCore(ECoreType.sing_box))) { continue; } diff --git a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs index d49193ad..6628e11d 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs @@ -437,7 +437,7 @@ public class ClashProxiesViewModel : MyReactiveObject { await Task.Delay(1000 * 60); numOfExecuted++; - if (!(AutoRefresh && _config.UiItem.ShowInTaskbar && _config.IsRunningCore(ECoreType.sing_box))) + if (!(AutoRefresh && AppManager.Instance.ShowInTaskbar && AppManager.Instance.IsRunningCore(ECoreType.sing_box))) { continue; } diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index c3bb0fe3..a09ad4de 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -253,7 +253,7 @@ public class MainWindowViewModel : MyReactiveObject private async Task Init() { - _config.UiItem.ShowInTaskbar = true; + AppManager.Instance.ShowInTaskbar = true; //await ConfigHandler.InitBuiltinRouting(_config); await ConfigHandler.InitBuiltinDNS(_config); @@ -306,7 +306,7 @@ public class MainWindowViewModel : MyReactiveObject private async Task UpdateStatisticsHandler(ServerSpeedItem update) { - if (!_config.UiItem.ShowInTaskbar) + if (!AppManager.Instance.ShowInTaskbar) { return; } @@ -560,7 +560,7 @@ public class MainWindowViewModel : MyReactiveObject }); AppEvents.TestServerRequested.Publish(); - var showClashUI = _config.IsRunningCore(ECoreType.sing_box); + var showClashUI = AppManager.Instance.IsRunningCore(ECoreType.sing_box); if (showClashUI) { AppEvents.ProxiesReloadRequested.Publish(); diff --git a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs index 08a77d33..68bf71b5 100644 --- a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs @@ -44,7 +44,7 @@ public class MsgViewModel : MyReactiveObject EnqueueQueueMsg(msg); - if (!_config.UiItem.ShowInTaskbar) + if (!AppManager.Instance.ShowInTaskbar) { return; } diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index 7617ac6f..b8cd142e 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -549,7 +549,7 @@ public class StatusBarViewModel : MyReactiveObject try { - if (_config.IsRunningCore(ECoreType.sing_box)) + if (AppManager.Instance.IsRunningCore(ECoreType.sing_box)) { SpeedProxyDisplay = string.Format(ResUI.SpeedDisplayText, EInboundProtocol.mixed, Utils.HumanFy(update.ProxyUp), Utils.HumanFy(update.ProxyDown)); SpeedDirectDisplay = string.Empty; diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index 08f66dcd..5c5ba9cb 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -409,8 +409,8 @@ public partial class MainWindow : WindowBase { var bl = blShow ?? (Utils.IsLinux() - ? (!_config.UiItem.ShowInTaskbar ^ (WindowState == WindowState.Minimized)) - : !_config.UiItem.ShowInTaskbar); + ? (!AppManager.Instance.ShowInTaskbar ^ (WindowState == WindowState.Minimized)) + : !AppManager.Instance.ShowInTaskbar); if (bl) { Show(); @@ -436,7 +436,7 @@ public partial class MainWindow : WindowBase Hide(); } - _config.UiItem.ShowInTaskbar = bl; + AppManager.Instance.ShowInTaskbar = bl; } protected override void OnLoaded(object? sender, RoutedEventArgs e) diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index a52f26b1..93e62aad 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -376,7 +376,7 @@ public partial class MainWindow public void ShowHideWindow(bool? blShow) { - var bl = blShow ?? !_config.UiItem.ShowInTaskbar; + var bl = blShow ?? !AppManager.Instance.ShowInTaskbar; if (bl) { this?.Show(); @@ -391,7 +391,7 @@ public partial class MainWindow { this?.Hide(); } - _config.UiItem.ShowInTaskbar = bl; + AppManager.Instance.ShowInTaskbar = bl; } protected override void OnLoaded(object? sender, RoutedEventArgs e)