v2rayN/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs

578 lines
18 KiB
C#
Raw Normal View History

2023-01-01 11:42:01 +00:00
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Splat;
2023-04-06 02:44:29 +00:00
using System.Diagnostics;
2023-01-01 11:42:01 +00:00
using System.Reactive;
using System.Reactive.Linq;
2024-08-20 06:15:29 +00:00
namespace ServiceLib.ViewModels
2023-01-01 11:42:01 +00:00
{
public class MainWindowViewModel : MyReactiveObject
2023-01-01 11:42:01 +00:00
{
#region Menu
//servers
public ReactiveCommand<Unit, Unit> AddVmessServerCmd { get; }
2023-04-14 12:49:36 +00:00
2023-01-01 11:42:01 +00:00
public ReactiveCommand<Unit, Unit> AddVlessServerCmd { get; }
public ReactiveCommand<Unit, Unit> AddShadowsocksServerCmd { get; }
public ReactiveCommand<Unit, Unit> AddSocksServerCmd { get; }
2024-04-10 05:32:50 +00:00
public ReactiveCommand<Unit, Unit> AddHttpServerCmd { get; }
2023-01-01 11:42:01 +00:00
public ReactiveCommand<Unit, Unit> AddTrojanServerCmd { get; }
2023-11-28 08:07:53 +00:00
public ReactiveCommand<Unit, Unit> AddHysteria2ServerCmd { get; }
2023-12-19 08:03:30 +00:00
public ReactiveCommand<Unit, Unit> AddTuicServerCmd { get; }
public ReactiveCommand<Unit, Unit> AddWireguardServerCmd { get; }
2023-01-01 11:42:01 +00:00
public ReactiveCommand<Unit, Unit> AddCustomServerCmd { get; }
public ReactiveCommand<Unit, Unit> AddServerViaClipboardCmd { get; }
public ReactiveCommand<Unit, Unit> AddServerViaScanCmd { get; }
2023-04-14 12:49:36 +00:00
2023-01-01 11:42:01 +00:00
//Subscription
public ReactiveCommand<Unit, Unit> SubSettingCmd { get; }
2023-04-14 12:49:36 +00:00
2023-01-01 11:42:01 +00:00
public ReactiveCommand<Unit, Unit> SubUpdateCmd { get; }
public ReactiveCommand<Unit, Unit> SubUpdateViaProxyCmd { get; }
2023-01-08 01:24:09 +00:00
public ReactiveCommand<Unit, Unit> SubGroupUpdateCmd { get; }
2023-01-01 11:42:01 +00:00
public ReactiveCommand<Unit, Unit> SubGroupUpdateViaProxyCmd { get; }
//Setting
public ReactiveCommand<Unit, Unit> OptionSettingCmd { get; }
2023-04-14 12:49:36 +00:00
2023-01-01 11:42:01 +00:00
public ReactiveCommand<Unit, Unit> RoutingSettingCmd { get; }
public ReactiveCommand<Unit, Unit> DNSSettingCmd { get; }
2023-01-01 11:42:01 +00:00
public ReactiveCommand<Unit, Unit> GlobalHotkeySettingCmd { get; }
public ReactiveCommand<Unit, Unit> RebootAsAdminCmd { get; }
2023-01-01 11:42:01 +00:00
public ReactiveCommand<Unit, Unit> ClearServerStatisticsCmd { get; }
2024-05-08 03:43:03 +00:00
public ReactiveCommand<Unit, Unit> OpenTheFileLocationCmd { get; }
2023-01-01 11:42:01 +00:00
//Presets
public ReactiveCommand<Unit, Unit> PresetDefaultCmd { get; }
public ReactiveCommand<Unit, Unit> PresetRussiaCmd { get; }
2023-01-01 11:42:01 +00:00
public ReactiveCommand<Unit, Unit> ReloadCmd { get; }
2023-04-14 12:49:36 +00:00
2023-01-01 11:42:01 +00:00
[Reactive]
public bool BlReloadEnabled { get; set; }
[Reactive]
2024-07-18 09:39:11 +00:00
public bool ShowClashUI { get; set; }
2024-07-19 02:51:14 +00:00
[Reactive]
public int TabMainSelectedIndex { get; set; }
2024-10-12 07:45:21 +00:00
#endregion Menu
2023-01-01 11:42:01 +00:00
#region Init
2024-10-12 07:45:21 +00:00
public MainWindowViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
2023-01-01 11:42:01 +00:00
{
2024-10-07 01:51:41 +00:00
_config = AppHandler.Instance.Config;
2023-01-01 11:42:01 +00:00
_updateView = updateView;
2024-02-01 04:44:47 +00:00
Init();
_config.uiItem.showInTaskbar = true;
2024-02-01 04:44:47 +00:00
#region WhenAnyValue && ReactiveCommand
2023-01-01 11:42:01 +00:00
//servers
AddVmessServerCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await AddServerAsync(true, EConfigType.VMess);
2023-01-01 11:42:01 +00:00
});
AddVlessServerCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await AddServerAsync(true, EConfigType.VLESS);
2023-01-01 11:42:01 +00:00
});
AddShadowsocksServerCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await AddServerAsync(true, EConfigType.Shadowsocks);
2023-01-01 11:42:01 +00:00
});
AddSocksServerCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await AddServerAsync(true, EConfigType.SOCKS);
2023-01-01 11:42:01 +00:00
});
AddHttpServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
await AddServerAsync(true, EConfigType.HTTP);
});
AddTrojanServerCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await AddServerAsync(true, EConfigType.Trojan);
2023-01-01 11:42:01 +00:00
});
AddHysteria2ServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
await AddServerAsync(true, EConfigType.Hysteria2);
});
AddTuicServerCmd = ReactiveCommand.CreateFromTask(async () =>
2023-12-19 08:03:30 +00:00
{
await AddServerAsync(true, EConfigType.TUIC);
2023-12-19 08:03:30 +00:00
});
AddWireguardServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
await AddServerAsync(true, EConfigType.WireGuard);
});
AddCustomServerCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await AddServerAsync(true, EConfigType.Custom);
2023-01-01 11:42:01 +00:00
});
AddServerViaClipboardCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await AddServerViaClipboardAsync(null);
2023-01-01 11:42:01 +00:00
});
2024-08-22 11:51:10 +00:00
AddServerViaScanCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
2024-10-12 07:45:21 +00:00
await AddServerViaScanTaskAsync();
2023-01-01 11:42:01 +00:00
});
//Subscription
SubSettingCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await SubSettingAsync();
2023-01-01 11:42:01 +00:00
});
2024-07-18 09:39:11 +00:00
SubUpdateCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await UpdateSubscriptionProcess("", false);
2023-01-01 11:42:01 +00:00
});
SubUpdateViaProxyCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await UpdateSubscriptionProcess("", true);
2023-01-01 11:42:01 +00:00
});
SubGroupUpdateCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await UpdateSubscriptionProcess(_config.subIndexId, false);
2023-01-01 11:42:01 +00:00
});
SubGroupUpdateViaProxyCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await UpdateSubscriptionProcess(_config.subIndexId, true);
2023-01-01 11:42:01 +00:00
});
//Setting
OptionSettingCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await OptionSettingAsync();
2023-01-01 11:42:01 +00:00
});
RoutingSettingCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await RoutingSettingAsync();
2023-01-01 11:42:01 +00:00
});
DNSSettingCmd = ReactiveCommand.CreateFromTask(async () =>
{
await DNSSettingAsync();
});
2024-08-22 11:51:10 +00:00
GlobalHotkeySettingCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
2024-08-22 11:51:10 +00:00
if (await _updateView?.Invoke(EViewAction.GlobalHotkeySettingWindow, null) == true)
2023-01-01 11:42:01 +00:00
{
2024-10-07 02:59:13 +00:00
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
2023-01-01 11:42:01 +00:00
}
});
RebootAsAdminCmd = ReactiveCommand.CreateFromTask(async () =>
2023-04-06 02:44:29 +00:00
{
await RebootAsAdmin();
2023-04-06 02:44:29 +00:00
});
ClearServerStatisticsCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await ClearServerStatistics();
2023-01-01 11:42:01 +00:00
});
OpenTheFileLocationCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await OpenTheFileLocation();
2023-01-01 11:42:01 +00:00
});
ReloadCmd = ReactiveCommand.CreateFromTask(async () =>
2023-01-01 11:42:01 +00:00
{
await Reload();
2023-01-01 11:42:01 +00:00
});
PresetDefaultCmd = ReactiveCommand.CreateFromTask(async () =>
{
await ApplyPreset(EPresetType.Default);
});
PresetRussiaCmd = ReactiveCommand.CreateFromTask(async () =>
{
await ApplyPreset(EPresetType.Russia);
});
2024-02-01 04:44:47 +00:00
#endregion WhenAnyValue && ReactiveCommand
AutoHideStartup();
2023-01-01 11:42:01 +00:00
}
private void Init()
{
ConfigHandler.InitRouting(_config);
ConfigHandler.InitBuiltinDNS(_config);
2024-10-07 03:18:24 +00:00
CoreHandler.Instance.Init(_config, UpdateHandler);
2024-10-12 07:45:21 +00:00
TaskHandler.Instance.RegUpdateTask(_config, UpdateTaskHandler);
2023-01-01 11:42:01 +00:00
2023-02-10 06:36:37 +00:00
if (_config.guiItem.enableStatistics)
2023-01-01 11:42:01 +00:00
{
2024-07-18 09:39:11 +00:00
StatisticsHandler.Instance.Init(_config, UpdateStatisticsHandler);
2023-01-01 11:42:01 +00:00
}
Reload();
}
2023-04-14 12:49:36 +00:00
#endregion Init
2023-01-01 11:42:01 +00:00
#region Actions
2023-04-14 12:49:36 +00:00
2023-01-01 11:42:01 +00:00
private void UpdateHandler(bool notify, string msg)
{
2024-10-07 02:59:13 +00:00
NoticeHandler.Instance.SendMessage(msg);
2024-03-07 03:51:45 +00:00
if (notify)
{
2024-10-07 02:59:13 +00:00
NoticeHandler.Instance.Enqueue(msg);
2024-03-07 03:51:45 +00:00
}
2023-01-01 11:42:01 +00:00
}
2023-04-14 12:49:36 +00:00
2023-02-19 04:18:08 +00:00
private void UpdateTaskHandler(bool success, string msg)
2023-01-01 11:42:01 +00:00
{
2024-10-07 02:59:13 +00:00
NoticeHandler.Instance.SendMessageEx(msg);
2023-01-01 11:42:01 +00:00
if (success)
{
2023-02-28 12:23:15 +00:00
var indexIdOld = _config.indexId;
2023-02-04 10:52:17 +00:00
RefreshServers();
2023-02-28 12:23:15 +00:00
if (indexIdOld != _config.indexId)
{
Reload();
}
if (_config.uiItem.enableAutoAdjustMainLvColWidth)
{
2024-08-30 04:59:43 +00:00
_updateView?.Invoke(EViewAction.AdjustMainLvColWidth, null);
}
2023-01-01 11:42:01 +00:00
}
}
2023-04-14 12:49:36 +00:00
2023-01-01 11:42:01 +00:00
private void UpdateStatisticsHandler(ServerSpeedItem update)
{
if (!_config.uiItem.showInTaskbar)
{
return;
}
_updateView?.Invoke(EViewAction.DispatcherStatistics, update);
}
public void SetStatisticsResult(ServerSpeedItem update)
2023-01-01 11:42:01 +00:00
{
try
{
2024-10-12 07:45:21 +00:00
Locator.Current.GetService<StatusBarViewModel>()?.UpdateStatistics(update);
if ((update.proxyUp + update.proxyDown) > 0 && DateTime.Now.Second % 3 == 0)
2024-07-18 09:39:11 +00:00
{
Locator.Current.GetService<ProfilesViewModel>()?.UpdateStatistics(update);
}
2023-01-01 11:42:01 +00:00
}
catch (Exception ex)
{
2024-01-10 02:43:48 +00:00
Logging.SaveLog(ex.Message, ex);
2023-01-01 11:42:01 +00:00
}
}
2023-04-14 12:49:36 +00:00
2024-08-22 11:51:10 +00:00
public async Task MyAppExitAsync(bool blWindowsShutDown)
2023-01-01 11:42:01 +00:00
{
try
{
2024-01-10 02:43:48 +00:00
Logging.SaveLog("MyAppExit Begin");
2024-08-20 06:15:29 +00:00
//if (blWindowsShutDown)
2024-10-16 01:20:05 +00:00
await SysProxyHandler.UpdateSysProxy(_config, true);
2023-01-01 11:42:01 +00:00
2023-12-22 08:03:25 +00:00
ConfigHandler.SaveConfig(_config);
ProfileExHandler.Instance.SaveTo();
2024-07-18 09:39:11 +00:00
StatisticsHandler.Instance.SaveTo();
StatisticsHandler.Instance.Close();
2024-10-07 03:18:24 +00:00
CoreHandler.Instance.CoreStop();
2024-08-20 06:15:29 +00:00
2024-01-10 02:43:48 +00:00
Logging.SaveLog("MyAppExit End");
2023-01-01 11:42:01 +00:00
}
catch { }
finally
{
2024-10-08 06:55:06 +00:00
_updateView?.Invoke(EViewAction.Shutdown, null);
2023-01-01 11:42:01 +00:00
}
}
public async Task UpgradeApp(string arg)
2024-09-06 10:37:46 +00:00
{
if (!Utils.UpgradeAppExists(out var fileName))
{
NoticeHandler.Instance.SendMessageAndEnqueue(ResUI.UpgradeAppNotExistTip);
Logging.SaveLog("UpgradeApp does not exist");
return;
}
2024-09-06 10:37:46 +00:00
Process process = new()
{
StartInfo = new ProcessStartInfo
{
FileName = fileName,
Arguments = arg.AppendQuotes(),
2024-09-06 10:37:46 +00:00
WorkingDirectory = Utils.StartupPath()
}
};
process.Start();
if (process.Id > 0)
{
await MyAppExitAsync(false);
}
}
2024-10-12 07:45:21 +00:00
public void ShowHideWindow(bool? blShow)
{
_updateView?.Invoke(EViewAction.ShowHideWindow, blShow);
}
2023-04-14 12:49:36 +00:00
#endregion Actions
2023-01-01 11:42:01 +00:00
#region Servers && Groups
2024-07-18 09:39:11 +00:00
private void RefreshServers()
2023-01-01 11:42:01 +00:00
{
2024-10-11 02:17:44 +00:00
MessageBus.Current.SendMessage("", EMsgCommand.RefreshProfiles.ToString());
2023-01-01 11:42:01 +00:00
}
2024-07-18 09:39:11 +00:00
private void RefreshSubscriptions()
2023-01-01 11:42:01 +00:00
{
2024-07-18 09:39:11 +00:00
Locator.Current.GetService<ProfilesViewModel>()?.RefreshSubscriptions();
2023-01-01 11:42:01 +00:00
}
2023-04-14 12:49:36 +00:00
#endregion Servers && Groups
2023-01-01 11:42:01 +00:00
#region Add Servers
2023-04-14 12:49:36 +00:00
2024-08-22 11:51:10 +00:00
public async Task AddServerAsync(bool blNew, EConfigType eConfigType)
2023-01-01 11:42:01 +00:00
{
2024-07-18 09:39:11 +00:00
ProfileItem item = new()
2023-01-01 11:42:01 +00:00
{
2024-07-18 09:39:11 +00:00
subid = _config.subIndexId,
configType = eConfigType,
isSub = false,
};
2023-01-01 11:42:01 +00:00
bool? ret = false;
if (eConfigType == EConfigType.Custom)
{
2024-08-22 11:51:10 +00:00
ret = await _updateView?.Invoke(EViewAction.AddServer2Window, item);
2023-01-01 11:42:01 +00:00
}
else
{
2024-08-22 11:51:10 +00:00
ret = await _updateView?.Invoke(EViewAction.AddServerWindow, item);
2023-01-01 11:42:01 +00:00
}
if (ret == true)
{
RefreshServers();
if (item.indexId == _config.indexId)
{
Reload();
}
}
}
2024-08-22 11:51:10 +00:00
public async Task AddServerViaClipboardAsync(string? clipboardData)
2023-01-01 11:42:01 +00:00
{
2024-08-20 06:15:29 +00:00
if (clipboardData == null)
{
2024-08-22 11:51:10 +00:00
await _updateView?.Invoke(EViewAction.AddServerViaClipboard, null);
2024-08-20 06:15:29 +00:00
return;
}
int ret = ConfigHandler.AddBatchServers(_config, clipboardData, _config.subIndexId, false);
2023-01-01 11:42:01 +00:00
if (ret > 0)
{
2024-07-18 09:39:11 +00:00
RefreshSubscriptions();
2023-01-01 11:42:01 +00:00
RefreshServers();
2024-10-07 02:59:13 +00:00
NoticeHandler.Instance.Enqueue(string.Format(ResUI.SuccessfullyImportedServerViaClipboard, ret));
2023-01-01 11:42:01 +00:00
}
}
2023-04-14 12:49:36 +00:00
2024-10-12 07:45:21 +00:00
public async Task AddServerViaScanTaskAsync()
{
_updateView?.Invoke(EViewAction.ScanScreenTask, null);
}
public void ScanScreenResult(string result)
2023-01-01 11:42:01 +00:00
{
2024-03-26 06:26:03 +00:00
if (Utils.IsNullOrEmpty(result))
2023-01-01 11:42:01 +00:00
{
2024-10-07 02:59:13 +00:00
NoticeHandler.Instance.Enqueue(ResUI.NoValidQRcodeFound);
2023-01-01 11:42:01 +00:00
}
else
{
2024-07-18 09:39:11 +00:00
int ret = ConfigHandler.AddBatchServers(_config, result, _config.subIndexId, false);
2023-01-01 11:42:01 +00:00
if (ret > 0)
{
2024-07-18 09:39:11 +00:00
RefreshSubscriptions();
2023-01-01 11:42:01 +00:00
RefreshServers();
2024-10-07 02:59:13 +00:00
NoticeHandler.Instance.Enqueue(ResUI.SuccessfullyImportedServerViaScan);
2023-01-01 11:42:01 +00:00
}
}
}
2023-04-14 12:49:36 +00:00
#endregion Add Servers
2023-01-01 11:42:01 +00:00
#region Subscription
2024-08-22 11:51:10 +00:00
private async Task SubSettingAsync()
2023-01-01 11:42:01 +00:00
{
2024-08-22 11:51:10 +00:00
if (await _updateView?.Invoke(EViewAction.SubSettingWindow, null) == true)
2023-01-01 11:42:01 +00:00
{
2024-07-18 09:39:11 +00:00
RefreshSubscriptions();
2023-01-01 11:42:01 +00:00
}
}
public async Task UpdateSubscriptionProcess(string subId, bool blProxy)
2023-02-08 11:20:44 +00:00
{
2024-10-07 02:39:43 +00:00
(new UpdateService()).UpdateSubscriptionProcess(_config, subId, blProxy, UpdateTaskHandler);
2023-01-01 11:42:01 +00:00
}
2023-04-14 12:49:36 +00:00
#endregion Subscription
2023-01-01 11:42:01 +00:00
#region Setting
2024-08-22 11:51:10 +00:00
private async Task OptionSettingAsync()
2023-01-01 11:42:01 +00:00
{
2024-08-22 11:51:10 +00:00
var ret = await _updateView?.Invoke(EViewAction.OptionSettingWindow, null);
2023-01-01 11:42:01 +00:00
if (ret == true)
{
Locator.Current.GetService<StatusBarViewModel>()?.InboundDisplayStatus();
2023-01-01 11:42:01 +00:00
Reload();
}
}
2023-04-14 12:49:36 +00:00
2024-08-22 11:51:10 +00:00
private async Task RoutingSettingAsync()
2023-01-01 11:42:01 +00:00
{
2024-08-22 11:51:10 +00:00
var ret = await _updateView?.Invoke(EViewAction.RoutingSettingWindow, null);
2023-01-01 11:42:01 +00:00
if (ret == true)
{
ConfigHandler.InitRouting(_config);
2024-10-12 07:45:21 +00:00
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
2023-01-01 11:42:01 +00:00
Reload();
}
}
2023-04-27 08:20:13 +00:00
2024-08-22 11:51:10 +00:00
private async Task DNSSettingAsync()
{
2024-08-22 11:51:10 +00:00
var ret = await _updateView?.Invoke(EViewAction.DNSSettingWindow, null);
if (ret == true)
{
Reload();
}
}
2023-01-01 11:42:01 +00:00
2024-10-12 07:45:21 +00:00
public async Task RebootAsAdmin()
2023-04-06 02:44:29 +00:00
{
try
{
2024-10-12 07:45:21 +00:00
ProcessStartInfo startInfo = new()
{
UseShellExecute = true,
Arguments = Global.RebootAs,
WorkingDirectory = Utils.StartupPath(),
FileName = Utils.GetExePath().AppendQuotes(),
Verb = "runas",
};
2023-04-06 02:44:29 +00:00
Process.Start(startInfo);
2024-10-12 07:45:21 +00:00
await MyAppExitAsync(false);
}
catch { }
2023-04-06 02:44:29 +00:00
}
private async Task ClearServerStatistics()
{
StatisticsHandler.Instance.ClearAllServerStatistics();
RefreshServers();
}
private async Task OpenTheFileLocation()
{
if (Utils.IsWindows())
{
Utils.ProcessStart("Explorer", $"/select,{Utils.GetConfigPath()}");
}
else if (Utils.IsLinux())
{
Utils.ProcessStart("nautilus", Utils.GetConfigPath());
}
}
2023-04-14 12:49:36 +00:00
#endregion Setting
2023-01-01 11:42:01 +00:00
2024-03-07 01:06:35 +00:00
#region core job
2023-01-01 11:42:01 +00:00
public async Task Reload()
2023-01-01 11:42:01 +00:00
{
2024-01-30 09:18:00 +00:00
BlReloadEnabled = false;
await LoadCore();
2024-10-12 07:45:21 +00:00
Locator.Current.GetService<StatusBarViewModel>()?.TestServerAvailability();
2024-10-16 01:20:05 +00:00
await SysProxyHandler.UpdateSysProxy(_config, false);
_updateView?.Invoke(EViewAction.DispatcherReload, null);
2023-01-01 11:42:01 +00:00
}
public void ReloadResult()
{
2024-10-16 01:20:05 +00:00
//Locator.Current.GetService<StatusBarViewModel>()?.ChangeSystemProxyAsync(_config.systemProxyItem.sysProxyType, false);
BlReloadEnabled = true;
2024-10-05 09:51:31 +00:00
ShowClashUI = _config.IsRunningCore(ECoreType.sing_box);
if (ShowClashUI)
{
Locator.Current.GetService<ClashProxiesViewModel>()?.ProxiesReload();
}
else { TabMainSelectedIndex = 0; }
}
2024-03-07 01:06:35 +00:00
private async Task LoadCore()
2023-01-01 11:42:01 +00:00
{
await Task.Run(() =>
{
2024-08-20 06:15:29 +00:00
//if (_config.tunModeItem.enableTun)
//{
// Task.Delay(1000).Wait();
// WindowsUtils.RemoveTunDevice();
//}
var node = ConfigHandler.GetDefaultServer(_config);
2024-10-07 03:18:24 +00:00
CoreHandler.Instance.LoadCore(node);
2024-06-28 02:41:17 +00:00
});
2023-01-01 11:42:01 +00:00
}
2024-09-01 08:39:45 +00:00
public void CloseCore()
2023-01-01 11:42:01 +00:00
{
2023-12-22 08:03:25 +00:00
ConfigHandler.SaveConfig(_config, false);
2024-10-07 03:18:24 +00:00
CoreHandler.Instance.CoreStop();
2023-01-01 11:42:01 +00:00
}
private void AutoHideStartup()
{
if (_config.uiItem.autoHideStartup)
2023-01-01 11:42:01 +00:00
{
Observable.Range(1, 1)
2024-10-12 07:45:21 +00:00
.Delay(TimeSpan.FromSeconds(1))
.Subscribe(async x =>
{
ShowHideWindow(false);
});
2023-01-01 11:42:01 +00:00
}
}
2024-10-12 07:45:21 +00:00
#endregion core job
#region Presets
public async Task ApplyPreset(EPresetType type)
{
ConfigHandler.ApplyPreset(_config, type);
await new UpdateService().UpdateGeoFileAll(_config, UpdateHandler);
ConfigHandler.InitRouting(_config);
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
ConfigHandler.SaveConfig(_config, false);
Reload();
}
#endregion
2023-01-01 11:42:01 +00:00
}
2024-07-25 02:26:39 +00:00
}