Refactor NoticeHandler

pull/5829/head
2dust 2024-10-07 10:59:13 +08:00
parent d5c6a42a9a
commit 4ccc7aa92d
37 changed files with 115 additions and 150 deletions

View File

@ -6,6 +6,5 @@ namespace ServiceLib.Base
{ {
protected static Config? _config; protected static Config? _config;
protected Func<EViewAction, object?, Task<bool>>? _updateView; protected Func<EViewAction, object?, Task<bool>>? _updateView;
protected NoticeHandler? _noticeHandler;
} }
} }

View File

@ -4,11 +4,14 @@
{ {
v2fly = 1, v2fly = 1,
Xray = 2, Xray = 2,
//SagerNet = 3, //SagerNet = 3,
v2fly_v5 = 4, v2fly_v5 = 4,
//clash = 11, //clash = 11,
//clash_meta = 12, //clash_meta = 12,
mihomo = 13, mihomo = 13,
hysteria = 21, hysteria = 21,
naiveproxy = 22, naiveproxy = 22,
tuic = 23, tuic = 23,

View File

@ -1,6 +1,4 @@
using Splat; namespace ServiceLib.Handler
namespace ServiceLib.Handler
{ {
public sealed class AppHandler public sealed class AppHandler
{ {
@ -33,7 +31,7 @@ namespace ServiceLib.Handler
#region Init #region Init
public AppHandler() public AppHandler()
{ {
} }
public bool InitApp() public bool InitApp()
@ -42,7 +40,6 @@ namespace ServiceLib.Handler
{ {
return false; return false;
} }
Locator.CurrentMutable.RegisterLazySingleton(() => new NoticeHandler(), typeof(NoticeHandler));
Thread.CurrentThread.CurrentUICulture = new(_config.uiItem.currentLanguage); Thread.CurrentThread.CurrentUICulture = new(_config.uiItem.currentLanguage);
//Under Win10 //Under Win10

View File

@ -1,6 +1,4 @@
using ServiceLib.Services.CoreConfig; namespace ServiceLib.Handler
namespace ServiceLib.Handler
{ {
/// <summary> /// <summary>
/// Core configuration file processing class /// Core configuration file processing class

View File

@ -4,6 +4,9 @@ namespace ServiceLib.Handler
{ {
public class NoticeHandler public class NoticeHandler
{ {
private static readonly Lazy<NoticeHandler> _instance = new(() => new());
public static NoticeHandler Instance => _instance.Value;
public void Enqueue(string? content) public void Enqueue(string? content)
{ {
if (content.IsNullOrEmpty()) if (content.IsNullOrEmpty())

View File

@ -1,6 +1,4 @@
using ServiceLib.Services.Statistics; namespace ServiceLib.Handler
namespace ServiceLib.Handler
{ {
public class StatisticsHandler public class StatisticsHandler
{ {

View File

@ -1,6 +1,4 @@
using ServiceLib.Services; namespace ServiceLib.Handler
namespace ServiceLib.Handler
{ {
public class TaskHandler public class TaskHandler
{ {

View File

@ -110,7 +110,7 @@ namespace ServiceLib.Handler
} }
else else
{ {
SaveLog(result.Description); SaveLog(result.Description);
} }
} }
catch (Exception ex) catch (Exception ex)

View File

@ -1,6 +1,5 @@
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Splat;
using System.Reactive; using System.Reactive;
namespace ServiceLib.ViewModels namespace ServiceLib.ViewModels
@ -20,7 +19,6 @@ 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>();
_config = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_updateView = updateView; _updateView = updateView;
@ -55,25 +53,25 @@ namespace ServiceLib.ViewModels
string remarks = SelectedSource.remarks; string remarks = SelectedSource.remarks;
if (Utils.IsNullOrEmpty(remarks)) if (Utils.IsNullOrEmpty(remarks))
{ {
_noticeHandler?.Enqueue(ResUI.PleaseFillRemarks); NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
return; return;
} }
if (Utils.IsNullOrEmpty(SelectedSource.address)) if (Utils.IsNullOrEmpty(SelectedSource.address))
{ {
_noticeHandler?.Enqueue(ResUI.FillServerAddressCustom); NoticeHandler.Instance.Enqueue(ResUI.FillServerAddressCustom);
return; return;
} }
SelectedSource.coreType = CoreType.IsNullOrEmpty() ? null : (ECoreType)Enum.Parse(typeof(ECoreType), CoreType); SelectedSource.coreType = CoreType.IsNullOrEmpty() ? null : (ECoreType)Enum.Parse(typeof(ECoreType), CoreType);
if (ConfigHandler.EditCustomServer(_config, SelectedSource) == 0) if (ConfigHandler.EditCustomServer(_config, SelectedSource) == 0)
{ {
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
await _updateView?.Invoke(EViewAction.CloseWindow, null); await _updateView?.Invoke(EViewAction.CloseWindow, null);
} }
else else
{ {
_noticeHandler?.Enqueue(ResUI.OperationFailed); NoticeHandler.Instance.Enqueue(ResUI.OperationFailed);
} }
} }
@ -89,7 +87,7 @@ namespace ServiceLib.ViewModels
item.address = fileName; item.address = fileName;
if (ConfigHandler.AddCustomServer(_config, item, false) == 0) if (ConfigHandler.AddCustomServer(_config, item, false) == 0)
{ {
_noticeHandler?.Enqueue(ResUI.SuccessfullyImportedCustomServer); NoticeHandler.Instance.Enqueue(ResUI.SuccessfullyImportedCustomServer);
if (Utils.IsNotEmpty(item.indexId)) if (Utils.IsNotEmpty(item.indexId))
{ {
SelectedSource = JsonUtils.DeepCopy(item); SelectedSource = JsonUtils.DeepCopy(item);
@ -98,7 +96,7 @@ namespace ServiceLib.ViewModels
} }
else else
{ {
_noticeHandler?.Enqueue(ResUI.FailedImportedCustomServer); NoticeHandler.Instance.Enqueue(ResUI.FailedImportedCustomServer);
} }
} }
@ -107,7 +105,7 @@ namespace ServiceLib.ViewModels
var address = SelectedSource.address; var address = SelectedSource.address;
if (Utils.IsNullOrEmpty(address)) if (Utils.IsNullOrEmpty(address))
{ {
_noticeHandler?.Enqueue(ResUI.FillServerAddressCustom); NoticeHandler.Instance.Enqueue(ResUI.FillServerAddressCustom);
return; return;
} }
@ -118,7 +116,7 @@ namespace ServiceLib.ViewModels
} }
else else
{ {
_noticeHandler?.Enqueue(ResUI.FailedReadConfiguration); NoticeHandler.Instance.Enqueue(ResUI.FailedReadConfiguration);
} }
} }
} }

View File

@ -1,6 +1,5 @@
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Splat;
using System.Reactive; using System.Reactive;
namespace ServiceLib.ViewModels namespace ServiceLib.ViewModels
@ -18,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 = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
if (profileItem.indexId.IsNullOrEmpty()) if (profileItem.indexId.IsNullOrEmpty())
@ -45,32 +44,32 @@ namespace ServiceLib.ViewModels
{ {
if (Utils.IsNullOrEmpty(SelectedSource.remarks)) if (Utils.IsNullOrEmpty(SelectedSource.remarks))
{ {
_noticeHandler?.Enqueue(ResUI.PleaseFillRemarks); NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
return; return;
} }
if (Utils.IsNullOrEmpty(SelectedSource.address)) if (Utils.IsNullOrEmpty(SelectedSource.address))
{ {
_noticeHandler?.Enqueue(ResUI.FillServerAddress); NoticeHandler.Instance.Enqueue(ResUI.FillServerAddress);
return; return;
} }
var port = SelectedSource.port.ToString(); var port = SelectedSource.port.ToString();
if (Utils.IsNullOrEmpty(port) || !Utils.IsNumeric(port) if (Utils.IsNullOrEmpty(port) || !Utils.IsNumeric(port)
|| SelectedSource.port <= 0 || SelectedSource.port >= Global.MaxPort) || SelectedSource.port <= 0 || SelectedSource.port >= Global.MaxPort)
{ {
_noticeHandler?.Enqueue(ResUI.FillCorrectServerPort); NoticeHandler.Instance.Enqueue(ResUI.FillCorrectServerPort);
return; return;
} }
if (SelectedSource.configType == EConfigType.Shadowsocks) if (SelectedSource.configType == EConfigType.Shadowsocks)
{ {
if (Utils.IsNullOrEmpty(SelectedSource.id)) if (Utils.IsNullOrEmpty(SelectedSource.id))
{ {
_noticeHandler?.Enqueue(ResUI.FillPassword); NoticeHandler.Instance.Enqueue(ResUI.FillPassword);
return; return;
} }
if (Utils.IsNullOrEmpty(SelectedSource.security)) if (Utils.IsNullOrEmpty(SelectedSource.security))
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectEncryption); NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectEncryption);
return; return;
} }
} }
@ -79,7 +78,7 @@ namespace ServiceLib.ViewModels
{ {
if (Utils.IsNullOrEmpty(SelectedSource.id)) if (Utils.IsNullOrEmpty(SelectedSource.id))
{ {
_noticeHandler?.Enqueue(ResUI.FillUUID); NoticeHandler.Instance.Enqueue(ResUI.FillUUID);
return; return;
} }
} }
@ -87,12 +86,12 @@ namespace ServiceLib.ViewModels
if (ConfigHandler.AddServer(_config, SelectedSource) == 0) if (ConfigHandler.AddServer(_config, SelectedSource) == 0)
{ {
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
await _updateView?.Invoke(EViewAction.CloseWindow, null); await _updateView?.Invoke(EViewAction.CloseWindow, null);
} }
else else
{ {
_noticeHandler?.Enqueue(ResUI.OperationFailed); NoticeHandler.Instance.Enqueue(ResUI.OperationFailed);
} }
} }
} }

View File

@ -24,7 +24,6 @@ namespace ServiceLib.ViewModels
{ {
_config = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_updateView = updateView; _updateView = updateView;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
WebDavCheckCmd = ReactiveCommand.CreateFromTask(async () => WebDavCheckCmd = ReactiveCommand.CreateFromTask(async () =>
{ {

View File

@ -24,7 +24,6 @@ namespace ServiceLib.ViewModels
{ {
_config = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_updateView = updateView; _updateView = updateView;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
RefreshSubItems(); RefreshSubItems();

View File

@ -2,7 +2,6 @@ using DynamicData;
using DynamicData.Binding; using DynamicData.Binding;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Splat;
using System.Reactive; using System.Reactive;
using System.Reactive.Linq; using System.Reactive.Linq;
using static ServiceLib.Models.ClashProviders; using static ServiceLib.Models.ClashProviders;
@ -44,7 +43,6 @@ namespace ServiceLib.ViewModels
public ClashProxiesViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public ClashProxiesViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_config = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_updateView = updateView; _updateView = updateView;
@ -135,7 +133,7 @@ namespace ServiceLib.ViewModels
private void UpdateHandler(bool notify, string msg) private void UpdateHandler(bool notify, string msg)
{ {
_noticeHandler?.SendMessageEx(msg); NoticeHandler.Instance.SendMessageEx(msg);
} }
public void ProxiesReload() public void ProxiesReload()
@ -363,7 +361,7 @@ namespace ServiceLib.ViewModels
var selectedProxy = TryGetProxy(name); var selectedProxy = TryGetProxy(name);
if (selectedProxy == null || selectedProxy.type != "Selector") if (selectedProxy == null || selectedProxy.type != "Selector")
{ {
_noticeHandler?.Enqueue(ResUI.OperationFailed); NoticeHandler.Instance.Enqueue(ResUI.OperationFailed);
return; return;
} }
@ -379,7 +377,7 @@ namespace ServiceLib.ViewModels
SelectedGroup = group2; SelectedGroup = group2;
} }
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
} }
private void ProxiesDelayTest(bool blAll) private void ProxiesDelayTest(bool blAll)

View File

@ -1,6 +1,5 @@
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Splat;
using System.Reactive; using System.Reactive;
namespace ServiceLib.ViewModels namespace ServiceLib.ViewModels
@ -24,7 +23,7 @@ namespace ServiceLib.ViewModels
public DNSSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public DNSSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
var item = AppHandler.Instance.GetDNSItem(ECoreType.Xray); var item = AppHandler.Instance.GetDNSItem(ECoreType.Xray);
@ -68,7 +67,7 @@ namespace ServiceLib.ViewModels
{ {
if (normalDNS.Contains("{") || normalDNS.Contains("}")) if (normalDNS.Contains("{") || normalDNS.Contains("}"))
{ {
_noticeHandler?.Enqueue(ResUI.FillCorrectDNSText); NoticeHandler.Instance.Enqueue(ResUI.FillCorrectDNSText);
return; return;
} }
} }
@ -78,7 +77,7 @@ namespace ServiceLib.ViewModels
var obj2 = JsonUtils.Deserialize<Dns4Sbox>(normalDNS2); var obj2 = JsonUtils.Deserialize<Dns4Sbox>(normalDNS2);
if (obj2 == null) if (obj2 == null)
{ {
_noticeHandler?.Enqueue(ResUI.FillCorrectDNSText); NoticeHandler.Instance.Enqueue(ResUI.FillCorrectDNSText);
return; return;
} }
} }
@ -87,7 +86,7 @@ namespace ServiceLib.ViewModels
var obj2 = JsonUtils.Deserialize<Dns4Sbox>(tunDNS2); var obj2 = JsonUtils.Deserialize<Dns4Sbox>(tunDNS2);
if (obj2 == null) if (obj2 == null)
{ {
_noticeHandler?.Enqueue(ResUI.FillCorrectDNSText); NoticeHandler.Instance.Enqueue(ResUI.FillCorrectDNSText);
return; return;
} }
} }
@ -106,7 +105,7 @@ namespace ServiceLib.ViewModels
item2.tunDNS = JsonUtils.Serialize(JsonUtils.ParseJson(tunDNS2)); ; item2.tunDNS = JsonUtils.Serialize(JsonUtils.ParseJson(tunDNS2)); ;
ConfigHandler.SaveDNSItems(_config, item2); ConfigHandler.SaveDNSItems(_config, item2);
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
await _updateView?.Invoke(EViewAction.CloseWindow, null); await _updateView?.Invoke(EViewAction.CloseWindow, null);
} }
} }

View File

@ -147,7 +147,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 = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
_isAdministrator = isAdministrator; _isAdministrator = isAdministrator;
@ -281,7 +281,7 @@ namespace ServiceLib.ViewModels
{ {
if (await _updateView?.Invoke(EViewAction.GlobalHotkeySettingWindow, null) == true) if (await _updateView?.Invoke(EViewAction.GlobalHotkeySettingWindow, null) == true)
{ {
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
} }
}); });
RebootAsAdminCmd = ReactiveCommand.Create(() => RebootAsAdminCmd = ReactiveCommand.Create(() =>
@ -364,16 +364,16 @@ namespace ServiceLib.ViewModels
private void UpdateHandler(bool notify, string msg) private void UpdateHandler(bool notify, string msg)
{ {
_noticeHandler?.SendMessage(msg); NoticeHandler.Instance.SendMessage(msg);
if (notify) if (notify)
{ {
_noticeHandler?.Enqueue(msg); NoticeHandler.Instance.Enqueue(msg);
} }
} }
private void UpdateTaskHandler(bool success, string msg) private void UpdateTaskHandler(bool success, string msg)
{ {
_noticeHandler?.SendMessageEx(msg); NoticeHandler.Instance.SendMessageEx(msg);
if (success) if (success)
{ {
var indexIdOld = _config.indexId; var indexIdOld = _config.indexId;
@ -559,7 +559,7 @@ namespace ServiceLib.ViewModels
{ {
RefreshSubscriptions(); RefreshSubscriptions();
RefreshServers(); RefreshServers();
_noticeHandler?.Enqueue(string.Format(ResUI.SuccessfullyImportedServerViaClipboard, ret)); NoticeHandler.Instance.Enqueue(string.Format(ResUI.SuccessfullyImportedServerViaClipboard, ret));
} }
} }
@ -567,7 +567,7 @@ namespace ServiceLib.ViewModels
{ {
if (Utils.IsNullOrEmpty(result)) if (Utils.IsNullOrEmpty(result))
{ {
_noticeHandler?.Enqueue(ResUI.NoValidQRcodeFound); NoticeHandler.Instance.Enqueue(ResUI.NoValidQRcodeFound);
} }
else else
{ {
@ -576,7 +576,7 @@ namespace ServiceLib.ViewModels
{ {
RefreshSubscriptions(); RefreshSubscriptions();
RefreshServers(); RefreshServers();
_noticeHandler?.Enqueue(ResUI.SuccessfullyImportedServerViaScan); NoticeHandler.Instance.Enqueue(ResUI.SuccessfullyImportedServerViaScan);
} }
} }
} }
@ -594,7 +594,7 @@ namespace ServiceLib.ViewModels
var item = AppHandler.Instance.GetProfileItem(indexId); var item = AppHandler.Instance.GetProfileItem(indexId);
if (item is null) if (item is null)
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer); NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectServer);
return; return;
} }
@ -631,7 +631,7 @@ namespace ServiceLib.ViewModels
} }
await (new UpdateService()).RunAvailabilityCheck(async (bool success, string msg) => await (new UpdateService()).RunAvailabilityCheck(async (bool success, string msg) =>
{ {
_noticeHandler?.SendMessageEx(msg); NoticeHandler.Instance.SendMessageEx(msg);
await _updateView?.Invoke(EViewAction.DispatcherServerAvailability, msg); await _updateView?.Invoke(EViewAction.DispatcherServerAvailability, msg);
}); });
} }
@ -784,7 +784,7 @@ namespace ServiceLib.ViewModels
{ {
//await _updateView?.Invoke(EViewAction.UpdateSysProxy, _config.tunModeItem.enableTun ? true : false); //await _updateView?.Invoke(EViewAction.UpdateSysProxy, _config.tunModeItem.enableTun ? true : false);
await _updateView?.Invoke(EViewAction.UpdateSysProxy, false); await _updateView?.Invoke(EViewAction.UpdateSysProxy, false);
_noticeHandler?.SendMessageEx($"{ResUI.TipChangeSystemProxy} - {_config.systemProxyItem.sysProxyType.ToString()}"); NoticeHandler.Instance.SendMessageEx($"{ResUI.TipChangeSystemProxy} - {_config.systemProxyItem.sysProxyType.ToString()}");
BlSystemProxyClear = (type == ESysProxyType.ForcedClear); BlSystemProxyClear = (type == ESysProxyType.ForcedClear);
BlSystemProxySet = (type == ESysProxyType.ForcedChange); BlSystemProxySet = (type == ESysProxyType.ForcedChange);
@ -844,7 +844,7 @@ namespace ServiceLib.ViewModels
if (ConfigHandler.SetDefaultRouting(_config, item) == 0) if (ConfigHandler.SetDefaultRouting(_config, item) == 0)
{ {
_noticeHandler?.SendMessageEx(ResUI.TipChangeRouting); NoticeHandler.Instance.SendMessageEx(ResUI.TipChangeRouting);
Reload(); Reload();
await _updateView?.Invoke(EViewAction.DispatcherRefreshIcon, null); await _updateView?.Invoke(EViewAction.DispatcherRefreshIcon, null);
} }

View File

@ -1,6 +1,5 @@
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Splat;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@ -24,7 +23,6 @@ namespace ServiceLib.ViewModels
{ {
_config = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_updateView = updateView; _updateView = updateView;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
MessageBus.Current.Listen<string>(Global.CommandSendMsgView).Subscribe(async x => await AppendQueueMsg(x)); MessageBus.Current.Listen<string>(Global.CommandSendMsgView).Subscribe(async x => await AppendQueueMsg(x));

View File

@ -1,6 +1,5 @@
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Splat;
using System.Reactive; using System.Reactive;
namespace ServiceLib.ViewModels namespace ServiceLib.ViewModels
@ -103,7 +102,7 @@ namespace ServiceLib.ViewModels
public OptionSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public OptionSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
#region Core #region Core
@ -251,7 +250,7 @@ namespace ServiceLib.ViewModels
if (Utils.IsNullOrEmpty(localPort.ToString()) || !Utils.IsNumeric(localPort.ToString()) if (Utils.IsNullOrEmpty(localPort.ToString()) || !Utils.IsNumeric(localPort.ToString())
|| localPort <= 0 || localPort >= Global.MaxPort) || localPort <= 0 || localPort >= Global.MaxPort)
{ {
_noticeHandler?.Enqueue(ResUI.FillLocalListeningPort); NoticeHandler.Instance.Enqueue(ResUI.FillLocalListeningPort);
return; return;
} }
var needReboot = (EnableStatistics != _config.guiItem.enableStatistics var needReboot = (EnableStatistics != _config.guiItem.enableStatistics
@ -267,7 +266,7 @@ namespace ServiceLib.ViewModels
// || Utile.IsNullOrEmpty(KcpreadBufferSize.ToString()) || !Utile.IsNumeric(KcpreadBufferSize.ToString()) // || Utile.IsNullOrEmpty(KcpreadBufferSize.ToString()) || !Utile.IsNumeric(KcpreadBufferSize.ToString())
// || Utile.IsNullOrEmpty(KcpwriteBufferSize.ToString()) || !Utile.IsNumeric(KcpwriteBufferSize.ToString())) // || Utile.IsNullOrEmpty(KcpwriteBufferSize.ToString()) || !Utile.IsNumeric(KcpwriteBufferSize.ToString()))
//{ //{
// _noticeHandler?.Enqueue(ResUI.FillKcpParameters); // NoticeHandler.Instance.Enqueue(ResUI.FillKcpParameters);
// return; // return;
//} //}
@ -337,17 +336,17 @@ namespace ServiceLib.ViewModels
{ {
if (needReboot) if (needReboot)
{ {
_noticeHandler?.Enqueue(ResUI.NeedRebootTips); NoticeHandler.Instance.Enqueue(ResUI.NeedRebootTips);
} }
else else
{ {
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
} }
await _updateView?.Invoke(EViewAction.CloseWindow, null); await _updateView?.Invoke(EViewAction.CloseWindow, null);
} }
else else
{ {
_noticeHandler?.Enqueue(ResUI.OperationFailed); NoticeHandler.Instance.Enqueue(ResUI.OperationFailed);
} }
} }

View File

@ -2,7 +2,6 @@ using DynamicData;
using DynamicData.Binding; using DynamicData.Binding;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using ServiceLib.Services;
using Splat; using Splat;
using System.Reactive; using System.Reactive;
using System.Reactive.Linq; using System.Reactive.Linq;
@ -99,7 +98,7 @@ namespace ServiceLib.ViewModels
public ProfilesViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public ProfilesViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
MessageBus.Current.Listen<string>(Global.CommandRefreshProfiles).Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null)); MessageBus.Current.Listen<string>(Global.CommandRefreshProfiles).Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null));
@ -259,8 +258,8 @@ namespace ServiceLib.ViewModels
{ {
if (Utils.IsNullOrEmpty(result.IndexId)) if (Utils.IsNullOrEmpty(result.IndexId))
{ {
_noticeHandler?.SendMessageEx(result.Delay); NoticeHandler.Instance.SendMessageEx(result.Delay);
_noticeHandler?.Enqueue(result.Delay); NoticeHandler.Instance.Enqueue(result.Delay);
return; return;
} }
var item = _profileItems.Where(it => it.indexId == result.IndexId).FirstOrDefault(); var item = _profileItems.Where(it => it.indexId == result.IndexId).FirstOrDefault();
@ -430,7 +429,7 @@ namespace ServiceLib.ViewModels
var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId); var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId);
if (item is null) if (item is null)
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer); NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectServer);
return; return;
} }
eConfigType = item.configType; eConfigType = item.configType;
@ -467,7 +466,7 @@ namespace ServiceLib.ViewModels
var exists = lstSelecteds.Exists(t => t.indexId == _config.indexId); var exists = lstSelecteds.Exists(t => t.indexId == _config.indexId);
ConfigHandler.RemoveServer(_config, lstSelecteds); ConfigHandler.RemoveServer(_config, lstSelecteds);
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
RefreshServers(); RefreshServers();
if (exists) if (exists)
@ -481,7 +480,7 @@ namespace ServiceLib.ViewModels
var tuple = ConfigHandler.DedupServerList(_config, _config.subIndexId); var tuple = ConfigHandler.DedupServerList(_config, _config.subIndexId);
RefreshServers(); RefreshServers();
Reload(); Reload();
_noticeHandler?.Enqueue(string.Format(ResUI.RemoveDuplicateServerResult, tuple.Item1, tuple.Item2)); NoticeHandler.Instance.Enqueue(string.Format(ResUI.RemoveDuplicateServerResult, tuple.Item1, tuple.Item2));
} }
private void CopyServer() private void CopyServer()
@ -493,7 +492,7 @@ namespace ServiceLib.ViewModels
if (ConfigHandler.CopyServer(_config, lstSelecteds) == 0) if (ConfigHandler.CopyServer(_config, lstSelecteds) == 0)
{ {
RefreshServers(); RefreshServers();
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
} }
} }
@ -519,7 +518,7 @@ namespace ServiceLib.ViewModels
var item = AppHandler.Instance.GetProfileItem(indexId); var item = AppHandler.Instance.GetProfileItem(indexId);
if (item is null) if (item is null)
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer); NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectServer);
return; return;
} }
@ -552,7 +551,7 @@ namespace ServiceLib.ViewModels
var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId); var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId);
if (item is null) if (item is null)
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer); NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectServer);
return; return;
} }
var url = FmtHandler.GetShareUri(item); var url = FmtHandler.GetShareUri(item);
@ -573,7 +572,7 @@ namespace ServiceLib.ViewModels
if (ConfigHandler.AddCustomServer4Multiple(_config, lstSelecteds, coreType, out string indexId) != 0) if (ConfigHandler.AddCustomServer4Multiple(_config, lstSelecteds, coreType, out string indexId) != 0)
{ {
_noticeHandler?.Enqueue(ResUI.OperationFailed); NoticeHandler.Instance.Enqueue(ResUI.OperationFailed);
return; return;
} }
if (indexId == _config.indexId) if (indexId == _config.indexId)
@ -618,7 +617,7 @@ namespace ServiceLib.ViewModels
} }
ConfigHandler.MoveToGroup(_config, lstSelecteds, SelectedMoveToGroup.id); ConfigHandler.MoveToGroup(_config, lstSelecteds, SelectedMoveToGroup.id);
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
RefreshServers(); RefreshServers();
SelectedMoveToGroup = new(); SelectedMoveToGroup = new();
@ -630,7 +629,7 @@ namespace ServiceLib.ViewModels
var item = _lstProfile.FirstOrDefault(t => t.indexId == SelectedProfile.indexId); var item = _lstProfile.FirstOrDefault(t => t.indexId == SelectedProfile.indexId);
if (item is null) if (item is null)
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer); NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectServer);
return; return;
} }
@ -685,19 +684,19 @@ namespace ServiceLib.ViewModels
var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId); var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId);
if (item is null) if (item is null)
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer); NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectServer);
return; return;
} }
if (blClipboard) if (blClipboard)
{ {
if (CoreConfigHandler.GenerateClientConfig(item, null, out string msg, out string content) != 0) if (CoreConfigHandler.GenerateClientConfig(item, null, out string msg, out string content) != 0)
{ {
Locator.Current.GetService<NoticeHandler>()?.Enqueue(msg); NoticeHandler.Instance.Enqueue(msg);
} }
else else
{ {
await _updateView?.Invoke(EViewAction.SetClipboardData, content); await _updateView?.Invoke(EViewAction.SetClipboardData, content);
_noticeHandler?.SendMessage(ResUI.OperationSuccess); NoticeHandler.Instance.SendMessage(ResUI.OperationSuccess);
} }
} }
else else
@ -714,12 +713,12 @@ namespace ServiceLib.ViewModels
} }
if (CoreConfigHandler.GenerateClientConfig(item, fileName, out string msg, out string content) != 0) if (CoreConfigHandler.GenerateClientConfig(item, fileName, out string msg, out string content) != 0)
{ {
Locator.Current.GetService<NoticeHandler>()?.Enqueue(msg); NoticeHandler.Instance.Enqueue(msg);
} }
else else
{ {
msg = string.Format(ResUI.SaveClientConfigurationIn, fileName); msg = string.Format(ResUI.SaveClientConfigurationIn, fileName);
Locator.Current.GetService<NoticeHandler>()?.SendMessageAndEnqueue(msg); NoticeHandler.Instance.SendMessageAndEnqueue(msg);
} }
} }
@ -751,7 +750,7 @@ namespace ServiceLib.ViewModels
{ {
await _updateView?.Invoke(EViewAction.SetClipboardData, sb.ToString()); await _updateView?.Invoke(EViewAction.SetClipboardData, sb.ToString());
} }
_noticeHandler?.SendMessage(ResUI.BatchExportURLSuccessfully); NoticeHandler.Instance.SendMessage(ResUI.BatchExportURLSuccessfully);
} }
} }

View File

@ -1,6 +1,5 @@
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Splat;
using System.Reactive; using System.Reactive;
namespace ServiceLib.ViewModels namespace ServiceLib.ViewModels
@ -30,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 = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
if (rulesItem.id.IsNullOrEmpty()) if (rulesItem.id.IsNullOrEmpty())
@ -84,10 +83,10 @@ namespace ServiceLib.ViewModels
if (!hasRule) if (!hasRule)
{ {
_noticeHandler?.Enqueue(string.Format(ResUI.RoutingRuleDetailRequiredTips, "Port/Protocol/Domain/IP/Process")); NoticeHandler.Instance.Enqueue(string.Format(ResUI.RoutingRuleDetailRequiredTips, "Port/Protocol/Domain/IP/Process"));
return; return;
} }
//_noticeHandler?.Enqueue(ResUI.OperationSuccess); //NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
await _updateView?.Invoke(EViewAction.CloseWindow, null); await _updateView?.Invoke(EViewAction.CloseWindow, null);
} }
} }

View File

@ -1,8 +1,6 @@
using DynamicData.Binding; using DynamicData.Binding;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using ServiceLib.Services;
using Splat;
using System.Reactive; using System.Reactive;
namespace ServiceLib.ViewModels namespace ServiceLib.ViewModels
@ -38,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 = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
SelectedSource = new(); SelectedSource = new();
@ -160,7 +158,7 @@ namespace ServiceLib.ViewModels
{ {
if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty()) if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty())
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectRules); NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectRules);
return; return;
} }
if (await _updateView?.Invoke(EViewAction.ShowYesNo, null) == false) if (await _updateView?.Invoke(EViewAction.ShowYesNo, null) == false)
@ -183,7 +181,7 @@ namespace ServiceLib.ViewModels
{ {
if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty()) if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty())
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectRules); NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectRules);
return; return;
} }
@ -207,7 +205,7 @@ namespace ServiceLib.ViewModels
{ {
if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty()) if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty())
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectRules); NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectRules);
return; return;
} }
@ -228,7 +226,7 @@ namespace ServiceLib.ViewModels
string remarks = SelectedRouting.remarks; string remarks = SelectedRouting.remarks;
if (Utils.IsNullOrEmpty(remarks)) if (Utils.IsNullOrEmpty(remarks))
{ {
_noticeHandler?.Enqueue(ResUI.PleaseFillRemarks); NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
return; return;
} }
var item = SelectedRouting; var item = SelectedRouting;
@ -241,12 +239,12 @@ namespace ServiceLib.ViewModels
if (ConfigHandler.SaveRoutingItem(_config, item) == 0) if (ConfigHandler.SaveRoutingItem(_config, item) == 0)
{ {
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
await _updateView?.Invoke(EViewAction.CloseWindow, null); await _updateView?.Invoke(EViewAction.CloseWindow, null);
} }
else else
{ {
_noticeHandler?.Enqueue(ResUI.OperationFailed); NoticeHandler.Instance.Enqueue(ResUI.OperationFailed);
} }
} }
@ -268,7 +266,7 @@ namespace ServiceLib.ViewModels
if (ret == 0) if (ret == 0)
{ {
RefreshRulesItems(); RefreshRulesItems();
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
} }
} }
@ -283,7 +281,7 @@ namespace ServiceLib.ViewModels
if (ret == 0) if (ret == 0)
{ {
RefreshRulesItems(); RefreshRulesItems();
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
} }
} }
@ -292,7 +290,7 @@ namespace ServiceLib.ViewModels
var url = SelectedRouting.url; var url = SelectedRouting.url;
if (Utils.IsNullOrEmpty(url)) if (Utils.IsNullOrEmpty(url))
{ {
_noticeHandler?.Enqueue(ResUI.MsgNeedUrl); NoticeHandler.Instance.Enqueue(ResUI.MsgNeedUrl);
return; return;
} }
@ -302,7 +300,7 @@ namespace ServiceLib.ViewModels
if (ret == 0) if (ret == 0)
{ {
RefreshRulesItems(); RefreshRulesItems();
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
} }
} }

View File

@ -1,7 +1,6 @@
using DynamicData.Binding; using DynamicData.Binding;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Splat;
using System.Reactive; using System.Reactive;
namespace ServiceLib.ViewModels namespace ServiceLib.ViewModels
@ -68,7 +67,7 @@ namespace ServiceLib.ViewModels
public RoutingSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public RoutingSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
SelectedSource = new(); SelectedSource = new();
@ -200,12 +199,12 @@ namespace ServiceLib.ViewModels
if (ConfigHandler.SaveConfig(_config) == 0) if (ConfigHandler.SaveConfig(_config) == 0)
{ {
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
await _updateView?.Invoke(EViewAction.CloseWindow, null); await _updateView?.Invoke(EViewAction.CloseWindow, null);
} }
else else
{ {
_noticeHandler?.Enqueue(ResUI.OperationFailed); NoticeHandler.Instance.Enqueue(ResUI.OperationFailed);
} }
} }
@ -219,8 +218,8 @@ namespace ServiceLib.ViewModels
DirectIP = "geoip:private,geoip:cn"; DirectIP = "geoip:private,geoip:cn";
BlockDomain = "geosite:category-ads-all"; BlockDomain = "geosite:category-ads-all";
//_noticeHandler?.Enqueue(ResUI.OperationSuccess); //NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
} }
public async Task RoutingAdvancedEditAsync(bool blNew) public async Task RoutingAdvancedEditAsync(bool blNew)
@ -249,7 +248,7 @@ namespace ServiceLib.ViewModels
{ {
if (SelectedSource is null || SelectedSource.remarks.IsNullOrEmpty()) if (SelectedSource is null || SelectedSource.remarks.IsNullOrEmpty())
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectRules); NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectRules);
return; return;
} }
if (await _updateView?.Invoke(EViewAction.ShowYesNo, null) == false) if (await _updateView?.Invoke(EViewAction.ShowYesNo, null) == false)
@ -274,7 +273,7 @@ namespace ServiceLib.ViewModels
var item = AppHandler.Instance.GetRoutingItem(SelectedSource?.id); var item = AppHandler.Instance.GetRoutingItem(SelectedSource?.id);
if (item is null) if (item is null)
{ {
_noticeHandler?.Enqueue(ResUI.PleaseSelectRules); NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectRules);
return; return;
} }

View File

@ -1,6 +1,5 @@
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Splat;
using System.Reactive; using System.Reactive;
namespace ServiceLib.ViewModels namespace ServiceLib.ViewModels
@ -15,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 = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
if (subItem.id.IsNullOrEmpty()) if (subItem.id.IsNullOrEmpty())
@ -38,18 +37,18 @@ namespace ServiceLib.ViewModels
string remarks = SelectedSource.remarks; string remarks = SelectedSource.remarks;
if (Utils.IsNullOrEmpty(remarks)) if (Utils.IsNullOrEmpty(remarks))
{ {
_noticeHandler?.Enqueue(ResUI.PleaseFillRemarks); NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
return; return;
} }
if (ConfigHandler.AddSubItem(_config, SelectedSource) == 0) if (ConfigHandler.AddSubItem(_config, SelectedSource) == 0)
{ {
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
await _updateView?.Invoke(EViewAction.CloseWindow, null); await _updateView?.Invoke(EViewAction.CloseWindow, null);
} }
else else
{ {
_noticeHandler?.Enqueue(ResUI.OperationFailed); NoticeHandler.Instance.Enqueue(ResUI.OperationFailed);
} }
} }
} }

View File

@ -2,7 +2,6 @@
using DynamicData.Binding; using DynamicData.Binding;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Splat;
using System.Reactive; using System.Reactive;
namespace ServiceLib.ViewModels namespace ServiceLib.ViewModels
@ -26,7 +25,7 @@ namespace ServiceLib.ViewModels
public SubSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public SubSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{ {
_config = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView; _updateView = updateView;
SelectedSource = new(); SelectedSource = new();
@ -95,7 +94,7 @@ namespace ServiceLib.ViewModels
ConfigHandler.DeleteSubItem(_config, it.id); ConfigHandler.DeleteSubItem(_config, it.id);
} }
RefreshSubItems(); RefreshSubItems();
_noticeHandler?.Enqueue(ResUI.OperationSuccess); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
IsModified = true; IsModified = true;
} }
} }

View File

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

View File

@ -3,7 +3,6 @@ using Avalonia.Controls;
using Avalonia.Styling; using Avalonia.Styling;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Splat;
using System.Reactive.Linq; using System.Reactive.Linq;
namespace v2rayN.Desktop.ViewModels namespace v2rayN.Desktop.ViewModels
@ -22,7 +21,6 @@ namespace v2rayN.Desktop.ViewModels
public ThemeSettingViewModel() public ThemeSettingViewModel()
{ {
_config = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
BindingUI(); BindingUI();
RestoreUI(); RestoreUI();
@ -75,7 +73,7 @@ namespace v2rayN.Desktop.ViewModels
_config.uiItem.currentLanguage = CurrentLanguage; _config.uiItem.currentLanguage = CurrentLanguage;
Thread.CurrentThread.CurrentUICulture = new(CurrentLanguage); Thread.CurrentThread.CurrentUICulture = new(CurrentLanguage);
ConfigHandler.SaveConfig(_config); ConfigHandler.SaveConfig(_config);
_noticeHandler?.Enqueue(ResUI.NeedRebootTips); NoticeHandler.Instance.Enqueue(ResUI.NeedRebootTips);
} }
}); });
} }

View File

@ -2,7 +2,6 @@
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.ReactiveUI; using Avalonia.ReactiveUI;
using ReactiveUI; using ReactiveUI;
using Splat;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using v2rayN.Desktop.Common; using v2rayN.Desktop.Common;
@ -10,7 +9,6 @@ namespace v2rayN.Desktop.Views
{ {
public partial class BackupAndRestoreView : ReactiveUserControl<BackupAndRestoreViewModel> public partial class BackupAndRestoreView : ReactiveUserControl<BackupAndRestoreViewModel>
{ {
private NoticeHandler? _noticeHandler;
private Window _window; private Window _window;
public BackupAndRestoreView(Window window) public BackupAndRestoreView(Window window)
@ -23,7 +21,6 @@ namespace v2rayN.Desktop.Views
ViewModel = new BackupAndRestoreViewModel(UpdateViewHandler); ViewModel = new BackupAndRestoreViewModel(UpdateViewHandler);
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
this.WhenActivated(disposables => this.WhenActivated(disposables =>
{ {
this.Bind(ViewModel, vm => vm.OperationMsg, v => v.txtMsg.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.OperationMsg, v => v.txtMsg.Text).DisposeWith(disposables);

View File

@ -49,7 +49,7 @@ namespace v2rayN.Desktop.Views
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
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);
}); });
} }
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj) private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)

View File

@ -79,7 +79,6 @@ namespace v2rayN.Desktop.Views
this.BindCommand(ViewModel, vm => vm.ClearServerStatisticsCmd, v => v.menuClearServerStatistics).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ClearServerStatisticsCmd, v => v.menuClearServerStatistics).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.OpenTheFileLocationCmd, v => v.menuOpenTheFileLocation).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.OpenTheFileLocationCmd, v => v.menuOpenTheFileLocation).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ReloadCmd, v => v.menuReload).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ReloadCmd, v => v.menuReload).DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.BlReloadEnabled, v => v.menuReload.IsEnabled).DisposeWith(disposables); this.OneWayBind(ViewModel, vm => vm.BlReloadEnabled, v => v.menuReload.IsEnabled).DisposeWith(disposables);

View File

@ -196,7 +196,7 @@ namespace v2rayN.Desktop.Views
else else
{ {
ViewModel?.EditServerAsync(EConfigType.Custom); ViewModel?.EditServerAsync(EConfigType.Custom);
} }
} }
private void LstProfiles_LoadingRow(object? sender, DataGridRowEventArgs e) private void LstProfiles_LoadingRow(object? sender, DataGridRowEventArgs e)
@ -313,6 +313,7 @@ namespace v2rayN.Desktop.Views
ViewModel?.RefreshServers(); ViewModel?.RefreshServers();
} }
} }
private void MenuStorageUI_Click(object? sender, RoutedEventArgs e) private void MenuStorageUI_Click(object? sender, RoutedEventArgs e)
{ {
StorageUI(); StorageUI();

View File

@ -12,7 +12,7 @@ namespace v2rayN.Desktop.Views
txtContent.Text = url; txtContent.Text = url;
imgQrcode.Source = GetQRCode(url); imgQrcode.Source = GetQRCode(url);
// btnCancel.Click += (s, e) => this.Close(); // btnCancel.Click += (s, e) => this.Close();
} }
private Bitmap? GetQRCode(string? url) private Bitmap? GetQRCode(string? url)

View File

@ -207,7 +207,7 @@ namespace v2rayN
uint attributeSize = (uint)Marshal.SizeOf(attribute); uint attributeSize = (uint)Marshal.SizeOf(attribute);
DwmSetWindowAttribute(hWnd, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1, ref attribute, attributeSize); DwmSetWindowAttribute(hWnd, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1, ref attribute, attributeSize);
DwmSetWindowAttribute(hWnd, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, ref attribute, attributeSize); DwmSetWindowAttribute(hWnd, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, ref attribute, attributeSize);
} }
/// <summary> /// <summary>
/// 开机自动启动 /// 开机自动启动

View File

@ -5,7 +5,6 @@ using MaterialDesignColors.ColorManipulation;
using MaterialDesignThemes.Wpf; using MaterialDesignThemes.Wpf;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Splat;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows; using System.Windows;
@ -38,7 +37,7 @@ namespace v2rayN.ViewModels
public ThemeSettingViewModel() public ThemeSettingViewModel()
{ {
_config = AppHandler.Instance.Config; _config = AppHandler.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
RegisterSystemColorSet(_config, Application.Current.MainWindow, (bool bl) => { ModifyTheme(bl); }); RegisterSystemColorSet(_config, Application.Current.MainWindow, (bool bl) => { ModifyTheme(bl); });
BindingUI(); BindingUI();
@ -161,7 +160,7 @@ namespace v2rayN.ViewModels
_config.uiItem.currentLanguage = CurrentLanguage; _config.uiItem.currentLanguage = CurrentLanguage;
Thread.CurrentThread.CurrentUICulture = new(CurrentLanguage); Thread.CurrentThread.CurrentUICulture = new(CurrentLanguage);
ConfigHandler.SaveConfig(_config); ConfigHandler.SaveConfig(_config);
_noticeHandler?.Enqueue(ResUI.NeedRebootTips); NoticeHandler.Instance.Enqueue(ResUI.NeedRebootTips);
} }
}); });
} }

View File

@ -17,7 +17,7 @@ namespace v2rayN.Views
foreach (ECoreType it in Enum.GetValues(typeof(ECoreType))) foreach (ECoreType it in Enum.GetValues(typeof(ECoreType)))
{ {
if (it == ECoreType.v2rayN) if (it == ECoreType.v2rayN)
continue; continue;
cmbCoreType.Items.Add(it.ToString()); cmbCoreType.Items.Add(it.ToString());
} }
cmbCoreType.Items.Add(string.Empty); cmbCoreType.Items.Add(string.Empty);

View File

@ -1,5 +1,4 @@
using ReactiveUI; using ReactiveUI;
using Splat;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Windows; using System.Windows;
@ -7,8 +6,6 @@ namespace v2rayN.Views
{ {
public partial class BackupAndRestoreView public partial class BackupAndRestoreView
{ {
private NoticeHandler? _noticeHandler;
public BackupAndRestoreView() public BackupAndRestoreView()
{ {
InitializeComponent(); InitializeComponent();
@ -17,7 +14,6 @@ namespace v2rayN.Views
ViewModel = new BackupAndRestoreViewModel(UpdateViewHandler); ViewModel = new BackupAndRestoreViewModel(UpdateViewHandler);
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
this.WhenActivated(disposables => this.WhenActivated(disposables =>
{ {
this.Bind(ViewModel, vm => vm.OperationMsg, v => v.txtMsg.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.OperationMsg, v => v.txtMsg.Text).DisposeWith(disposables);
@ -32,7 +28,7 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.RemoteBackupCmd, v => v.menuRemoteBackup).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.RemoteBackupCmd, v => v.menuRemoteBackup).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.RemoteRestoreCmd, v => v.menuRemoteRestore).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.RemoteRestoreCmd, v => v.menuRemoteRestore).DisposeWith(disposables);
}); });
} }
private void MenuLocalBackup_Click(object sender, RoutedEventArgs e) private void MenuLocalBackup_Click(object sender, RoutedEventArgs e)
{ {

View File

@ -1,11 +1,11 @@
<reactiveui:ReactiveUserControl <reactiveui:ReactiveUserControl
x:Class="v2rayN.Views.ClashConnectionsView" x:Class="v2rayN.Views.ClashConnectionsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:reactiveui="http://reactiveui.net"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:reactiveui="http://reactiveui.net"
xmlns:resx="clr-namespace:ServiceLib.Resx;assembly=ServiceLib" xmlns:resx="clr-namespace:ServiceLib.Resx;assembly=ServiceLib"
xmlns:vms="clr-namespace:ServiceLib.ViewModels;assembly=ServiceLib" xmlns:vms="clr-namespace:ServiceLib.ViewModels;assembly=ServiceLib"
d:DesignHeight="450" d:DesignHeight="450"

View File

@ -172,7 +172,7 @@ namespace v2rayN.Views
{ {
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
} }
RestoreUI(); RestoreUI();
AddHelpMenuItem(); AddHelpMenuItem();
} }
@ -492,7 +492,7 @@ namespace v2rayN.Views
{ {
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(); var coreInfo = CoreInfoHandler.Instance.GetCoreInfo();
foreach (var it in coreInfo foreach (var it in coreInfo
.Where(t => t.coreType != ECoreType.v2fly .Where(t => t.coreType != ECoreType.v2fly
&& t.coreType != ECoreType.hysteria)) && t.coreType != ECoreType.hysteria))
{ {
var item = new MenuItem() var item = new MenuItem()

View File

@ -164,8 +164,6 @@
HorizontalAlignment="Left" HorizontalAlignment="Left"
Style="{StaticResource ToolbarTextBlock}" Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbRoutingTips}" /> Text="{x:Static resx:ResUI.TbRoutingTips}" />
</Grid> </Grid>
<StackPanel <StackPanel