mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-09 06:59:53 +03:00
Refactor NoticeHandler
This commit is contained in:
@@ -2,7 +2,6 @@ using DynamicData;
|
||||
using DynamicData.Binding;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using ServiceLib.Services;
|
||||
using Splat;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Linq;
|
||||
@@ -99,7 +98,7 @@ namespace ServiceLib.ViewModels
|
||||
public ProfilesViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
|
||||
{
|
||||
_config = AppHandler.Instance.Config;
|
||||
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
|
||||
|
||||
_updateView = updateView;
|
||||
|
||||
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))
|
||||
{
|
||||
_noticeHandler?.SendMessageEx(result.Delay);
|
||||
_noticeHandler?.Enqueue(result.Delay);
|
||||
NoticeHandler.Instance.SendMessageEx(result.Delay);
|
||||
NoticeHandler.Instance.Enqueue(result.Delay);
|
||||
return;
|
||||
}
|
||||
var item = _profileItems.Where(it => it.indexId == result.IndexId).FirstOrDefault();
|
||||
@@ -430,7 +429,7 @@ namespace ServiceLib.ViewModels
|
||||
var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId);
|
||||
if (item is null)
|
||||
{
|
||||
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
|
||||
NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectServer);
|
||||
return;
|
||||
}
|
||||
eConfigType = item.configType;
|
||||
@@ -467,7 +466,7 @@ namespace ServiceLib.ViewModels
|
||||
var exists = lstSelecteds.Exists(t => t.indexId == _config.indexId);
|
||||
|
||||
ConfigHandler.RemoveServer(_config, lstSelecteds);
|
||||
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
|
||||
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
|
||||
|
||||
RefreshServers();
|
||||
if (exists)
|
||||
@@ -481,7 +480,7 @@ namespace ServiceLib.ViewModels
|
||||
var tuple = ConfigHandler.DedupServerList(_config, _config.subIndexId);
|
||||
RefreshServers();
|
||||
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()
|
||||
@@ -493,7 +492,7 @@ namespace ServiceLib.ViewModels
|
||||
if (ConfigHandler.CopyServer(_config, lstSelecteds) == 0)
|
||||
{
|
||||
RefreshServers();
|
||||
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
|
||||
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,7 +518,7 @@ namespace ServiceLib.ViewModels
|
||||
var item = AppHandler.Instance.GetProfileItem(indexId);
|
||||
if (item is null)
|
||||
{
|
||||
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
|
||||
NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectServer);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -552,7 +551,7 @@ namespace ServiceLib.ViewModels
|
||||
var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId);
|
||||
if (item is null)
|
||||
{
|
||||
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
|
||||
NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectServer);
|
||||
return;
|
||||
}
|
||||
var url = FmtHandler.GetShareUri(item);
|
||||
@@ -573,7 +572,7 @@ namespace ServiceLib.ViewModels
|
||||
|
||||
if (ConfigHandler.AddCustomServer4Multiple(_config, lstSelecteds, coreType, out string indexId) != 0)
|
||||
{
|
||||
_noticeHandler?.Enqueue(ResUI.OperationFailed);
|
||||
NoticeHandler.Instance.Enqueue(ResUI.OperationFailed);
|
||||
return;
|
||||
}
|
||||
if (indexId == _config.indexId)
|
||||
@@ -618,7 +617,7 @@ namespace ServiceLib.ViewModels
|
||||
}
|
||||
|
||||
ConfigHandler.MoveToGroup(_config, lstSelecteds, SelectedMoveToGroup.id);
|
||||
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
|
||||
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
|
||||
|
||||
RefreshServers();
|
||||
SelectedMoveToGroup = new();
|
||||
@@ -630,7 +629,7 @@ namespace ServiceLib.ViewModels
|
||||
var item = _lstProfile.FirstOrDefault(t => t.indexId == SelectedProfile.indexId);
|
||||
if (item is null)
|
||||
{
|
||||
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
|
||||
NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectServer);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -685,19 +684,19 @@ namespace ServiceLib.ViewModels
|
||||
var item = AppHandler.Instance.GetProfileItem(SelectedProfile.indexId);
|
||||
if (item is null)
|
||||
{
|
||||
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
|
||||
NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectServer);
|
||||
return;
|
||||
}
|
||||
if (blClipboard)
|
||||
{
|
||||
if (CoreConfigHandler.GenerateClientConfig(item, null, out string msg, out string content) != 0)
|
||||
{
|
||||
Locator.Current.GetService<NoticeHandler>()?.Enqueue(msg);
|
||||
NoticeHandler.Instance.Enqueue(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _updateView?.Invoke(EViewAction.SetClipboardData, content);
|
||||
_noticeHandler?.SendMessage(ResUI.OperationSuccess);
|
||||
NoticeHandler.Instance.SendMessage(ResUI.OperationSuccess);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -714,12 +713,12 @@ namespace ServiceLib.ViewModels
|
||||
}
|
||||
if (CoreConfigHandler.GenerateClientConfig(item, fileName, out string msg, out string content) != 0)
|
||||
{
|
||||
Locator.Current.GetService<NoticeHandler>()?.Enqueue(msg);
|
||||
NoticeHandler.Instance.Enqueue(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
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());
|
||||
}
|
||||
_noticeHandler?.SendMessage(ResUI.BatchExportURLSuccessfully);
|
||||
NoticeHandler.Instance.SendMessage(ResUI.BatchExportURLSuccessfully);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user