mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-28 16:14:58 +03:00
Rename LazyConfig to AppHandler
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
namespace ServiceLib.Handler
|
||||
using Splat;
|
||||
|
||||
namespace ServiceLib.Handler
|
||||
{
|
||||
public sealed class LazyConfig
|
||||
public sealed class AppHandler
|
||||
{
|
||||
private static readonly Lazy<LazyConfig> _instance = new(() => new());
|
||||
private static readonly Lazy<AppHandler> _instance = new(() => new());
|
||||
private Config _config;
|
||||
private int? _statePort;
|
||||
private int? _statePort2;
|
||||
|
||||
public static LazyConfig Instance => _instance.Value;
|
||||
private Job? _processJob;
|
||||
public static AppHandler Instance => _instance.Value;
|
||||
public Config Config => _config;
|
||||
|
||||
public int StatePort
|
||||
@@ -28,21 +30,50 @@
|
||||
}
|
||||
}
|
||||
|
||||
private Job? _processJob;
|
||||
#region Init
|
||||
|
||||
public LazyConfig()
|
||||
public AppHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public bool InitApp()
|
||||
{
|
||||
if (ConfigHandler.LoadConfig(ref _config) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Locator.CurrentMutable.RegisterLazySingleton(() => new NoticeHandler(), typeof(NoticeHandler));
|
||||
Thread.CurrentThread.CurrentUICulture = new(_config.uiItem.currentLanguage);
|
||||
|
||||
//Under Win10
|
||||
if (Utils.IsWindows() && Environment.OSVersion.Version.Major < 10)
|
||||
{
|
||||
Environment.SetEnvironmentVariable("DOTNET_EnableWriteXorExecute", "0", EnvironmentVariableTarget.User);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool InitComponents()
|
||||
{
|
||||
Logging.Setup();
|
||||
Logging.LoggingEnabled(true);
|
||||
Logging.SaveLog($"v2rayN start up | {Utils.GetVersion()} | {Utils.GetExePath()}");
|
||||
Logging.SaveLog($"{Environment.OSVersion} - {(Environment.Is64BitOperatingSystem ? 64 : 32)}");
|
||||
Logging.ClearLogs();
|
||||
|
||||
SQLiteHelper.Instance.CreateTable<SubItem>();
|
||||
SQLiteHelper.Instance.CreateTable<ProfileItem>();
|
||||
SQLiteHelper.Instance.CreateTable<ServerStatItem>();
|
||||
SQLiteHelper.Instance.CreateTable<RoutingItem>();
|
||||
SQLiteHelper.Instance.CreateTable<ProfileExItem>();
|
||||
SQLiteHelper.Instance.CreateTable<DNSItem>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#region Config
|
||||
#endregion Init
|
||||
|
||||
public void SetConfig(Config config) => _config = config;
|
||||
#region Config
|
||||
|
||||
public int GetLocalPort(EInboundProtocol protocol)
|
||||
{
|
||||
@@ -76,7 +76,7 @@ namespace ServiceLib.Handler
|
||||
return;
|
||||
}
|
||||
var urlBase = $"{GetApiUrl()}/proxies";
|
||||
urlBase += @"/{0}/delay?timeout=10000&url=" + LazyConfig.Instance.Config.speedTestItem.speedPingTestUrl;
|
||||
urlBase += @"/{0}/delay?timeout=10000&url=" + AppHandler.Instance.Config.speedTestItem.speedPingTestUrl;
|
||||
|
||||
List<Task> tasks = new List<Task>();
|
||||
foreach (var it in lstProxy)
|
||||
@@ -200,7 +200,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
private string GetApiUrl()
|
||||
{
|
||||
return $"{Global.HttpProtocol}{Global.Loopback}:{LazyConfig.Instance.StatePort2}";
|
||||
return $"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort2}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -364,7 +364,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public static int AddServer(Config config, ProfileItem profileItem)
|
||||
{
|
||||
var item = LazyConfig.Instance.GetProfileItem(profileItem.indexId);
|
||||
var item = AppHandler.Instance.GetProfileItem(profileItem.indexId);
|
||||
if (item is null)
|
||||
{
|
||||
item = profileItem;
|
||||
@@ -476,7 +476,7 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
foreach (var it in indexes)
|
||||
{
|
||||
var item = LazyConfig.Instance.GetProfileItem(it.indexId);
|
||||
var item = AppHandler.Instance.GetProfileItem(it.indexId);
|
||||
if (item is null)
|
||||
{
|
||||
continue;
|
||||
@@ -541,7 +541,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public static ProfileItem? GetDefaultServer(Config config)
|
||||
{
|
||||
var item = LazyConfig.Instance.GetProfileItem(config.indexId);
|
||||
var item = AppHandler.Instance.GetProfileItem(config.indexId);
|
||||
if (item is null)
|
||||
{
|
||||
var item2 = SQLiteHelper.Instance.Table<ProfileItem>().FirstOrDefault();
|
||||
@@ -677,7 +677,7 @@ namespace ServiceLib.Handler
|
||||
/// <returns></returns>
|
||||
public static int EditCustomServer(Config config, ProfileItem profileItem)
|
||||
{
|
||||
var item = LazyConfig.Instance.GetProfileItem(profileItem.indexId);
|
||||
var item = AppHandler.Instance.GetProfileItem(profileItem.indexId);
|
||||
if (item is null)
|
||||
{
|
||||
item = profileItem;
|
||||
@@ -717,7 +717,7 @@ namespace ServiceLib.Handler
|
||||
profileItem.id = profileItem.id.TrimEx();
|
||||
profileItem.security = profileItem.security.TrimEx();
|
||||
|
||||
if (!LazyConfig.Instance.GetShadowsocksSecurities(profileItem).Contains(profileItem.security))
|
||||
if (!AppHandler.Instance.GetShadowsocksSecurities(profileItem).Contains(profileItem.security))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -894,7 +894,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public static int SortServers(Config config, string subId, string colName, bool asc)
|
||||
{
|
||||
var lstModel = LazyConfig.Instance.ProfileItems(subId, "");
|
||||
var lstModel = AppHandler.Instance.ProfileItems(subId, "");
|
||||
if (lstModel.Count <= 0)
|
||||
{
|
||||
return -1;
|
||||
@@ -1026,7 +1026,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public static Tuple<int, int> DedupServerList(Config config, string subId)
|
||||
{
|
||||
var lstProfile = LazyConfig.Instance.ProfileItems(subId);
|
||||
var lstProfile = AppHandler.Instance.ProfileItems(subId);
|
||||
|
||||
List<ProfileItem> lstKeep = new();
|
||||
List<ProfileItem> lstRemove = new();
|
||||
@@ -1126,7 +1126,7 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
try
|
||||
{
|
||||
var item = LazyConfig.Instance.GetProfileItem(indexId);
|
||||
var item = AppHandler.Instance.GetProfileItem(indexId);
|
||||
if (item == null)
|
||||
{
|
||||
return 0;
|
||||
@@ -1161,7 +1161,7 @@ namespace ServiceLib.Handler
|
||||
return -1;
|
||||
}
|
||||
|
||||
var profileItem = LazyConfig.Instance.GetProfileItem(indexId) ?? new();
|
||||
var profileItem = AppHandler.Instance.GetProfileItem(indexId) ?? new();
|
||||
profileItem.indexId = indexId;
|
||||
profileItem.remarks = coreType == ECoreType.sing_box ? ResUI.menuSetDefaultMultipleServer : ResUI.menuSetDefaultLoadBalanceServer;
|
||||
profileItem.address = Global.CoreMultipleLoadConfigFileName;
|
||||
@@ -1196,7 +1196,7 @@ namespace ServiceLib.Handler
|
||||
if (isSub && Utils.IsNotEmpty(subid))
|
||||
{
|
||||
RemoveServerViaSubid(config, subid, isSub);
|
||||
subFilter = LazyConfig.Instance.GetSubItem(subid)?.filter ?? "";
|
||||
subFilter = AppHandler.Instance.GetSubItem(subid)?.filter ?? "";
|
||||
}
|
||||
|
||||
int countServers = 0;
|
||||
@@ -1235,7 +1235,7 @@ namespace ServiceLib.Handler
|
||||
//Check for duplicate indexId
|
||||
if (lstDbIndexId is null)
|
||||
{
|
||||
lstDbIndexId = LazyConfig.Instance.ProfileItemIndexes("");
|
||||
lstDbIndexId = AppHandler.Instance.ProfileItemIndexes("");
|
||||
}
|
||||
if (lstAdd.Any(t => t.indexId == existItem.indexId)
|
||||
|| lstDbIndexId.Any(t => t == existItem.indexId))
|
||||
@@ -1295,7 +1295,7 @@ namespace ServiceLib.Handler
|
||||
return -1;
|
||||
}
|
||||
|
||||
var subItem = LazyConfig.Instance.GetSubItem(subid);
|
||||
var subItem = AppHandler.Instance.GetSubItem(subid);
|
||||
var subRemarks = subItem?.remarks;
|
||||
var preSocksPort = subItem?.preSocksPort;
|
||||
|
||||
@@ -1430,7 +1430,7 @@ namespace ServiceLib.Handler
|
||||
List<ProfileItem>? lstOriSub = null;
|
||||
if (isSub && Utils.IsNotEmpty(subid))
|
||||
{
|
||||
lstOriSub = LazyConfig.Instance.ProfileItems(subid);
|
||||
lstOriSub = AppHandler.Instance.ProfileItems(subid);
|
||||
}
|
||||
|
||||
var counter = 0;
|
||||
@@ -1500,7 +1500,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public static int AddSubItem(Config config, SubItem subItem)
|
||||
{
|
||||
var item = LazyConfig.Instance.GetSubItem(subItem.id);
|
||||
var item = AppHandler.Instance.GetSubItem(subItem.id);
|
||||
if (item is null)
|
||||
{
|
||||
item = subItem;
|
||||
@@ -1577,7 +1577,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public static int DeleteSubItem(Config config, string id)
|
||||
{
|
||||
var item = LazyConfig.Instance.GetSubItem(id);
|
||||
var item = AppHandler.Instance.GetSubItem(id);
|
||||
if (item is null)
|
||||
{
|
||||
return 0;
|
||||
@@ -1752,7 +1752,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public static RoutingItem GetDefaultRouting(Config config)
|
||||
{
|
||||
var item = LazyConfig.Instance.GetRoutingItem(config.routingBasicItem.routingIndexId);
|
||||
var item = AppHandler.Instance.GetRoutingItem(config.routingBasicItem.routingIndexId);
|
||||
if (item is null)
|
||||
{
|
||||
var item2 = SQLiteHelper.Instance.Table<RoutingItem>().FirstOrDefault(t => t.locked == false);
|
||||
@@ -1766,7 +1766,7 @@ namespace ServiceLib.Handler
|
||||
public static int InitBuiltinRouting(Config config, bool blImportAdvancedRules = false)
|
||||
{
|
||||
var ver = "V3-";
|
||||
var items = LazyConfig.Instance.RoutingItems();
|
||||
var items = AppHandler.Instance.RoutingItems();
|
||||
if (blImportAdvancedRules || items.Where(t => t.remarks.StartsWith(ver)).ToList().Count <= 0)
|
||||
{
|
||||
var maxSort = items.Count;
|
||||
@@ -1832,7 +1832,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public static int InitBuiltinDNS(Config config)
|
||||
{
|
||||
var items = LazyConfig.Instance.DNSItems();
|
||||
var items = AppHandler.Instance.DNSItems();
|
||||
if (items.Count <= 0)
|
||||
{
|
||||
var item = new DNSItem()
|
||||
|
||||
@@ -78,14 +78,14 @@
|
||||
}
|
||||
|
||||
//port
|
||||
fileContent["port"] = LazyConfig.Instance.GetLocalPort(EInboundProtocol.http);
|
||||
fileContent["port"] = AppHandler.Instance.GetLocalPort(EInboundProtocol.http);
|
||||
//socks-port
|
||||
fileContent["socks-port"] = LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks);
|
||||
fileContent["socks-port"] = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
|
||||
//log-level
|
||||
fileContent["log-level"] = GetLogLevel(_config.coreBasicItem.loglevel);
|
||||
|
||||
//external-controller
|
||||
fileContent["external-controller"] = $"{Global.Loopback}:{LazyConfig.Instance.StatePort2}";
|
||||
fileContent["external-controller"] = $"{Global.Loopback}:{AppHandler.Instance.StatePort2}";
|
||||
//allow-lan
|
||||
if (_config.inbound[0].allowLANConn)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
msg = ResUI.CheckServerSettings;
|
||||
return -1;
|
||||
}
|
||||
var config = LazyConfig.Instance.Config;
|
||||
var config = AppHandler.Instance.Config;
|
||||
|
||||
msg = ResUI.InitialConfiguration;
|
||||
if (node.configType == EConfigType.Custom)
|
||||
@@ -35,7 +35,7 @@
|
||||
return GenerateClientCustomConfig(node, fileName, out msg);
|
||||
}
|
||||
}
|
||||
else if (LazyConfig.Instance.GetCoreType(node, node.configType) == ECoreType.sing_box)
|
||||
else if (AppHandler.Instance.GetCoreType(node, node.configType) == ECoreType.sing_box)
|
||||
{
|
||||
var configGenSingbox = new CoreConfigSingbox(config);
|
||||
if (configGenSingbox.GenerateClientConfigContent(node, out SingboxConfig? singboxConfig, out msg) != 0)
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
singboxConfig.inbounds.Clear(); // Remove "proxy" service for speedtest, avoiding port conflicts.
|
||||
singboxConfig.outbounds.RemoveAt(0);
|
||||
|
||||
int httpPort = LazyConfig.Instance.GetLocalPort(EInboundProtocol.speedtest);
|
||||
int httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
|
||||
|
||||
foreach (var it in selecteds)
|
||||
{
|
||||
@@ -132,7 +132,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var item = LazyConfig.Instance.GetProfileItem(it.indexId);
|
||||
var item = AppHandler.Instance.GetProfileItem(it.indexId);
|
||||
if (it.configType is EConfigType.VMess or EConfigType.VLESS)
|
||||
{
|
||||
if (item is null || Utils.IsNullOrEmpty(item.id) || !Utils.IsGuidByParse(item.id))
|
||||
@@ -282,7 +282,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var item = LazyConfig.Instance.GetProfileItem(it.indexId);
|
||||
var item = AppHandler.Instance.GetProfileItem(it.indexId);
|
||||
if (item is null)
|
||||
{
|
||||
continue;
|
||||
@@ -486,7 +486,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
};
|
||||
singboxConfig.inbounds.Add(inbound);
|
||||
|
||||
inbound.listen_port = LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks);
|
||||
inbound.listen_port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
|
||||
inbound.sniff = _config.inbound[0].sniffingEnabled;
|
||||
inbound.sniff_override_destination = _config.inbound[0].routeOnly ? false : _config.inbound[0].sniffingEnabled;
|
||||
inbound.domain_strategy = Utils.IsNullOrEmpty(_config.routingBasicItem.domainStrategy4Singbox) ? null : _config.routingBasicItem.domainStrategy4Singbox;
|
||||
@@ -600,7 +600,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
}
|
||||
case EConfigType.Shadowsocks:
|
||||
{
|
||||
outbound.method = LazyConfig.Instance.GetShadowsocksSecurities(node).Contains(node.security) ? node.security : Global.None;
|
||||
outbound.method = AppHandler.Instance.GetShadowsocksSecurities(node).Contains(node.security) ? node.security : Global.None;
|
||||
outbound.password = node.id;
|
||||
|
||||
GenOutboundMux(node, outbound);
|
||||
@@ -854,7 +854,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
}
|
||||
try
|
||||
{
|
||||
var subItem = LazyConfig.Instance.GetSubItem(node.subid);
|
||||
var subItem = AppHandler.Instance.GetSubItem(node.subid);
|
||||
if (subItem is null)
|
||||
{
|
||||
return 0;
|
||||
@@ -865,7 +865,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
var txtOutbound = Utils.GetEmbedText(Global.SingboxSampleOutbound);
|
||||
|
||||
//Previous proxy
|
||||
var prevNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.prevProfile);
|
||||
var prevNode = AppHandler.Instance.GetProfileItemViaRemarks(subItem.prevProfile);
|
||||
if (prevNode is not null
|
||||
&& prevNode.configType != EConfigType.Custom)
|
||||
{
|
||||
@@ -878,7 +878,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
}
|
||||
|
||||
//Next proxy
|
||||
var nextNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.nextProfile);
|
||||
var nextNode = AppHandler.Instance.GetProfileItemViaRemarks(subItem.nextProfile);
|
||||
if (nextNode is not null
|
||||
&& nextNode.configType != EConfigType.Custom)
|
||||
{
|
||||
@@ -1173,7 +1173,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
{
|
||||
try
|
||||
{
|
||||
var item = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box);
|
||||
var item = AppHandler.Instance.GetDNSItem(ECoreType.sing_box);
|
||||
var strDNS = string.Empty;
|
||||
if (_config.tunModeItem.enableTun)
|
||||
{
|
||||
@@ -1260,7 +1260,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
singboxConfig.experimental ??= new Experimental4Sbox();
|
||||
singboxConfig.experimental.clash_api = new Clash_Api4Sbox()
|
||||
{
|
||||
external_controller = $"{Global.Loopback}:{LazyConfig.Instance.StatePort2}",
|
||||
external_controller = $"{Global.Loopback}:{AppHandler.Instance.StatePort2}",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var item = LazyConfig.Instance.GetProfileItem(it.indexId);
|
||||
var item = AppHandler.Instance.GetProfileItem(it.indexId);
|
||||
if (item is null)
|
||||
{
|
||||
continue;
|
||||
@@ -236,7 +236,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
v2rayConfig.inbounds.Clear(); // Remove "proxy" service for speedtest, avoiding port conflicts.
|
||||
v2rayConfig.outbounds.RemoveAt(0);
|
||||
|
||||
int httpPort = LazyConfig.Instance.GetLocalPort(EInboundProtocol.speedtest);
|
||||
int httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
|
||||
|
||||
foreach (var it in selecteds)
|
||||
{
|
||||
@@ -248,7 +248,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var item = LazyConfig.Instance.GetProfileItem(it.indexId);
|
||||
var item = AppHandler.Instance.GetProfileItem(it.indexId);
|
||||
if (it.configType is EConfigType.VMess or EConfigType.VLESS)
|
||||
{
|
||||
if (item is null || Utils.IsNullOrEmpty(item.id) || !Utils.IsGuidByParse(item.id))
|
||||
@@ -637,7 +637,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
serversItem.address = node.address;
|
||||
serversItem.port = node.port;
|
||||
serversItem.password = node.id;
|
||||
serversItem.method = LazyConfig.Instance.GetShadowsocksSecurities(node).Contains(node.security) ? node.security : "none";
|
||||
serversItem.method = AppHandler.Instance.GetShadowsocksSecurities(node).Contains(node.security) ? node.security : "none";
|
||||
|
||||
serversItem.ota = false;
|
||||
serversItem.level = 1;
|
||||
@@ -1029,7 +1029,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
{
|
||||
try
|
||||
{
|
||||
var item = LazyConfig.Instance.GetDNSItem(ECoreType.Xray);
|
||||
var item = AppHandler.Instance.GetDNSItem(ECoreType.Xray);
|
||||
var normalDNS = item?.normalDNS;
|
||||
var domainStrategy4Freedom = item?.domainStrategy4Freedom;
|
||||
if (Utils.IsNullOrEmpty(normalDNS))
|
||||
@@ -1136,7 +1136,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
Inboundsettings4Ray apiInboundSettings = new();
|
||||
apiInbound.tag = tag;
|
||||
apiInbound.listen = Global.Loopback;
|
||||
apiInbound.port = LazyConfig.Instance.StatePort;
|
||||
apiInbound.port = AppHandler.Instance.StatePort;
|
||||
apiInbound.protocol = Global.InboundAPIProtocol;
|
||||
apiInboundSettings.address = Global.Loopback;
|
||||
apiInbound.settings = apiInboundSettings;
|
||||
@@ -1193,7 +1193,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
}
|
||||
try
|
||||
{
|
||||
var subItem = LazyConfig.Instance.GetSubItem(node.subid);
|
||||
var subItem = AppHandler.Instance.GetSubItem(node.subid);
|
||||
if (subItem is null)
|
||||
{
|
||||
return 0;
|
||||
@@ -1204,7 +1204,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
var txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound);
|
||||
|
||||
//Previous proxy
|
||||
var prevNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.prevProfile);
|
||||
var prevNode = AppHandler.Instance.GetProfileItemViaRemarks(subItem.prevProfile);
|
||||
if (prevNode is not null
|
||||
&& prevNode.configType != EConfigType.Custom
|
||||
&& prevNode.configType != EConfigType.Hysteria2
|
||||
@@ -1223,7 +1223,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||
}
|
||||
|
||||
//Next proxy
|
||||
var nextNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.nextProfile);
|
||||
var nextNode = AppHandler.Instance.GetProfileItemViaRemarks(subItem.nextProfile);
|
||||
if (nextNode is not null
|
||||
&& nextNode.configType != EConfigType.Custom
|
||||
&& nextNode.configType != EConfigType.Hysteria2
|
||||
|
||||
@@ -182,7 +182,7 @@ namespace ServiceLib.Handler
|
||||
//{
|
||||
// coreType = LazyConfig.Instance.GetCoreType(node, node.configType);
|
||||
//}
|
||||
var coreType = LazyConfig.Instance.GetCoreType(node, node.configType);
|
||||
var coreType = AppHandler.Instance.GetCoreType(node, node.configType);
|
||||
_config.runningCoreType = coreType;
|
||||
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(coreType);
|
||||
|
||||
@@ -207,7 +207,7 @@ namespace ServiceLib.Handler
|
||||
configType = EConfigType.SOCKS,
|
||||
address = Global.Loopback,
|
||||
sni = node.address, //Tun2SocksAddress
|
||||
port = LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks)
|
||||
port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks)
|
||||
};
|
||||
}
|
||||
else if ((node.configType == EConfigType.Custom && node.preSocksPort > 0))
|
||||
@@ -339,7 +339,7 @@ namespace ServiceLib.Handler
|
||||
startUpSuccessful = true;
|
||||
}
|
||||
|
||||
LazyConfig.Instance.AddProcess(proc.Handle);
|
||||
AppHandler.Instance.AddProcess(proc.Handle);
|
||||
return proc;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
try
|
||||
{
|
||||
Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13);
|
||||
Utils.SetSecurityProtocol(AppHandler.Instance.Config.guiItem.enableSecurityProtocolTls13);
|
||||
|
||||
var progress = new Progress<string>();
|
||||
progress.ProgressChanged += (sender, value) =>
|
||||
@@ -62,7 +62,7 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
try
|
||||
{
|
||||
Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13);
|
||||
Utils.SetSecurityProtocol(AppHandler.Instance.Config.guiItem.enableSecurityProtocolTls13);
|
||||
UpdateCompleted?.Invoke(this, new ResultEventArgs(false, $"{ResUI.Downloading} {url}"));
|
||||
|
||||
var progress = new Progress<double>();
|
||||
@@ -92,7 +92,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public async Task<string?> UrlRedirectAsync(string url, bool blProxy)
|
||||
{
|
||||
Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13);
|
||||
Utils.SetSecurityProtocol(AppHandler.Instance.Config.guiItem.enableSecurityProtocolTls13);
|
||||
var webRequestHandler = new SocketsHttpHandler
|
||||
{
|
||||
AllowAutoRedirect = false,
|
||||
@@ -181,7 +181,7 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
try
|
||||
{
|
||||
Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13);
|
||||
Utils.SetSecurityProtocol(AppHandler.Instance.Config.guiItem.enableSecurityProtocolTls13);
|
||||
var webProxy = GetWebProxy(blProxy);
|
||||
var client = new HttpClient(new SocketsHttpHandler()
|
||||
{
|
||||
@@ -226,7 +226,7 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
try
|
||||
{
|
||||
Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13);
|
||||
Utils.SetSecurityProtocol(AppHandler.Instance.Config.guiItem.enableSecurityProtocolTls13);
|
||||
|
||||
var webProxy = GetWebProxy(blProxy);
|
||||
|
||||
@@ -260,7 +260,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
try
|
||||
{
|
||||
var config = LazyConfig.Instance.Config;
|
||||
var config = AppHandler.Instance.Config;
|
||||
int responseTime = await GetRealPingTime(config.speedTestItem.speedPingTestUrl, webProxy, 10);
|
||||
return responseTime;
|
||||
}
|
||||
@@ -314,7 +314,7 @@ namespace ServiceLib.Handler
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var httpPort = LazyConfig.Instance.GetLocalPort(EInboundProtocol.http);
|
||||
var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.http);
|
||||
if (!SocketCheck(Global.Loopback, httpPort))
|
||||
{
|
||||
return null;
|
||||
|
||||
@@ -236,7 +236,7 @@ namespace ServiceLib.Handler
|
||||
ProfileExHandler.Instance.SetTestSpeed(it.indexId, "-1");
|
||||
UpdateFunc(it.indexId, "", ResUI.Speedtesting);
|
||||
|
||||
var item = LazyConfig.Instance.GetProfileItem(it.indexId);
|
||||
var item = AppHandler.Instance.GetProfileItem(it.indexId);
|
||||
if (item is null) continue;
|
||||
|
||||
WebProxy webProxy = new(Global.Loopback, it.port);
|
||||
@@ -299,7 +299,7 @@ namespace ServiceLib.Handler
|
||||
ProfileExHandler.Instance.SetTestSpeed(it.indexId, "-1");
|
||||
UpdateFunc(it.indexId, "", ResUI.Speedtesting);
|
||||
|
||||
var item = LazyConfig.Instance.GetProfileItem(it.indexId);
|
||||
var item = AppHandler.Instance.GetProfileItem(it.indexId);
|
||||
if (item is null) continue;
|
||||
|
||||
WebProxy webProxy = new(Global.Loopback, it.port);
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace ServiceLib.Handler.Statistics
|
||||
|
||||
try
|
||||
{
|
||||
url = $"ws://{Global.Loopback}:{LazyConfig.Instance.StatePort2}/traffic";
|
||||
url = $"ws://{Global.Loopback}:{AppHandler.Instance.StatePort2}/traffic";
|
||||
|
||||
if (webSocket == null)
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace ServiceLib.Handler.Statistics
|
||||
{
|
||||
try
|
||||
{
|
||||
_channel = GrpcChannel.ForAddress($"{Global.HttpProtocol}{Global.Loopback}:{LazyConfig.Instance.StatePort}");
|
||||
_channel = GrpcChannel.ForAddress($"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort}");
|
||||
_client = new StatsService.StatsServiceClient(_channel);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
while (true)
|
||||
{
|
||||
var updateTime = ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
|
||||
var lstSubs = LazyConfig.Instance.SubItems()
|
||||
var lstSubs = AppHandler.Instance.SubItems()
|
||||
.Where(t => t.autoUpdateInterval > 0)
|
||||
.Where(t => updateTime - t.updateTime >= t.autoUpdateInterval * 60)
|
||||
.ToList();
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace ServiceLib.Handler
|
||||
_updateFunc = update;
|
||||
|
||||
_updateFunc(false, ResUI.MsgUpdateSubscriptionStart);
|
||||
var subItem = LazyConfig.Instance.SubItems().OrderBy(t => t.sort).ToList();
|
||||
var subItem = AppHandler.Instance.SubItems().OrderBy(t => t.sort).ToList();
|
||||
|
||||
if (subItem == null || subItem.Count <= 0)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
public WebDavHandler()
|
||||
{
|
||||
_config = LazyConfig.Instance.Config;
|
||||
_config = AppHandler.Instance.Config;
|
||||
}
|
||||
|
||||
private async Task<bool> GetClient()
|
||||
|
||||
Reference in New Issue
Block a user