Move ShowInTaskbar and RunningCoreType to AppManager
Some checks are pending
release Linux / build (Release) (push) Waiting to run
release Linux / rpm (push) Blocked by required conditions
release macOS / build (Release) (push) Waiting to run
release Windows desktop (Avalonia UI) / build (Release) (push) Waiting to run
release Windows / build (Release) (push) Waiting to run

This commit is contained in:
2dust 2025-12-24 16:01:28 +08:00
parent 5478c90180
commit 027252e687
15 changed files with 35 additions and 34 deletions

View file

@ -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,

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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<ColumnItem> MainColumnItem { get; set; }
public List<WindowSizeItem> WindowSizeItem { get; set; }

View file

@ -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()
{

View file

@ -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;
}

View file

@ -30,7 +30,7 @@ public class StatisticsXrayService
await Task.Delay(1000);
try
{
if (_config.RunningCoreType != ECoreType.Xray)
if (AppManager.Instance.RunningCoreType != ECoreType.Xray)
{
continue;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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();

View file

@ -44,7 +44,7 @@ public class MsgViewModel : MyReactiveObject
EnqueueQueueMsg(msg);
if (!_config.UiItem.ShowInTaskbar)
if (!AppManager.Instance.ShowInTaskbar)
{
return;
}

View file

@ -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;

View file

@ -409,8 +409,8 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
{
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<MainWindowViewModel>
Hide();
}
_config.UiItem.ShowInTaskbar = bl;
AppManager.Instance.ShowInTaskbar = bl;
}
protected override void OnLoaded(object? sender, RoutedEventArgs e)

View file

@ -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)