mirror of https://github.com/2dust/v2rayN
Code optimization
parent
ffb38129e2
commit
f0bac4b4c8
|
@ -9,7 +9,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Protobuf" Version="3.28.2" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.28.3" />
|
||||
<PackageReference Include="Grpc.Net.Client" Version="2.66.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.67.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
|
|
@ -495,7 +495,7 @@ namespace ServiceLib.Common
|
|||
{
|
||||
if (blFull)
|
||||
{
|
||||
return $"{Global.AppName} - V{GetVersionInfo()} - {File.GetLastWriteTime(GetExePath()):yyyy/MM/dd}";
|
||||
return $"{Global.AppName} - V{GetVersionInfo()} - {RuntimeInformation.ProcessArchitecture} - {File.GetLastWriteTime(GetExePath()):yyyy/MM/dd}";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -126,18 +126,7 @@
|
|||
|
||||
public async Task<List<string>> ProfileItemIndexes(string subid)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(subid))
|
||||
{
|
||||
return (await SQLiteHelper.Instance.TableAsync<ProfileItem>().ToListAsync())
|
||||
.Select(t => t.IndexId)
|
||||
.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return (await SQLiteHelper.Instance.TableAsync<ProfileItem>().Where(t => t.Subid == subid).ToListAsync())
|
||||
.Select(t => t.IndexId)
|
||||
.ToList();
|
||||
}
|
||||
return (await ProfileItems(subid)).Select(t => t.IndexId).ToList();
|
||||
}
|
||||
|
||||
public async Task<List<ProfileItemModel>> ProfileItems(string subid, string filter)
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace ServiceLib.Handler
|
|||
private static readonly Lazy<ClashApiHandler> instance = new(() => new());
|
||||
public static ClashApiHandler Instance => instance.Value;
|
||||
|
||||
private Dictionary<String, ProxiesItem>? _proxies;
|
||||
private Dictionary<string, ProxiesItem>? _proxies;
|
||||
public Dictionary<string, object> ProfileContent { get; set; }
|
||||
|
||||
public async Task<Tuple<ClashProxies, ClashProviders>?> GetClashProxiesAsync(Config config)
|
||||
|
|
|
@ -108,7 +108,7 @@ namespace ServiceLib.Handler
|
|||
EnableAutoAdjustMainLvColWidth = true
|
||||
};
|
||||
config.UiItem.MainColumnItem ??= new();
|
||||
|
||||
|
||||
if (Utils.IsNullOrEmpty(config.UiItem.CurrentLanguage))
|
||||
{
|
||||
if (Thread.CurrentThread.CurrentCulture.Name.Equals("zh-cn", StringComparison.CurrentCultureIgnoreCase))
|
||||
|
@ -380,8 +380,8 @@ namespace ServiceLib.Handler
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
var count = await SQLiteHelper.Instance.TableAsync<ProfileItem>().CountAsync(t => t.IndexId == config.IndexId);
|
||||
if (count > 0)
|
||||
|
||||
if (await SQLiteHelper.Instance.TableAsync<ProfileItem>().FirstOrDefaultAsync(t => t.IndexId == config.IndexId) != null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ namespace ServiceLib.Handler
|
|||
return await SetDefaultServerIndex(config, lstProfile.FirstOrDefault(t => t.Port > 0)?.IndexId);
|
||||
}
|
||||
|
||||
var item = await SQLiteHelper.Instance.TableAsync<ProfileItem>().Where(t => t.Port > 0).FirstOrDefaultAsync();
|
||||
var item = await SQLiteHelper.Instance.TableAsync<ProfileItem>().FirstOrDefaultAsync(t => t.Port > 0);
|
||||
return await SetDefaultServerIndex(config, item.IndexId);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace ServiceLib.Handler
|
|||
else
|
||||
{
|
||||
ShowMsg(true, $"{node.GetSummary()}");
|
||||
CoreStop();
|
||||
await CoreStop();
|
||||
await CoreStart(node);
|
||||
|
||||
//In tun mode, do a delay check and restart the core
|
||||
|
@ -74,19 +74,19 @@ namespace ServiceLib.Handler
|
|||
ShowMsg(false, result.Msg);
|
||||
if (result.Success)
|
||||
{
|
||||
pid = CoreStartSpeedtest(configPath, coreType);
|
||||
pid = await CoreStartSpeedtest(configPath, coreType);
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void CoreStop()
|
||||
public async Task CoreStop()
|
||||
{
|
||||
try
|
||||
{
|
||||
bool hasProc = false;
|
||||
if (_process != null)
|
||||
{
|
||||
KillProcess(_process);
|
||||
await KillProcess(_process);
|
||||
_process.Dispose();
|
||||
_process = null;
|
||||
hasProc = true;
|
||||
|
@ -94,7 +94,7 @@ namespace ServiceLib.Handler
|
|||
|
||||
if (_processPre != null)
|
||||
{
|
||||
KillProcess(_processPre);
|
||||
await KillProcess(_processPre);
|
||||
_processPre.Dispose();
|
||||
_processPre = null;
|
||||
hasProc = true;
|
||||
|
@ -117,7 +117,7 @@ namespace ServiceLib.Handler
|
|||
string? path = p.MainModule?.FileName;
|
||||
if (path == Utils.GetExeName(Utils.GetBinPath(vName, it.CoreType.ToString())))
|
||||
{
|
||||
KillProcess(p);
|
||||
await KillProcess(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,12 +130,12 @@ namespace ServiceLib.Handler
|
|||
}
|
||||
}
|
||||
|
||||
public void CoreStopPid(int pid)
|
||||
public async Task CoreStopPid(int pid)
|
||||
{
|
||||
try
|
||||
{
|
||||
var _p = Process.GetProcessById(pid);
|
||||
KillProcess(_p);
|
||||
await KillProcess(_p);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -186,7 +186,7 @@ namespace ServiceLib.Handler
|
|||
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(coreType);
|
||||
|
||||
var displayLog = node.ConfigType != EConfigType.Custom || node.DisplayLog;
|
||||
var proc = RunProcess(node, coreInfo, "", displayLog);
|
||||
var proc = await RunProcess(node, coreInfo, "", displayLog);
|
||||
if (proc is null)
|
||||
{
|
||||
return;
|
||||
|
@ -228,7 +228,7 @@ namespace ServiceLib.Handler
|
|||
if (result.Success)
|
||||
{
|
||||
var coreInfo2 = CoreInfoHandler.Instance.GetCoreInfo(preCoreType);
|
||||
var proc2 = RunProcess(node, coreInfo2, $" -c {Global.CorePreConfigFileName}", true);
|
||||
var proc2 = await RunProcess(node, coreInfo2, $" -c {Global.CorePreConfigFileName}", true);
|
||||
if (proc2 is not null)
|
||||
{
|
||||
_processPre = proc2;
|
||||
|
@ -238,7 +238,7 @@ namespace ServiceLib.Handler
|
|||
}
|
||||
}
|
||||
|
||||
private int CoreStartSpeedtest(string configPath, ECoreType coreType)
|
||||
private async Task<int> CoreStartSpeedtest(string configPath, ECoreType coreType)
|
||||
{
|
||||
ShowMsg(false, string.Format(ResUI.StartService, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")));
|
||||
|
||||
|
@ -246,7 +246,7 @@ namespace ServiceLib.Handler
|
|||
try
|
||||
{
|
||||
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(coreType);
|
||||
var proc = RunProcess(new(), coreInfo, $" -c {Global.CoreSpeedtestConfigFileName}", true);
|
||||
var proc = await RunProcess(new(), coreInfo, $" -c {Global.CoreSpeedtestConfigFileName}", true);
|
||||
if (proc is null)
|
||||
{
|
||||
return -1;
|
||||
|
@ -272,7 +272,7 @@ namespace ServiceLib.Handler
|
|||
|
||||
#region Process
|
||||
|
||||
private Process? RunProcess(ProfileItem node, CoreInfo coreInfo, string configPath, bool displayLog)
|
||||
private async Task<Process?> RunProcess(ProfileItem node, CoreInfo coreInfo, string configPath, bool displayLog)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -351,7 +351,7 @@ namespace ServiceLib.Handler
|
|||
}
|
||||
}
|
||||
|
||||
private void KillProcess(Process? proc)
|
||||
private async Task KillProcess(Process? proc)
|
||||
{
|
||||
if (proc is null)
|
||||
{
|
||||
|
|
|
@ -11,8 +11,8 @@ namespace ServiceLib.ViewModels
|
|||
{
|
||||
public class ClashProxiesViewModel : MyReactiveObject
|
||||
{
|
||||
private Dictionary<String, ProxiesItem>? _proxies;
|
||||
private Dictionary<String, ProvidersItem>? _providers;
|
||||
private Dictionary<string, ProxiesItem>? _proxies;
|
||||
private Dictionary<string, ProvidersItem>? _providers;
|
||||
private int _delayTimeout = 99999999;
|
||||
|
||||
private IObservableCollection<ClashProxyModel> _proxyGroups = new ObservableCollectionExtended<ClashProxyModel>();
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MaterialDesignThemes" Version="5.1.0" />
|
||||
<PackageReference Include="H.NotifyIcon.Wpf" Version="2.1.3" />
|
||||
<PackageReference Include="H.NotifyIcon.Wpf" Version="2.1.4" />
|
||||
<PackageReference Include="TaskScheduler" Version="2.11.0" />
|
||||
<PackageReference Include="ReactiveUI.Fody" Version="19.5.41" />
|
||||
<PackageReference Include="ReactiveUI.WPF" Version="20.1.63" />
|
||||
|
|
Loading…
Reference in New Issue