Rename LazyConfig to AppHandler

This commit is contained in:
2dust 2024-10-07 09:51:41 +08:00
parent f40eb724d7
commit 3bdef4d6d8
59 changed files with 186 additions and 198 deletions

View file

@ -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 Config _config;
private int? _statePort; private int? _statePort;
private int? _statePort2; private int? _statePort2;
private Job? _processJob;
public static LazyConfig Instance => _instance.Value; public static AppHandler Instance => _instance.Value;
public Config Config => _config; public Config Config => _config;
public int StatePort 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<SubItem>();
SQLiteHelper.Instance.CreateTable<ProfileItem>(); SQLiteHelper.Instance.CreateTable<ProfileItem>();
SQLiteHelper.Instance.CreateTable<ServerStatItem>(); SQLiteHelper.Instance.CreateTable<ServerStatItem>();
SQLiteHelper.Instance.CreateTable<RoutingItem>(); SQLiteHelper.Instance.CreateTable<RoutingItem>();
SQLiteHelper.Instance.CreateTable<ProfileExItem>(); SQLiteHelper.Instance.CreateTable<ProfileExItem>();
SQLiteHelper.Instance.CreateTable<DNSItem>(); SQLiteHelper.Instance.CreateTable<DNSItem>();
return true;
} }
#region Config #endregion Init
public void SetConfig(Config config) => _config = config; #region Config
public int GetLocalPort(EInboundProtocol protocol) public int GetLocalPort(EInboundProtocol protocol)
{ {

View file

@ -76,7 +76,7 @@ namespace ServiceLib.Handler
return; return;
} }
var urlBase = $"{GetApiUrl()}/proxies"; 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>(); List<Task> tasks = new List<Task>();
foreach (var it in lstProxy) foreach (var it in lstProxy)
@ -200,7 +200,7 @@ namespace ServiceLib.Handler
private string GetApiUrl() private string GetApiUrl()
{ {
return $"{Global.HttpProtocol}{Global.Loopback}:{LazyConfig.Instance.StatePort2}"; return $"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort2}";
} }
} }
} }

View file

@ -364,7 +364,7 @@ namespace ServiceLib.Handler
public static int AddServer(Config config, ProfileItem profileItem) 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) if (item is null)
{ {
item = profileItem; item = profileItem;
@ -476,7 +476,7 @@ namespace ServiceLib.Handler
{ {
foreach (var it in indexes) foreach (var it in indexes)
{ {
var item = LazyConfig.Instance.GetProfileItem(it.indexId); var item = AppHandler.Instance.GetProfileItem(it.indexId);
if (item is null) if (item is null)
{ {
continue; continue;
@ -541,7 +541,7 @@ namespace ServiceLib.Handler
public static ProfileItem? GetDefaultServer(Config config) public static ProfileItem? GetDefaultServer(Config config)
{ {
var item = LazyConfig.Instance.GetProfileItem(config.indexId); var item = AppHandler.Instance.GetProfileItem(config.indexId);
if (item is null) if (item is null)
{ {
var item2 = SQLiteHelper.Instance.Table<ProfileItem>().FirstOrDefault(); var item2 = SQLiteHelper.Instance.Table<ProfileItem>().FirstOrDefault();
@ -677,7 +677,7 @@ namespace ServiceLib.Handler
/// <returns></returns> /// <returns></returns>
public static int EditCustomServer(Config config, ProfileItem profileItem) 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) if (item is null)
{ {
item = profileItem; item = profileItem;
@ -717,7 +717,7 @@ namespace ServiceLib.Handler
profileItem.id = profileItem.id.TrimEx(); profileItem.id = profileItem.id.TrimEx();
profileItem.security = profileItem.security.TrimEx(); profileItem.security = profileItem.security.TrimEx();
if (!LazyConfig.Instance.GetShadowsocksSecurities(profileItem).Contains(profileItem.security)) if (!AppHandler.Instance.GetShadowsocksSecurities(profileItem).Contains(profileItem.security))
{ {
return -1; return -1;
} }
@ -894,7 +894,7 @@ namespace ServiceLib.Handler
public static int SortServers(Config config, string subId, string colName, bool asc) 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) if (lstModel.Count <= 0)
{ {
return -1; return -1;
@ -1026,7 +1026,7 @@ namespace ServiceLib.Handler
public static Tuple<int, int> DedupServerList(Config config, string subId) 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> lstKeep = new();
List<ProfileItem> lstRemove = new(); List<ProfileItem> lstRemove = new();
@ -1126,7 +1126,7 @@ namespace ServiceLib.Handler
{ {
try try
{ {
var item = LazyConfig.Instance.GetProfileItem(indexId); var item = AppHandler.Instance.GetProfileItem(indexId);
if (item == null) if (item == null)
{ {
return 0; return 0;
@ -1161,7 +1161,7 @@ namespace ServiceLib.Handler
return -1; return -1;
} }
var profileItem = LazyConfig.Instance.GetProfileItem(indexId) ?? new(); var profileItem = AppHandler.Instance.GetProfileItem(indexId) ?? new();
profileItem.indexId = indexId; profileItem.indexId = indexId;
profileItem.remarks = coreType == ECoreType.sing_box ? ResUI.menuSetDefaultMultipleServer : ResUI.menuSetDefaultLoadBalanceServer; profileItem.remarks = coreType == ECoreType.sing_box ? ResUI.menuSetDefaultMultipleServer : ResUI.menuSetDefaultLoadBalanceServer;
profileItem.address = Global.CoreMultipleLoadConfigFileName; profileItem.address = Global.CoreMultipleLoadConfigFileName;
@ -1196,7 +1196,7 @@ namespace ServiceLib.Handler
if (isSub && Utils.IsNotEmpty(subid)) if (isSub && Utils.IsNotEmpty(subid))
{ {
RemoveServerViaSubid(config, subid, isSub); RemoveServerViaSubid(config, subid, isSub);
subFilter = LazyConfig.Instance.GetSubItem(subid)?.filter ?? ""; subFilter = AppHandler.Instance.GetSubItem(subid)?.filter ?? "";
} }
int countServers = 0; int countServers = 0;
@ -1235,7 +1235,7 @@ namespace ServiceLib.Handler
//Check for duplicate indexId //Check for duplicate indexId
if (lstDbIndexId is null) if (lstDbIndexId is null)
{ {
lstDbIndexId = LazyConfig.Instance.ProfileItemIndexes(""); lstDbIndexId = AppHandler.Instance.ProfileItemIndexes("");
} }
if (lstAdd.Any(t => t.indexId == existItem.indexId) if (lstAdd.Any(t => t.indexId == existItem.indexId)
|| lstDbIndexId.Any(t => t == existItem.indexId)) || lstDbIndexId.Any(t => t == existItem.indexId))
@ -1295,7 +1295,7 @@ namespace ServiceLib.Handler
return -1; return -1;
} }
var subItem = LazyConfig.Instance.GetSubItem(subid); var subItem = AppHandler.Instance.GetSubItem(subid);
var subRemarks = subItem?.remarks; var subRemarks = subItem?.remarks;
var preSocksPort = subItem?.preSocksPort; var preSocksPort = subItem?.preSocksPort;
@ -1430,7 +1430,7 @@ namespace ServiceLib.Handler
List<ProfileItem>? lstOriSub = null; List<ProfileItem>? lstOriSub = null;
if (isSub && Utils.IsNotEmpty(subid)) if (isSub && Utils.IsNotEmpty(subid))
{ {
lstOriSub = LazyConfig.Instance.ProfileItems(subid); lstOriSub = AppHandler.Instance.ProfileItems(subid);
} }
var counter = 0; var counter = 0;
@ -1500,7 +1500,7 @@ namespace ServiceLib.Handler
public static int AddSubItem(Config config, SubItem subItem) 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) if (item is null)
{ {
item = subItem; item = subItem;
@ -1577,7 +1577,7 @@ namespace ServiceLib.Handler
public static int DeleteSubItem(Config config, string id) public static int DeleteSubItem(Config config, string id)
{ {
var item = LazyConfig.Instance.GetSubItem(id); var item = AppHandler.Instance.GetSubItem(id);
if (item is null) if (item is null)
{ {
return 0; return 0;
@ -1752,7 +1752,7 @@ namespace ServiceLib.Handler
public static RoutingItem GetDefaultRouting(Config config) 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) if (item is null)
{ {
var item2 = SQLiteHelper.Instance.Table<RoutingItem>().FirstOrDefault(t => t.locked == false); 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) public static int InitBuiltinRouting(Config config, bool blImportAdvancedRules = false)
{ {
var ver = "V3-"; 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) if (blImportAdvancedRules || items.Where(t => t.remarks.StartsWith(ver)).ToList().Count <= 0)
{ {
var maxSort = items.Count; var maxSort = items.Count;
@ -1832,7 +1832,7 @@ namespace ServiceLib.Handler
public static int InitBuiltinDNS(Config config) public static int InitBuiltinDNS(Config config)
{ {
var items = LazyConfig.Instance.DNSItems(); var items = AppHandler.Instance.DNSItems();
if (items.Count <= 0) if (items.Count <= 0)
{ {
var item = new DNSItem() var item = new DNSItem()

View file

@ -78,14 +78,14 @@
} }
//port //port
fileContent["port"] = LazyConfig.Instance.GetLocalPort(EInboundProtocol.http); fileContent["port"] = AppHandler.Instance.GetLocalPort(EInboundProtocol.http);
//socks-port //socks-port
fileContent["socks-port"] = LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks); fileContent["socks-port"] = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
//log-level //log-level
fileContent["log-level"] = GetLogLevel(_config.coreBasicItem.loglevel); fileContent["log-level"] = GetLogLevel(_config.coreBasicItem.loglevel);
//external-controller //external-controller
fileContent["external-controller"] = $"{Global.Loopback}:{LazyConfig.Instance.StatePort2}"; fileContent["external-controller"] = $"{Global.Loopback}:{AppHandler.Instance.StatePort2}";
//allow-lan //allow-lan
if (_config.inbound[0].allowLANConn) if (_config.inbound[0].allowLANConn)
{ {

View file

@ -15,7 +15,7 @@
msg = ResUI.CheckServerSettings; msg = ResUI.CheckServerSettings;
return -1; return -1;
} }
var config = LazyConfig.Instance.Config; var config = AppHandler.Instance.Config;
msg = ResUI.InitialConfiguration; msg = ResUI.InitialConfiguration;
if (node.configType == EConfigType.Custom) if (node.configType == EConfigType.Custom)
@ -35,7 +35,7 @@
return GenerateClientCustomConfig(node, fileName, out msg); 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); var configGenSingbox = new CoreConfigSingbox(config);
if (configGenSingbox.GenerateClientConfigContent(node, out SingboxConfig? singboxConfig, out msg) != 0) if (configGenSingbox.GenerateClientConfigContent(node, out SingboxConfig? singboxConfig, out msg) != 0)

View file

@ -120,7 +120,7 @@ namespace ServiceLib.Handler.CoreConfig
singboxConfig.inbounds.Clear(); // Remove "proxy" service for speedtest, avoiding port conflicts. singboxConfig.inbounds.Clear(); // Remove "proxy" service for speedtest, avoiding port conflicts.
singboxConfig.outbounds.RemoveAt(0); singboxConfig.outbounds.RemoveAt(0);
int httpPort = LazyConfig.Instance.GetLocalPort(EInboundProtocol.speedtest); int httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
foreach (var it in selecteds) foreach (var it in selecteds)
{ {
@ -132,7 +132,7 @@ namespace ServiceLib.Handler.CoreConfig
{ {
continue; 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 (it.configType is EConfigType.VMess or EConfigType.VLESS)
{ {
if (item is null || Utils.IsNullOrEmpty(item.id) || !Utils.IsGuidByParse(item.id)) if (item is null || Utils.IsNullOrEmpty(item.id) || !Utils.IsGuidByParse(item.id))
@ -282,7 +282,7 @@ namespace ServiceLib.Handler.CoreConfig
{ {
continue; continue;
} }
var item = LazyConfig.Instance.GetProfileItem(it.indexId); var item = AppHandler.Instance.GetProfileItem(it.indexId);
if (item is null) if (item is null)
{ {
continue; continue;
@ -486,7 +486,7 @@ namespace ServiceLib.Handler.CoreConfig
}; };
singboxConfig.inbounds.Add(inbound); 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 = _config.inbound[0].sniffingEnabled;
inbound.sniff_override_destination = _config.inbound[0].routeOnly ? false : _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; inbound.domain_strategy = Utils.IsNullOrEmpty(_config.routingBasicItem.domainStrategy4Singbox) ? null : _config.routingBasicItem.domainStrategy4Singbox;
@ -600,7 +600,7 @@ namespace ServiceLib.Handler.CoreConfig
} }
case EConfigType.Shadowsocks: 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; outbound.password = node.id;
GenOutboundMux(node, outbound); GenOutboundMux(node, outbound);
@ -854,7 +854,7 @@ namespace ServiceLib.Handler.CoreConfig
} }
try try
{ {
var subItem = LazyConfig.Instance.GetSubItem(node.subid); var subItem = AppHandler.Instance.GetSubItem(node.subid);
if (subItem is null) if (subItem is null)
{ {
return 0; return 0;
@ -865,7 +865,7 @@ namespace ServiceLib.Handler.CoreConfig
var txtOutbound = Utils.GetEmbedText(Global.SingboxSampleOutbound); var txtOutbound = Utils.GetEmbedText(Global.SingboxSampleOutbound);
//Previous proxy //Previous proxy
var prevNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.prevProfile); var prevNode = AppHandler.Instance.GetProfileItemViaRemarks(subItem.prevProfile);
if (prevNode is not null if (prevNode is not null
&& prevNode.configType != EConfigType.Custom) && prevNode.configType != EConfigType.Custom)
{ {
@ -878,7 +878,7 @@ namespace ServiceLib.Handler.CoreConfig
} }
//Next proxy //Next proxy
var nextNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.nextProfile); var nextNode = AppHandler.Instance.GetProfileItemViaRemarks(subItem.nextProfile);
if (nextNode is not null if (nextNode is not null
&& nextNode.configType != EConfigType.Custom) && nextNode.configType != EConfigType.Custom)
{ {
@ -1173,7 +1173,7 @@ namespace ServiceLib.Handler.CoreConfig
{ {
try try
{ {
var item = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box); var item = AppHandler.Instance.GetDNSItem(ECoreType.sing_box);
var strDNS = string.Empty; var strDNS = string.Empty;
if (_config.tunModeItem.enableTun) if (_config.tunModeItem.enableTun)
{ {
@ -1260,7 +1260,7 @@ namespace ServiceLib.Handler.CoreConfig
singboxConfig.experimental ??= new Experimental4Sbox(); singboxConfig.experimental ??= new Experimental4Sbox();
singboxConfig.experimental.clash_api = new Clash_Api4Sbox() singboxConfig.experimental.clash_api = new Clash_Api4Sbox()
{ {
external_controller = $"{Global.Loopback}:{LazyConfig.Instance.StatePort2}", external_controller = $"{Global.Loopback}:{AppHandler.Instance.StatePort2}",
}; };
} }

View file

@ -118,7 +118,7 @@ namespace ServiceLib.Handler.CoreConfig
{ {
continue; continue;
} }
var item = LazyConfig.Instance.GetProfileItem(it.indexId); var item = AppHandler.Instance.GetProfileItem(it.indexId);
if (item is null) if (item is null)
{ {
continue; continue;
@ -236,7 +236,7 @@ namespace ServiceLib.Handler.CoreConfig
v2rayConfig.inbounds.Clear(); // Remove "proxy" service for speedtest, avoiding port conflicts. v2rayConfig.inbounds.Clear(); // Remove "proxy" service for speedtest, avoiding port conflicts.
v2rayConfig.outbounds.RemoveAt(0); v2rayConfig.outbounds.RemoveAt(0);
int httpPort = LazyConfig.Instance.GetLocalPort(EInboundProtocol.speedtest); int httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
foreach (var it in selecteds) foreach (var it in selecteds)
{ {
@ -248,7 +248,7 @@ namespace ServiceLib.Handler.CoreConfig
{ {
continue; 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 (it.configType is EConfigType.VMess or EConfigType.VLESS)
{ {
if (item is null || Utils.IsNullOrEmpty(item.id) || !Utils.IsGuidByParse(item.id)) 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.address = node.address;
serversItem.port = node.port; serversItem.port = node.port;
serversItem.password = node.id; 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.ota = false;
serversItem.level = 1; serversItem.level = 1;
@ -1029,7 +1029,7 @@ namespace ServiceLib.Handler.CoreConfig
{ {
try try
{ {
var item = LazyConfig.Instance.GetDNSItem(ECoreType.Xray); var item = AppHandler.Instance.GetDNSItem(ECoreType.Xray);
var normalDNS = item?.normalDNS; var normalDNS = item?.normalDNS;
var domainStrategy4Freedom = item?.domainStrategy4Freedom; var domainStrategy4Freedom = item?.domainStrategy4Freedom;
if (Utils.IsNullOrEmpty(normalDNS)) if (Utils.IsNullOrEmpty(normalDNS))
@ -1136,7 +1136,7 @@ namespace ServiceLib.Handler.CoreConfig
Inboundsettings4Ray apiInboundSettings = new(); Inboundsettings4Ray apiInboundSettings = new();
apiInbound.tag = tag; apiInbound.tag = tag;
apiInbound.listen = Global.Loopback; apiInbound.listen = Global.Loopback;
apiInbound.port = LazyConfig.Instance.StatePort; apiInbound.port = AppHandler.Instance.StatePort;
apiInbound.protocol = Global.InboundAPIProtocol; apiInbound.protocol = Global.InboundAPIProtocol;
apiInboundSettings.address = Global.Loopback; apiInboundSettings.address = Global.Loopback;
apiInbound.settings = apiInboundSettings; apiInbound.settings = apiInboundSettings;
@ -1193,7 +1193,7 @@ namespace ServiceLib.Handler.CoreConfig
} }
try try
{ {
var subItem = LazyConfig.Instance.GetSubItem(node.subid); var subItem = AppHandler.Instance.GetSubItem(node.subid);
if (subItem is null) if (subItem is null)
{ {
return 0; return 0;
@ -1204,7 +1204,7 @@ namespace ServiceLib.Handler.CoreConfig
var txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound); var txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound);
//Previous proxy //Previous proxy
var prevNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.prevProfile); var prevNode = AppHandler.Instance.GetProfileItemViaRemarks(subItem.prevProfile);
if (prevNode is not null if (prevNode is not null
&& prevNode.configType != EConfigType.Custom && prevNode.configType != EConfigType.Custom
&& prevNode.configType != EConfigType.Hysteria2 && prevNode.configType != EConfigType.Hysteria2
@ -1223,7 +1223,7 @@ namespace ServiceLib.Handler.CoreConfig
} }
//Next proxy //Next proxy
var nextNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.nextProfile); var nextNode = AppHandler.Instance.GetProfileItemViaRemarks(subItem.nextProfile);
if (nextNode is not null if (nextNode is not null
&& nextNode.configType != EConfigType.Custom && nextNode.configType != EConfigType.Custom
&& nextNode.configType != EConfigType.Hysteria2 && nextNode.configType != EConfigType.Hysteria2

View file

@ -182,7 +182,7 @@ namespace ServiceLib.Handler
//{ //{
// coreType = LazyConfig.Instance.GetCoreType(node, node.configType); // 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; _config.runningCoreType = coreType;
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(coreType); var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(coreType);
@ -207,7 +207,7 @@ namespace ServiceLib.Handler
configType = EConfigType.SOCKS, configType = EConfigType.SOCKS,
address = Global.Loopback, address = Global.Loopback,
sni = node.address, //Tun2SocksAddress 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)) else if ((node.configType == EConfigType.Custom && node.preSocksPort > 0))
@ -339,7 +339,7 @@ namespace ServiceLib.Handler
startUpSuccessful = true; startUpSuccessful = true;
} }
LazyConfig.Instance.AddProcess(proc.Handle); AppHandler.Instance.AddProcess(proc.Handle);
return proc; return proc;
} }
catch (Exception ex) catch (Exception ex)

View file

@ -30,7 +30,7 @@ namespace ServiceLib.Handler
{ {
try try
{ {
Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13); Utils.SetSecurityProtocol(AppHandler.Instance.Config.guiItem.enableSecurityProtocolTls13);
var progress = new Progress<string>(); var progress = new Progress<string>();
progress.ProgressChanged += (sender, value) => progress.ProgressChanged += (sender, value) =>
@ -62,7 +62,7 @@ namespace ServiceLib.Handler
{ {
try try
{ {
Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13); Utils.SetSecurityProtocol(AppHandler.Instance.Config.guiItem.enableSecurityProtocolTls13);
UpdateCompleted?.Invoke(this, new ResultEventArgs(false, $"{ResUI.Downloading} {url}")); UpdateCompleted?.Invoke(this, new ResultEventArgs(false, $"{ResUI.Downloading} {url}"));
var progress = new Progress<double>(); var progress = new Progress<double>();
@ -92,7 +92,7 @@ namespace ServiceLib.Handler
public async Task<string?> UrlRedirectAsync(string url, bool blProxy) 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 var webRequestHandler = new SocketsHttpHandler
{ {
AllowAutoRedirect = false, AllowAutoRedirect = false,
@ -181,7 +181,7 @@ namespace ServiceLib.Handler
{ {
try try
{ {
Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13); Utils.SetSecurityProtocol(AppHandler.Instance.Config.guiItem.enableSecurityProtocolTls13);
var webProxy = GetWebProxy(blProxy); var webProxy = GetWebProxy(blProxy);
var client = new HttpClient(new SocketsHttpHandler() var client = new HttpClient(new SocketsHttpHandler()
{ {
@ -226,7 +226,7 @@ namespace ServiceLib.Handler
{ {
try try
{ {
Utils.SetSecurityProtocol(LazyConfig.Instance.Config.guiItem.enableSecurityProtocolTls13); Utils.SetSecurityProtocol(AppHandler.Instance.Config.guiItem.enableSecurityProtocolTls13);
var webProxy = GetWebProxy(blProxy); var webProxy = GetWebProxy(blProxy);
@ -260,7 +260,7 @@ namespace ServiceLib.Handler
try try
{ {
var config = LazyConfig.Instance.Config; var config = AppHandler.Instance.Config;
int responseTime = await GetRealPingTime(config.speedTestItem.speedPingTestUrl, webProxy, 10); int responseTime = await GetRealPingTime(config.speedTestItem.speedPingTestUrl, webProxy, 10);
return responseTime; return responseTime;
} }
@ -314,7 +314,7 @@ namespace ServiceLib.Handler
{ {
return null; return null;
} }
var httpPort = LazyConfig.Instance.GetLocalPort(EInboundProtocol.http); var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.http);
if (!SocketCheck(Global.Loopback, httpPort)) if (!SocketCheck(Global.Loopback, httpPort))
{ {
return null; return null;

View file

@ -236,7 +236,7 @@ namespace ServiceLib.Handler
ProfileExHandler.Instance.SetTestSpeed(it.indexId, "-1"); ProfileExHandler.Instance.SetTestSpeed(it.indexId, "-1");
UpdateFunc(it.indexId, "", ResUI.Speedtesting); UpdateFunc(it.indexId, "", ResUI.Speedtesting);
var item = LazyConfig.Instance.GetProfileItem(it.indexId); var item = AppHandler.Instance.GetProfileItem(it.indexId);
if (item is null) continue; if (item is null) continue;
WebProxy webProxy = new(Global.Loopback, it.port); WebProxy webProxy = new(Global.Loopback, it.port);
@ -299,7 +299,7 @@ namespace ServiceLib.Handler
ProfileExHandler.Instance.SetTestSpeed(it.indexId, "-1"); ProfileExHandler.Instance.SetTestSpeed(it.indexId, "-1");
UpdateFunc(it.indexId, "", ResUI.Speedtesting); UpdateFunc(it.indexId, "", ResUI.Speedtesting);
var item = LazyConfig.Instance.GetProfileItem(it.indexId); var item = AppHandler.Instance.GetProfileItem(it.indexId);
if (item is null) continue; if (item is null) continue;
WebProxy webProxy = new(Global.Loopback, it.port); WebProxy webProxy = new(Global.Loopback, it.port);

View file

@ -26,7 +26,7 @@ namespace ServiceLib.Handler.Statistics
try try
{ {
url = $"ws://{Global.Loopback}:{LazyConfig.Instance.StatePort2}/traffic"; url = $"ws://{Global.Loopback}:{AppHandler.Instance.StatePort2}/traffic";
if (webSocket == null) if (webSocket == null)
{ {

View file

@ -29,7 +29,7 @@ namespace ServiceLib.Handler.Statistics
{ {
try 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); _client = new StatsService.StatsServiceClient(_channel);
} }
catch (Exception ex) catch (Exception ex)

View file

@ -24,7 +24,7 @@
while (true) while (true)
{ {
var updateTime = ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds(); var updateTime = ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
var lstSubs = LazyConfig.Instance.SubItems() var lstSubs = AppHandler.Instance.SubItems()
.Where(t => t.autoUpdateInterval > 0) .Where(t => t.autoUpdateInterval > 0)
.Where(t => updateTime - t.updateTime >= t.autoUpdateInterval * 60) .Where(t => updateTime - t.updateTime >= t.autoUpdateInterval * 60)
.ToList(); .ToList();

View file

@ -128,7 +128,7 @@ namespace ServiceLib.Handler
_updateFunc = update; _updateFunc = update;
_updateFunc(false, ResUI.MsgUpdateSubscriptionStart); _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) if (subItem == null || subItem.Count <= 0)
{ {

View file

@ -17,7 +17,7 @@ namespace ServiceLib.Handler
public WebDavHandler() public WebDavHandler()
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
} }
private async Task<bool> GetClient() private async Task<bool> GetClient()

View file

@ -103,8 +103,6 @@
public int trayMenuServersLimit { get; set; } = 20; public int trayMenuServersLimit { get; set; } = 20;
public bool enableHWA { get; set; } = false; public bool enableHWA { get; set; } = false;
public bool enableLog { get; set; } = true;
} }
[Serializable] [Serializable]

View file

@ -21,7 +21,7 @@ namespace ServiceLib.ViewModels
public AddServer2ViewModel(ProfileItem profileItem, Func<EViewAction, object?, Task<bool>>? updateView) public AddServer2ViewModel(ProfileItem profileItem, Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_updateView = updateView; _updateView = updateView;
if (profileItem.indexId.IsNullOrEmpty()) if (profileItem.indexId.IsNullOrEmpty())
@ -84,7 +84,7 @@ namespace ServiceLib.ViewModels
return; return;
} }
var item = LazyConfig.Instance.GetProfileItem(SelectedSource.indexId); var item = AppHandler.Instance.GetProfileItem(SelectedSource.indexId);
item ??= SelectedSource; item ??= SelectedSource;
item.address = fileName; item.address = fileName;
if (ConfigHandler.AddCustomServer(_config, item, false) == 0) if (ConfigHandler.AddCustomServer(_config, item, false) == 0)

View file

@ -17,7 +17,7 @@ namespace ServiceLib.ViewModels
public AddServerViewModel(ProfileItem profileItem, Func<EViewAction, object?, Task<bool>>? updateView) public AddServerViewModel(ProfileItem profileItem, Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;

View file

@ -22,7 +22,7 @@ namespace ServiceLib.ViewModels
public BackupAndRestoreViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public BackupAndRestoreViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_updateView = updateView; _updateView = updateView;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();

View file

@ -22,7 +22,7 @@ namespace ServiceLib.ViewModels
public CheckUpdateViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public CheckUpdateViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_updateView = updateView; _updateView = updateView;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();

View file

@ -30,7 +30,7 @@ namespace ServiceLib.ViewModels
public ClashConnectionsViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public ClashConnectionsViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_updateView = updateView; _updateView = updateView;
SortingSelected = _config.clashUIItem.connectionsSorting; SortingSelected = _config.clashUIItem.connectionsSorting;
AutoRefresh = _config.clashUIItem.connectionsAutoRefresh; AutoRefresh = _config.clashUIItem.connectionsAutoRefresh;

View file

@ -45,7 +45,7 @@ namespace ServiceLib.ViewModels
public ClashProxiesViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public ClashProxiesViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_updateView = updateView; _updateView = updateView;
SelectedGroup = new(); SelectedGroup = new();

View file

@ -23,17 +23,17 @@ namespace ServiceLib.ViewModels
public DNSSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public DNSSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
var item = LazyConfig.Instance.GetDNSItem(ECoreType.Xray); var item = AppHandler.Instance.GetDNSItem(ECoreType.Xray);
useSystemHosts = item.useSystemHosts; useSystemHosts = item.useSystemHosts;
domainStrategy4Freedom = item?.domainStrategy4Freedom ?? string.Empty; domainStrategy4Freedom = item?.domainStrategy4Freedom ?? string.Empty;
domainDNSAddress = item?.domainDNSAddress ?? string.Empty; domainDNSAddress = item?.domainDNSAddress ?? string.Empty;
normalDNS = item?.normalDNS ?? string.Empty; normalDNS = item?.normalDNS ?? string.Empty;
var item2 = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box); var item2 = AppHandler.Instance.GetDNSItem(ECoreType.sing_box);
domainStrategy4Freedom2 = item2?.domainStrategy4Freedom ?? string.Empty; domainStrategy4Freedom2 = item2?.domainStrategy4Freedom ?? string.Empty;
domainDNSAddress2 = item2?.domainDNSAddress ?? string.Empty; domainDNSAddress2 = item2?.domainDNSAddress ?? string.Empty;
normalDNS2 = item2?.normalDNS ?? string.Empty; normalDNS2 = item2?.normalDNS ?? string.Empty;
@ -92,14 +92,14 @@ namespace ServiceLib.ViewModels
} }
} }
var item = LazyConfig.Instance.GetDNSItem(ECoreType.Xray); var item = AppHandler.Instance.GetDNSItem(ECoreType.Xray);
item.domainStrategy4Freedom = domainStrategy4Freedom; item.domainStrategy4Freedom = domainStrategy4Freedom;
item.domainDNSAddress = domainDNSAddress; item.domainDNSAddress = domainDNSAddress;
item.useSystemHosts = useSystemHosts; item.useSystemHosts = useSystemHosts;
item.normalDNS = normalDNS; item.normalDNS = normalDNS;
ConfigHandler.SaveDNSItems(_config, item); ConfigHandler.SaveDNSItems(_config, item);
var item2 = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box); var item2 = AppHandler.Instance.GetDNSItem(ECoreType.sing_box);
item2.domainStrategy4Freedom = domainStrategy4Freedom2; item2.domainStrategy4Freedom = domainStrategy4Freedom2;
item2.domainDNSAddress = domainDNSAddress2; item2.domainDNSAddress = domainDNSAddress2;
item2.normalDNS = JsonUtils.Serialize(JsonUtils.ParseJson(normalDNS2)); item2.normalDNS = JsonUtils.Serialize(JsonUtils.ParseJson(normalDNS2));

View file

@ -146,7 +146,7 @@ namespace ServiceLib.ViewModels
public MainWindowViewModel(bool isAdministrator, Func<EViewAction, object?, Task<bool>>? updateView) public MainWindowViewModel(bool isAdministrator, Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
_isAdministrator = isAdministrator; _isAdministrator = isAdministrator;
@ -486,7 +486,7 @@ namespace ServiceLib.ViewModels
private void RefreshServersMenu() private void RefreshServersMenu()
{ {
var lstModel = LazyConfig.Instance.ProfileItems(_config.subIndexId, ""); var lstModel = AppHandler.Instance.ProfileItems(_config.subIndexId, "");
_servers.Clear(); _servers.Clear();
if (lstModel.Count > _config.guiItem.trayMenuServersLimit) if (lstModel.Count > _config.guiItem.trayMenuServersLimit)
@ -591,7 +591,7 @@ namespace ServiceLib.ViewModels
{ {
return; return;
} }
var item = LazyConfig.Instance.GetProfileItem(indexId); var item = AppHandler.Instance.GetProfileItem(indexId);
if (item is null) if (item is null)
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer); _noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
@ -809,7 +809,7 @@ namespace ServiceLib.ViewModels
} }
BlRouting = true; BlRouting = true;
var routings = LazyConfig.Instance.RoutingItems(); var routings = AppHandler.Instance.RoutingItems();
foreach (var item in routings) foreach (var item in routings)
{ {
_routingItems.Add(item); _routingItems.Add(item);
@ -832,7 +832,7 @@ namespace ServiceLib.ViewModels
return; return;
} }
var item = LazyConfig.Instance.GetRoutingItem(SelectedRouting?.id); var item = AppHandler.Instance.GetRoutingItem(SelectedRouting?.id);
if (item is null) if (item is null)
{ {
return; return;
@ -887,7 +887,7 @@ namespace ServiceLib.ViewModels
public void InboundDisplayStaus() public void InboundDisplayStaus()
{ {
StringBuilder sb = new(); StringBuilder sb = new();
sb.Append($"[{EInboundProtocol.socks}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks)}]"); sb.Append($"[{EInboundProtocol.socks}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.socks)}]");
sb.Append(" | "); sb.Append(" | ");
//if (_config.systemProxyItem.sysProxyType == ESysProxyType.ForcedChange) //if (_config.systemProxyItem.sysProxyType == ESysProxyType.ForcedChange)
//{ //{
@ -895,7 +895,7 @@ namespace ServiceLib.ViewModels
//} //}
//else //else
//{ //{
sb.Append($"[{EInboundProtocol.http}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.http)}]"); sb.Append($"[{EInboundProtocol.http}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.http)}]");
//} //}
InboundDisplay = $"{ResUI.LabLocal}:{sb}"; InboundDisplay = $"{ResUI.LabLocal}:{sb}";
@ -904,9 +904,9 @@ namespace ServiceLib.ViewModels
if (_config.inbound[0].newPort4LAN) if (_config.inbound[0].newPort4LAN)
{ {
StringBuilder sb2 = new(); StringBuilder sb2 = new();
sb2.Append($"[{EInboundProtocol.socks}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks2)}]"); sb2.Append($"[{EInboundProtocol.socks}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.socks2)}]");
sb2.Append(" | "); sb2.Append(" | ");
sb2.Append($"[{EInboundProtocol.http}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.http2)}]"); sb2.Append($"[{EInboundProtocol.http}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.http2)}]");
InboundLanDisplay = $"{ResUI.LabLAN}:{sb2}"; InboundLanDisplay = $"{ResUI.LabLAN}:{sb2}";
} }
else else

View file

@ -22,7 +22,7 @@ namespace ServiceLib.ViewModels
public MsgViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public MsgViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_updateView = updateView; _updateView = updateView;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();

View file

@ -102,7 +102,7 @@ namespace ServiceLib.ViewModels
public OptionSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public OptionSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;

View file

@ -97,7 +97,7 @@ namespace ServiceLib.ViewModels
public ProfilesViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public ProfilesViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
@ -350,7 +350,7 @@ namespace ServiceLib.ViewModels
public void RefreshServersBiz() public void RefreshServersBiz()
{ {
var lstModel = LazyConfig.Instance.ProfileItemsEx(_config.subIndexId, _serverFilter); var lstModel = AppHandler.Instance.ProfileItemsEx(_config.subIndexId, _serverFilter);
_lstProfile = JsonUtils.Deserialize<List<ProfileItem>>(JsonUtils.Serialize(lstModel)) ?? []; _lstProfile = JsonUtils.Deserialize<List<ProfileItem>>(JsonUtils.Serialize(lstModel)) ?? [];
_profileItems.Clear(); _profileItems.Clear();
@ -374,7 +374,7 @@ namespace ServiceLib.ViewModels
_subItems.Clear(); _subItems.Clear();
_subItems.Add(new SubItem { remarks = ResUI.AllGroupServers }); _subItems.Add(new SubItem { remarks = ResUI.AllGroupServers });
foreach (var item in LazyConfig.Instance.SubItems().OrderBy(t => t.sort)) foreach (var item in AppHandler.Instance.SubItems().OrderBy(t => t.sort))
{ {
_subItems.Add(item); _subItems.Add(item);
} }
@ -405,7 +405,7 @@ namespace ServiceLib.ViewModels
{ {
foreach (var profile in orderProfiles) foreach (var profile in orderProfiles)
{ {
var item = LazyConfig.Instance.GetProfileItem(profile.indexId); var item = AppHandler.Instance.GetProfileItem(profile.indexId);
if (item is not null) if (item is not null)
{ {
lstSelecteds.Add(item); lstSelecteds.Add(item);
@ -426,7 +426,7 @@ namespace ServiceLib.ViewModels
{ {
return; return;
} }
var item = LazyConfig.Instance.GetProfileItem(SelectedProfile.indexId); var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId);
if (item is null) if (item is null)
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer); _noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
@ -515,7 +515,7 @@ namespace ServiceLib.ViewModels
{ {
return; return;
} }
var item = LazyConfig.Instance.GetProfileItem(indexId); var item = AppHandler.Instance.GetProfileItem(indexId);
if (item is null) if (item is null)
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer); _noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
@ -548,7 +548,7 @@ namespace ServiceLib.ViewModels
public async Task ShareServerAsync() public async Task ShareServerAsync()
{ {
var item = LazyConfig.Instance.GetProfileItem(SelectedProfile.indexId); var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId);
if (item is null) if (item is null)
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer); _noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
@ -681,7 +681,7 @@ namespace ServiceLib.ViewModels
private async Task Export2ClientConfigAsync(bool blClipboard) private async Task Export2ClientConfigAsync(bool blClipboard)
{ {
var item = LazyConfig.Instance.GetProfileItem(SelectedProfile.indexId); var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId);
if (item is null) if (item is null)
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer); _noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
@ -767,7 +767,7 @@ namespace ServiceLib.ViewModels
} }
else else
{ {
item = LazyConfig.Instance.GetSubItem(_config.subIndexId); item = AppHandler.Instance.GetSubItem(_config.subIndexId);
if (item is null) if (item is null)
{ {
return; return;

View file

@ -29,7 +29,7 @@ namespace ServiceLib.ViewModels
public RoutingRuleDetailsViewModel(RulesItem rulesItem, Func<EViewAction, object?, Task<bool>>? updateView) public RoutingRuleDetailsViewModel(RulesItem rulesItem, Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;

View file

@ -36,7 +36,7 @@ namespace ServiceLib.ViewModels
public RoutingRuleSettingViewModel(RoutingItem routingItem, Func<EViewAction, object?, Task<bool>>? updateView) public RoutingRuleSettingViewModel(RoutingItem routingItem, Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
SelectedSource = new(); SelectedSource = new();

View file

@ -67,7 +67,7 @@ namespace ServiceLib.ViewModels
public RoutingSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public RoutingSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
SelectedSource = new(); SelectedSource = new();
@ -165,7 +165,7 @@ namespace ServiceLib.ViewModels
{ {
_routingItems.Clear(); _routingItems.Clear();
var routings = LazyConfig.Instance.RoutingItems(); var routings = AppHandler.Instance.RoutingItems();
foreach (var item in routings) foreach (var item in routings)
{ {
bool def = false; bool def = false;
@ -232,7 +232,7 @@ namespace ServiceLib.ViewModels
} }
else else
{ {
item = LazyConfig.Instance.GetRoutingItem(SelectedSource?.id); item = AppHandler.Instance.GetRoutingItem(SelectedSource?.id);
if (item is null) if (item is null)
{ {
return; return;
@ -258,7 +258,7 @@ namespace ServiceLib.ViewModels
} }
foreach (var it in SelectedSources ?? [SelectedSource]) foreach (var it in SelectedSources ?? [SelectedSource])
{ {
var item = LazyConfig.Instance.GetRoutingItem(it?.id); var item = AppHandler.Instance.GetRoutingItem(it?.id);
if (item != null) if (item != null)
{ {
ConfigHandler.RemoveRoutingItem(item); ConfigHandler.RemoveRoutingItem(item);
@ -271,7 +271,7 @@ namespace ServiceLib.ViewModels
public void RoutingAdvancedSetDefault() public void RoutingAdvancedSetDefault()
{ {
var item = LazyConfig.Instance.GetRoutingItem(SelectedSource?.id); var item = AppHandler.Instance.GetRoutingItem(SelectedSource?.id);
if (item is null) if (item is null)
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectRules); _noticeHandler?.Enqueue(ResUI.PleaseSelectRules);

View file

@ -14,7 +14,7 @@ namespace ServiceLib.ViewModels
public SubEditViewModel(SubItem subItem, Func<EViewAction, object?, Task<bool>>? updateView) public SubEditViewModel(SubItem subItem, Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;

View file

@ -25,7 +25,7 @@ namespace ServiceLib.ViewModels
public SubSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public SubSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
@ -58,7 +58,7 @@ namespace ServiceLib.ViewModels
public void RefreshSubItems() public void RefreshSubItems()
{ {
_subItems.Clear(); _subItems.Clear();
_subItems.AddRange(LazyConfig.Instance.SubItems().OrderBy(t => t.sort)); _subItems.AddRange(AppHandler.Instance.SubItems().OrderBy(t => t.sort));
} }
public async Task EditSubAsync(bool blNew) public async Task EditSubAsync(bool blNew)
@ -70,7 +70,7 @@ namespace ServiceLib.ViewModels
} }
else else
{ {
item = LazyConfig.Instance.GetSubItem(SelectedSource?.id); item = AppHandler.Instance.GetSubItem(SelectedSource?.id);
if (item is null) if (item is null)
{ {
return; return;

View file

@ -1,7 +1,6 @@
using Avalonia; using Avalonia;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Splat;
using v2rayN.Desktop.ViewModels; using v2rayN.Desktop.ViewModels;
using v2rayN.Desktop.Views; using v2rayN.Desktop.Views;
@ -10,11 +9,14 @@ namespace v2rayN.Desktop;
public partial class App : Application public partial class App : Application
{ {
//public static EventWaitHandle ProgramStarted; //public static EventWaitHandle ProgramStarted;
private static Config _config;
public override void Initialize() public override void Initialize()
{ {
Init(); if (!AppHandler.Instance.InitApp())
{
Environment.Exit(0);
return;
}
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
@ -49,30 +51,7 @@ public partial class App : Application
// return; // return;
//} //}
Logging.Setup(); AppHandler.Instance.InitComponents();
Logging.LoggingEnabled(_config.guiItem.enableLog);
Logging.SaveLog($"v2rayN start up | {Utils.GetVersion()} | {Utils.GetExePath()}");
Logging.SaveLog($"{Environment.OSVersion} - {(Environment.Is64BitOperatingSystem ? 64 : 32)}");
Logging.ClearLogs();
}
private void Init()
{
if (ConfigHandler.LoadConfig(ref _config) != 0)
{
//Logging.SaveLog($"Loading GUI configuration file is abnormal,please restart the application{Environment.NewLine}加载GUI配置文件异常,请重启应用");
Environment.Exit(0);
return;
}
LazyConfig.Instance.SetConfig(_config);
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);
}
} }
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)

View file

@ -16,9 +16,9 @@ namespace v2rayN.Desktop.Handler
try try
{ {
int port = LazyConfig.Instance.GetLocalPort(EInboundProtocol.http); int port = AppHandler.Instance.GetLocalPort(EInboundProtocol.http);
int portSocks = LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks); int portSocks = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
int portPac = LazyConfig.Instance.GetLocalPort(EInboundProtocol.pac); int portPac = AppHandler.Instance.GetLocalPort(EInboundProtocol.pac);
if (port <= 0) if (port <= 0)
{ {
return false; return false;

View file

@ -16,7 +16,7 @@ namespace v2rayN.Desktop.ViewModels
public AppViewModel() public AppViewModel()
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
AddServerViaClipboardCmd = ReactiveCommand.Create(() => AddServerViaClipboardCmd = ReactiveCommand.Create(() =>

View file

@ -21,7 +21,7 @@ namespace v2rayN.Desktop.ViewModels
public ThemeSettingViewModel() public ThemeSettingViewModel()
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
BindingUI(); BindingUI();

View file

@ -79,7 +79,7 @@ namespace v2rayN.Desktop.Views
case EConfigType.Shadowsocks: case EConfigType.Shadowsocks:
gridSs.IsVisible = true; gridSs.IsVisible = true;
LazyConfig.Instance.GetShadowsocksSecurities(profileItem).ForEach(it => AppHandler.Instance.GetShadowsocksSecurities(profileItem).ForEach(it =>
{ {
cmbSecurity3.Items.Add(it); cmbSecurity3.Items.Add(it);
}); });

View file

@ -13,7 +13,7 @@ namespace v2rayN.Desktop.Views
{ {
InitializeComponent(); InitializeComponent();
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
btnCancel.Click += (s, e) => this.Close(); btnCancel.Click += (s, e) => this.Close();
ViewModel = new DNSSettingViewModel(UpdateViewHandler); ViewModel = new DNSSettingViewModel(UpdateViewHandler);

View file

@ -12,7 +12,7 @@ namespace v2rayN.Desktop.Views
InitializeComponent(); InitializeComponent();
btnCancel.Click += (s, e) => this.Close(); btnCancel.Click += (s, e) => this.Close();
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
//_config.globalHotkeys ??= new List<KeyEventItem>(); //_config.globalHotkeys ??= new List<KeyEventItem>();
//txtGlobalHotkey0.KeyDown += TxtGlobalHotkey_PreviewKeyDown; //txtGlobalHotkey0.KeyDown += TxtGlobalHotkey_PreviewKeyDown;

View file

@ -27,7 +27,7 @@ namespace v2rayN.Desktop.Views
{ {
InitializeComponent(); InitializeComponent();
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_manager = new WindowNotificationManager(TopLevel.GetTopLevel(this)) { MaxItems = 3, Position = NotificationPosition.BottomRight }; _manager = new WindowNotificationManager(TopLevel.GetTopLevel(this)) { MaxItems = 3, Position = NotificationPosition.BottomRight };
//ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false); //ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false);

View file

@ -14,7 +14,7 @@ namespace v2rayN.Desktop.Views
InitializeComponent(); InitializeComponent();
btnCancel.Click += (s, e) => this.Close(); btnCancel.Click += (s, e) => this.Close();
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
// var lstFonts = GetFonts(Utils.GetFontsPath()); // var lstFonts = GetFonts(Utils.GetFontsPath());
ViewModel = new OptionSettingViewModel(UpdateViewHandler); ViewModel = new OptionSettingViewModel(UpdateViewHandler);

View file

@ -21,7 +21,7 @@ namespace v2rayN.Desktop.Views
{ {
InitializeComponent(); InitializeComponent();
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_window = window; _window = window;
menuSelectAll.Click += menuSelectAll_Click; menuSelectAll.Click += menuSelectAll_Click;

View file

@ -1,5 +1,4 @@
using Splat; using System.Diagnostics;
using System.Diagnostics;
using System.Windows; using System.Windows;
using System.Windows.Threading; using System.Windows.Threading;
@ -38,34 +37,15 @@ namespace v2rayN
return; return;
} }
Logging.Setup(); if (!AppHandler.Instance.InitApp())
Init();
Logging.LoggingEnabled(_config.guiItem.enableLog);
Logging.SaveLog($"v2rayN start up | {Utils.GetVersion()} | {Utils.GetExePath()}");
Logging.SaveLog($"{Environment.OSVersion} - {(Environment.Is64BitOperatingSystem ? 64 : 32)}");
Logging.ClearLogs();
Thread.CurrentThread.CurrentUICulture = new(_config.uiItem.currentLanguage);
base.OnStartup(e);
}
private void Init()
{
if (ConfigHandler.LoadConfig(ref _config) != 0)
{ {
UI.Show($"Loading GUI configuration file is abnormal,please restart the application{Environment.NewLine}加载GUI配置文件异常,请重启应用"); UI.Show($"Loading GUI configuration file is abnormal,please restart the application{Environment.NewLine}加载GUI配置文件异常,请重启应用");
Environment.Exit(0); Environment.Exit(0);
return; return;
} }
LazyConfig.Instance.SetConfig(_config);
Locator.CurrentMutable.RegisterLazySingleton(() => new NoticeHandler(), typeof(NoticeHandler));
//Under Win10 AppHandler.Instance.InitComponents();
if (Environment.OSVersion.Version.Major < 10) base.OnStartup(e);
{
Environment.SetEnvironmentVariable("DOTNET_EnableWriteXorExecute", "0", EnvironmentVariableTarget.User);
}
} }
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)

View file

@ -10,7 +10,7 @@ namespace v2rayN.Converters
{ {
try try
{ {
var fontFamily = LazyConfig.Instance.Config.uiItem.currentFontFamily; var fontFamily = AppHandler.Instance.Config.uiItem.currentFontFamily;
if (Utils.IsNotEmpty(fontFamily)) if (Utils.IsNotEmpty(fontFamily))
{ {
var fontPath = Utils.GetFontsPath(); var fontPath = Utils.GetFontsPath();

View file

@ -16,7 +16,7 @@ namespace v2rayN.Handler
private Config _config private Config _config
{ {
get => LazyConfig.Instance.Config; get => AppHandler.Instance.Config;
} }
private Dictionary<int, List<EGlobalHotkey>> _hotkeyTriggerDic; private Dictionary<int, List<EGlobalHotkey>> _hotkeyTriggerDic;

View file

@ -15,9 +15,9 @@ namespace v2rayN.Handler
try try
{ {
int port = LazyConfig.Instance.GetLocalPort(EInboundProtocol.http); int port = AppHandler.Instance.GetLocalPort(EInboundProtocol.http);
int portSocks = LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks); int portSocks = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
int portPac = LazyConfig.Instance.GetLocalPort(EInboundProtocol.pac); int portPac = AppHandler.Instance.GetLocalPort(EInboundProtocol.pac);
if (port <= 0) if (port <= 0)
{ {
return false; return false;

View file

@ -37,7 +37,7 @@ namespace v2rayN.ViewModels
public ThemeSettingViewModel() public ThemeSettingViewModel()
{ {
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
RegisterSystemColorSet(_config, Application.Current.MainWindow, (bool bl) => { ModifyTheme(bl); }); RegisterSystemColorSet(_config, Application.Current.MainWindow, (bool bl) => { ModifyTheme(bl); });

View file

@ -34,7 +34,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.EditServerCmd, v => v.btnEdit).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.EditServerCmd, v => v.btnEdit).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SaveServerCmd, v => v.btnSave).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SaveServerCmd, v => v.btnSave).DisposeWith(disposables);
}); });
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark);
} }
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj) private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)

View file

@ -73,7 +73,7 @@ namespace v2rayN.Views
case EConfigType.Shadowsocks: case EConfigType.Shadowsocks:
gridSs.Visibility = Visibility.Visible; gridSs.Visibility = Visibility.Visible;
LazyConfig.Instance.GetShadowsocksSecurities(profileItem).ForEach(it => AppHandler.Instance.GetShadowsocksSecurities(profileItem).ForEach(it =>
{ {
cmbSecurity3.Items.Add(it); cmbSecurity3.Items.Add(it);
}); });
@ -219,7 +219,7 @@ namespace v2rayN.Views
}); });
this.Title = $"{profileItem.configType}"; this.Title = $"{profileItem.configType}";
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark);
} }
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj) private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)

View file

@ -13,7 +13,7 @@ namespace v2rayN.Views
InitializeComponent(); InitializeComponent();
this.Owner = Application.Current.MainWindow; this.Owner = Application.Current.MainWindow;
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
ViewModel = new DNSSettingViewModel(UpdateViewHandler); ViewModel = new DNSSettingViewModel(UpdateViewHandler);
@ -50,7 +50,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.ImportDefConfig4V2rayCmd, v => v.btnImportDefConfig4V2ray).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ImportDefConfig4V2rayCmd, v => v.btnImportDefConfig4V2ray).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ImportDefConfig4SingboxCmd, v => v.btnImportDefConfig4Singbox).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ImportDefConfig4SingboxCmd, v => v.btnImportDefConfig4Singbox).DisposeWith(disposables);
}); });
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark);
} }
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj) private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)

View file

@ -16,7 +16,7 @@ namespace v2rayN.Views
InitializeComponent(); InitializeComponent();
this.Owner = Application.Current.MainWindow; this.Owner = Application.Current.MainWindow;
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
_config.globalHotkeys ??= new List<KeyEventItem>(); _config.globalHotkeys ??= new List<KeyEventItem>();
btnReset.Click += btnReset_Click; btnReset.Click += btnReset_Click;

View file

@ -23,7 +23,7 @@ namespace v2rayN.Views
{ {
InitializeComponent(); InitializeComponent();
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false); ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false);
App.Current.SessionEnding += Current_SessionEnding; App.Current.SessionEnding += Current_SessionEnding;

View file

@ -16,7 +16,7 @@ namespace v2rayN.Views
InitializeComponent(); InitializeComponent();
this.Owner = Application.Current.MainWindow; this.Owner = Application.Current.MainWindow;
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
var lstFonts = GetFonts(Utils.GetFontsPath()); var lstFonts = GetFonts(Utils.GetFontsPath());
ViewModel = new OptionSettingViewModel(UpdateViewHandler); ViewModel = new OptionSettingViewModel(UpdateViewHandler);
@ -165,7 +165,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
}); });
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark);
} }
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj) private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)

View file

@ -22,7 +22,7 @@ namespace v2rayN.Views
InitializeComponent(); InitializeComponent();
lstGroup.MaxHeight = Math.Floor(SystemParameters.WorkArea.Height * 0.20 / 40) * 40; lstGroup.MaxHeight = Math.Floor(SystemParameters.WorkArea.Height * 0.20 / 40) * 40;
_config = LazyConfig.Instance.Config; _config = AppHandler.Instance.Config;
Application.Current.Exit += Current_Exit; Application.Current.Exit += Current_Exit;
btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click; btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click;

View file

@ -58,7 +58,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
}); });
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark);
} }
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj) private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)

View file

@ -60,7 +60,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
}); });
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark);
} }
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj) private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)

View file

@ -66,7 +66,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
}); });
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark);
} }
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj) private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)

View file

@ -37,7 +37,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
}); });
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark);
} }
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj) private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)

View file

@ -31,7 +31,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.SubEditCmd, v => v.menuSubEdit).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SubEditCmd, v => v.menuSubEdit).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SubShareCmd, v => v.menuSubShare).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SubShareCmd, v => v.menuSubShare).DisposeWith(disposables);
}); });
WindowsUtils.SetDarkBorder(this, LazyConfig.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : LazyConfig.Instance.Config.uiItem.colorModeDark); WindowsUtils.SetDarkBorder(this, AppHandler.Instance.Config.uiItem.followSystemTheme ? !WindowsUtils.IsLightTheme() : AppHandler.Instance.Config.uiItem.colorModeDark);
} }
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj) private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)