Rename LazyConfig to AppHandler

pull/5829/head
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 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)
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -97,7 +97,7 @@ namespace ServiceLib.ViewModels
public ProfilesViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{
_config = LazyConfig.Instance.Config;
_config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView;
@ -350,7 +350,7 @@ namespace ServiceLib.ViewModels
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)) ?? [];
_profileItems.Clear();
@ -374,7 +374,7 @@ namespace ServiceLib.ViewModels
_subItems.Clear();
_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);
}
@ -405,7 +405,7 @@ namespace ServiceLib.ViewModels
{
foreach (var profile in orderProfiles)
{
var item = LazyConfig.Instance.GetProfileItem(profile.indexId);
var item = AppHandler.Instance.GetProfileItem(profile.indexId);
if (item is not null)
{
lstSelecteds.Add(item);
@ -426,7 +426,7 @@ namespace ServiceLib.ViewModels
{
return;
}
var item = LazyConfig.Instance.GetProfileItem(SelectedProfile.indexId);
var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId);
if (item is null)
{
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
@ -515,7 +515,7 @@ namespace ServiceLib.ViewModels
{
return;
}
var item = LazyConfig.Instance.GetProfileItem(indexId);
var item = AppHandler.Instance.GetProfileItem(indexId);
if (item is null)
{
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
@ -548,7 +548,7 @@ namespace ServiceLib.ViewModels
public async Task ShareServerAsync()
{
var item = LazyConfig.Instance.GetProfileItem(SelectedProfile.indexId);
var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId);
if (item is null)
{
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
@ -681,7 +681,7 @@ namespace ServiceLib.ViewModels
private async Task Export2ClientConfigAsync(bool blClipboard)
{
var item = LazyConfig.Instance.GetProfileItem(SelectedProfile.indexId);
var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId);
if (item is null)
{
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
@ -767,7 +767,7 @@ namespace ServiceLib.ViewModels
}
else
{
item = LazyConfig.Instance.GetSubItem(_config.subIndexId);
item = AppHandler.Instance.GetSubItem(_config.subIndexId);
if (item is null)
{
return;

View File

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

View File

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

View File

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

View File

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

View File

@ -25,7 +25,7 @@ namespace ServiceLib.ViewModels
public SubSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{
_config = LazyConfig.Instance.Config;
_config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView;
@ -58,7 +58,7 @@ namespace ServiceLib.ViewModels
public void RefreshSubItems()
{
_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)
@ -70,7 +70,7 @@ namespace ServiceLib.ViewModels
}
else
{
item = LazyConfig.Instance.GetSubItem(SelectedSource?.id);
item = AppHandler.Instance.GetSubItem(SelectedSource?.id);
if (item is null)
{
return;

View File

@ -1,7 +1,6 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Splat;
using v2rayN.Desktop.ViewModels;
using v2rayN.Desktop.Views;
@ -10,11 +9,14 @@ namespace v2rayN.Desktop;
public partial class App : Application
{
//public static EventWaitHandle ProgramStarted;
private static Config _config;
public override void Initialize()
{
Init();
if (!AppHandler.Instance.InitApp())
{
Environment.Exit(0);
return;
}
AvaloniaXamlLoader.Load(this);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
@ -49,30 +51,7 @@ public partial class App : Application
// return;
//}
Logging.Setup();
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);
}
AppHandler.Instance.InitComponents();
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,4 @@
using Splat;
using System.Diagnostics;
using System.Diagnostics;
using System.Windows;
using System.Windows.Threading;
@ -38,34 +37,15 @@ namespace v2rayN
return;
}
Logging.Setup();
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)
if (!AppHandler.Instance.InitApp())
{
UI.Show($"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));
//Under Win10
if (Environment.OSVersion.Version.Major < 10)
{
Environment.SetEnvironmentVariable("DOTNET_EnableWriteXorExecute", "0", EnvironmentVariableTarget.User);
}
AppHandler.Instance.InitComponents();
base.OnStartup(e);
}
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)

View File

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

View File

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

View File

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

View File

@ -37,7 +37,7 @@ namespace v2rayN.ViewModels
public ThemeSettingViewModel()
{
_config = LazyConfig.Instance.Config;
_config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
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.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)

View File

@ -73,7 +73,7 @@ namespace v2rayN.Views
case EConfigType.Shadowsocks:
gridSs.Visibility = Visibility.Visible;
LazyConfig.Instance.GetShadowsocksSecurities(profileItem).ForEach(it =>
AppHandler.Instance.GetShadowsocksSecurities(profileItem).ForEach(it =>
{
cmbSecurity3.Items.Add(it);
});
@ -219,7 +219,7 @@ namespace v2rayN.Views
});
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)

View File

@ -13,7 +13,7 @@ namespace v2rayN.Views
InitializeComponent();
this.Owner = Application.Current.MainWindow;
_config = LazyConfig.Instance.Config;
_config = AppHandler.Instance.Config;
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.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)

View File

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

View File

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

View File

@ -16,7 +16,7 @@ namespace v2rayN.Views
InitializeComponent();
this.Owner = Application.Current.MainWindow;
_config = LazyConfig.Instance.Config;
_config = AppHandler.Instance.Config;
var lstFonts = GetFonts(Utils.GetFontsPath());
ViewModel = new OptionSettingViewModel(UpdateViewHandler);
@ -165,7 +165,7 @@ namespace v2rayN.Views
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)

View File

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

View File

@ -58,7 +58,7 @@ namespace v2rayN.Views
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)

View File

@ -60,7 +60,7 @@ namespace v2rayN.Views
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)

View File

@ -66,7 +66,7 @@ namespace v2rayN.Views
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)

View File

@ -37,7 +37,7 @@ namespace v2rayN.Views
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)

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