mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-27 18:42:52 +00:00
Compare commits
2 commits
a108eaf34b
...
058c6e4a85
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
058c6e4a85 | ||
|
|
ea1d438e40 |
13 changed files with 121 additions and 114 deletions
|
|
@ -1,10 +0,0 @@
|
||||||
namespace ServiceLib.Enums;
|
|
||||||
|
|
||||||
public enum EMsgCommand
|
|
||||||
{
|
|
||||||
ClearMsg,
|
|
||||||
SendMsgView,
|
|
||||||
SendSnackMsg,
|
|
||||||
RefreshProfiles,
|
|
||||||
AppExit
|
|
||||||
}
|
|
||||||
15
v2rayN/ServiceLib/Handler/AppEvents.cs
Normal file
15
v2rayN/ServiceLib/Handler/AppEvents.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
using System.Reactive;
|
||||||
|
using System.Reactive.Subjects;
|
||||||
|
|
||||||
|
namespace ServiceLib.Handler;
|
||||||
|
|
||||||
|
public static class AppEvents
|
||||||
|
{
|
||||||
|
public static readonly Subject<Unit> ProfilesRefreshRequested = new();
|
||||||
|
|
||||||
|
public static readonly Subject<string> SendSnackMsgRequested = new();
|
||||||
|
|
||||||
|
public static readonly Subject<string> SendMsgViewRequested = new();
|
||||||
|
|
||||||
|
public static readonly Subject<Unit> AppExitRequested = new();
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
using ReactiveUI;
|
|
||||||
|
|
||||||
namespace ServiceLib.Manager;
|
namespace ServiceLib.Manager;
|
||||||
|
|
||||||
public class NoticeManager
|
public class NoticeManager
|
||||||
|
|
@ -13,7 +11,7 @@ public class NoticeManager
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MessageBus.Current.SendMessage(content, EMsgCommand.SendSnackMsg.ToString());
|
AppEvents.SendSnackMsgRequested.OnNext(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendMessage(string? content)
|
public void SendMessage(string? content)
|
||||||
|
|
@ -22,7 +20,7 @@ public class NoticeManager
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MessageBus.Current.SendMessage(content, EMsgCommand.SendMsgView.ToString());
|
AppEvents.SendMsgViewRequested.OnNext(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendMessageEx(string? content)
|
public void SendMessageEx(string? content)
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,7 @@ public class MainWindowViewModel : MyReactiveObject
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
var indexIdOld = _config.IndexId;
|
var indexIdOld = _config.IndexId;
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
if (indexIdOld != _config.IndexId)
|
if (indexIdOld != _config.IndexId)
|
||||||
{
|
{
|
||||||
await Reload();
|
await Reload();
|
||||||
|
|
@ -300,7 +300,7 @@ public class MainWindowViewModel : MyReactiveObject
|
||||||
Logging.SaveLog("MyAppExitAsync Begin");
|
Logging.SaveLog("MyAppExitAsync Begin");
|
||||||
|
|
||||||
await SysProxyHandler.UpdateSysProxy(_config, true);
|
await SysProxyHandler.UpdateSysProxy(_config, true);
|
||||||
MessageBus.Current.SendMessage("", EMsgCommand.AppExit.ToString());
|
AppEvents.AppExitRequested.OnNext(Unit.Default);
|
||||||
|
|
||||||
await ConfigHandler.SaveConfig(_config);
|
await ConfigHandler.SaveConfig(_config);
|
||||||
await ProfileExManager.Instance.SaveTo();
|
await ProfileExManager.Instance.SaveTo();
|
||||||
|
|
@ -350,9 +350,11 @@ public class MainWindowViewModel : MyReactiveObject
|
||||||
|
|
||||||
#region Servers && Groups
|
#region Servers && Groups
|
||||||
|
|
||||||
private void RefreshServers()
|
private async Task RefreshServers()
|
||||||
{
|
{
|
||||||
MessageBus.Current.SendMessage("", EMsgCommand.RefreshProfiles.ToString());
|
AppEvents.ProfilesRefreshRequested.OnNext(Unit.Default);
|
||||||
|
|
||||||
|
await Task.Delay(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RefreshSubscriptions()
|
private void RefreshSubscriptions()
|
||||||
|
|
@ -384,7 +386,7 @@ public class MainWindowViewModel : MyReactiveObject
|
||||||
}
|
}
|
||||||
if (ret == true)
|
if (ret == true)
|
||||||
{
|
{
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
if (item.IndexId == _config.IndexId)
|
if (item.IndexId == _config.IndexId)
|
||||||
{
|
{
|
||||||
await Reload();
|
await Reload();
|
||||||
|
|
@ -399,11 +401,11 @@ public class MainWindowViewModel : MyReactiveObject
|
||||||
await _updateView?.Invoke(EViewAction.AddServerViaClipboard, null);
|
await _updateView?.Invoke(EViewAction.AddServerViaClipboard, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int ret = await ConfigHandler.AddBatchServers(_config, clipboardData, _config.SubIndexId, false);
|
var ret = await ConfigHandler.AddBatchServers(_config, clipboardData, _config.SubIndexId, false);
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
{
|
{
|
||||||
RefreshSubscriptions();
|
RefreshSubscriptions();
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
NoticeManager.Instance.Enqueue(string.Format(ResUI.SuccessfullyImportedServerViaClipboard, ret));
|
NoticeManager.Instance.Enqueue(string.Format(ResUI.SuccessfullyImportedServerViaClipboard, ret));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -449,11 +451,11 @@ public class MainWindowViewModel : MyReactiveObject
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int ret = await ConfigHandler.AddBatchServers(_config, result, _config.SubIndexId, false);
|
var ret = await ConfigHandler.AddBatchServers(_config, result, _config.SubIndexId, false);
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
{
|
{
|
||||||
RefreshSubscriptions();
|
RefreshSubscriptions();
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
NoticeManager.Instance.Enqueue(ResUI.SuccessfullyImportedServerViaScan);
|
NoticeManager.Instance.Enqueue(ResUI.SuccessfullyImportedServerViaScan);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -532,7 +534,7 @@ public class MainWindowViewModel : MyReactiveObject
|
||||||
private async Task ClearServerStatistics()
|
private async Task ClearServerStatistics()
|
||||||
{
|
{
|
||||||
await StatisticsManager.Instance.ClearAllServerStatistics();
|
await StatisticsManager.Instance.ClearAllServerStatistics();
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OpenTheFileLocation()
|
private async Task OpenTheFileLocation()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Reactive.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using ReactiveUI.Fody.Helpers;
|
using ReactiveUI.Fody.Helpers;
|
||||||
|
|
@ -34,12 +35,10 @@ public class MsgViewModel : MyReactiveObject
|
||||||
y => y == true)
|
y => y == true)
|
||||||
.Subscribe(c => { _config.MsgUIItem.AutoRefresh = AutoRefresh; });
|
.Subscribe(c => { _config.MsgUIItem.AutoRefresh = AutoRefresh; });
|
||||||
|
|
||||||
MessageBus.Current.Listen<string>(EMsgCommand.SendMsgView.ToString()).Subscribe(OnNext);
|
AppEvents.SendMsgViewRequested
|
||||||
}
|
.AsObservable()
|
||||||
|
//.ObserveOn(RxApp.MainThreadScheduler)
|
||||||
private async void OnNext(string x)
|
.Subscribe(async content => await AppendQueueMsg(content));
|
||||||
{
|
|
||||||
await AppendQueueMsg(x);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task AppendQueueMsg(string msg)
|
private async Task AppendQueueMsg(string msg)
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
this.WhenAnyValue(
|
this.WhenAnyValue(
|
||||||
x => x.ServerFilter,
|
x => x.ServerFilter,
|
||||||
y => y != null && _serverFilter != y)
|
y => y != null && _serverFilter != y)
|
||||||
.Subscribe(c => ServerFilterChanged(c));
|
.Subscribe(async c => await ServerFilterChanged(c));
|
||||||
|
|
||||||
//servers delete
|
//servers delete
|
||||||
EditServerCmd = ReactiveCommand.CreateFromTask(async () =>
|
EditServerCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
|
|
@ -249,7 +249,10 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
|
|
||||||
if (_updateView != null)
|
if (_updateView != null)
|
||||||
{
|
{
|
||||||
MessageBus.Current.Listen<string>(EMsgCommand.RefreshProfiles.ToString()).Subscribe(OnNext);
|
AppEvents.ProfilesRefreshRequested
|
||||||
|
.AsObservable()
|
||||||
|
.ObserveOn(RxApp.MainThreadScheduler)
|
||||||
|
.Subscribe(async _ => await RefreshServersBiz());//.DisposeWith(_disposables);
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = Init();
|
_ = Init();
|
||||||
|
|
@ -263,18 +266,13 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
SelectedServer = new();
|
SelectedServer = new();
|
||||||
|
|
||||||
await RefreshSubscriptions();
|
await RefreshSubscriptions();
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Init
|
#endregion Init
|
||||||
|
|
||||||
#region Actions
|
#region Actions
|
||||||
|
|
||||||
private async void OnNext(string x)
|
|
||||||
{
|
|
||||||
await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Reload()
|
private void Reload()
|
||||||
{
|
{
|
||||||
Locator.Current.GetService<MainWindowViewModel>()?.Reload();
|
Locator.Current.GetService<MainWindowViewModel>()?.Reload();
|
||||||
|
|
@ -353,12 +351,12 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
}
|
}
|
||||||
_config.SubIndexId = SelectedSub?.Id;
|
_config.SubIndexId = SelectedSub?.Id;
|
||||||
|
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
|
|
||||||
await _updateView?.Invoke(EViewAction.ProfilesFocus, null);
|
await _updateView?.Invoke(EViewAction.ProfilesFocus, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ServerFilterChanged(bool c)
|
private async Task ServerFilterChanged(bool c)
|
||||||
{
|
{
|
||||||
if (!c)
|
if (!c)
|
||||||
{
|
{
|
||||||
|
|
@ -367,16 +365,18 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
_serverFilter = ServerFilter;
|
_serverFilter = ServerFilter;
|
||||||
if (_serverFilter.IsNullOrEmpty())
|
if (_serverFilter.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RefreshServers()
|
public async Task RefreshServers()
|
||||||
{
|
{
|
||||||
MessageBus.Current.SendMessage("", EMsgCommand.RefreshProfiles.ToString());
|
AppEvents.ProfilesRefreshRequested.OnNext(Unit.Default);
|
||||||
|
|
||||||
|
await Task.Delay(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RefreshServersBiz()
|
private async Task RefreshServersBiz()
|
||||||
{
|
{
|
||||||
var lstModel = await GetProfileItemsEx(_config.SubIndexId, _serverFilter);
|
var lstModel = await GetProfileItemsEx(_config.SubIndexId, _serverFilter);
|
||||||
_lstProfile = JsonUtils.Deserialize<List<ProfileItem>>(JsonUtils.Serialize(lstModel)) ?? [];
|
_lstProfile = JsonUtils.Deserialize<List<ProfileItem>>(JsonUtils.Serialize(lstModel)) ?? [];
|
||||||
|
|
@ -395,6 +395,8 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
SelectedProfile = lstModel.First();
|
SelectedProfile = lstModel.First();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RefreshSubscriptions()
|
public async Task RefreshSubscriptions()
|
||||||
|
|
@ -514,7 +516,7 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
}
|
}
|
||||||
if (ret == true)
|
if (ret == true)
|
||||||
{
|
{
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
if (item.IndexId == _config.IndexId)
|
if (item.IndexId == _config.IndexId)
|
||||||
{
|
{
|
||||||
Reload();
|
Reload();
|
||||||
|
|
@ -541,7 +543,7 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
{
|
{
|
||||||
_profileItems.Clear();
|
_profileItems.Clear();
|
||||||
}
|
}
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
if (exists)
|
if (exists)
|
||||||
{
|
{
|
||||||
Reload();
|
Reload();
|
||||||
|
|
@ -553,7 +555,7 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
var tuple = await ConfigHandler.DedupServerList(_config, _config.SubIndexId);
|
var tuple = await ConfigHandler.DedupServerList(_config, _config.SubIndexId);
|
||||||
if (tuple.Item1 > 0 || tuple.Item2 > 0)
|
if (tuple.Item1 > 0 || tuple.Item2 > 0)
|
||||||
{
|
{
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
Reload();
|
Reload();
|
||||||
}
|
}
|
||||||
NoticeManager.Instance.Enqueue(string.Format(ResUI.RemoveDuplicateServerResult, tuple.Item1, tuple.Item2));
|
NoticeManager.Instance.Enqueue(string.Format(ResUI.RemoveDuplicateServerResult, tuple.Item1, tuple.Item2));
|
||||||
|
|
@ -568,7 +570,7 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
}
|
}
|
||||||
if (await ConfigHandler.CopyServer(_config, lstSelected) == 0)
|
if (await ConfigHandler.CopyServer(_config, lstSelected) == 0)
|
||||||
{
|
{
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
NoticeManager.Instance.Enqueue(ResUI.OperationSuccess);
|
NoticeManager.Instance.Enqueue(ResUI.OperationSuccess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -601,7 +603,7 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
|
|
||||||
if (await ConfigHandler.SetDefaultServerIndex(_config, indexId) == 0)
|
if (await ConfigHandler.SetDefaultServerIndex(_config, indexId) == 0)
|
||||||
{
|
{
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
Reload();
|
Reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -652,7 +654,7 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
}
|
}
|
||||||
if (ret?.Data?.ToString() == _config.IndexId)
|
if (ret?.Data?.ToString() == _config.IndexId)
|
||||||
{
|
{
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
Reload();
|
Reload();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -675,13 +677,13 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_dicHeaderSort[colName] = !asc;
|
_dicHeaderSort[colName] = !asc;
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RemoveInvalidServerResult()
|
public async Task RemoveInvalidServerResult()
|
||||||
{
|
{
|
||||||
var count = await ConfigHandler.RemoveInvalidServerResult(_config, _config.SubIndexId);
|
var count = await ConfigHandler.RemoveInvalidServerResult(_config, _config.SubIndexId);
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
NoticeManager.Instance.Enqueue(string.Format(ResUI.RemoveInvalidServerResultTip, count));
|
NoticeManager.Instance.Enqueue(string.Format(ResUI.RemoveInvalidServerResultTip, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -702,7 +704,7 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
await ConfigHandler.MoveToGroup(_config, lstSelected, SelectedMoveToGroup.Id);
|
await ConfigHandler.MoveToGroup(_config, lstSelected, SelectedMoveToGroup.Id);
|
||||||
NoticeManager.Instance.Enqueue(ResUI.OperationSuccess);
|
NoticeManager.Instance.Enqueue(ResUI.OperationSuccess);
|
||||||
|
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
SelectedMoveToGroup = null;
|
SelectedMoveToGroup = null;
|
||||||
SelectedMoveToGroup = new();
|
SelectedMoveToGroup = new();
|
||||||
}
|
}
|
||||||
|
|
@ -723,7 +725,7 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
}
|
}
|
||||||
if (await ConfigHandler.MoveServer(_config, _lstProfile, index, eMove) == 0)
|
if (await ConfigHandler.MoveServer(_config, _lstProfile, index, eMove) == 0)
|
||||||
{
|
{
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -734,7 +736,7 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
{
|
{
|
||||||
if (await ConfigHandler.MoveServer(_config, _lstProfile, startIndex, EMove.Position, targetIndex) == 0)
|
if (await ConfigHandler.MoveServer(_config, _lstProfile, startIndex, EMove.Position, targetIndex) == 0)
|
||||||
{
|
{
|
||||||
RefreshServers();
|
await RefreshServers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Reactive;
|
using System.Reactive;
|
||||||
|
using System.Reactive.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using DynamicData.Binding;
|
using DynamicData.Binding;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
|
|
@ -216,15 +217,13 @@ public class StatusBarViewModel : MyReactiveObject
|
||||||
_updateView = updateView;
|
_updateView = updateView;
|
||||||
if (_updateView != null)
|
if (_updateView != null)
|
||||||
{
|
{
|
||||||
MessageBus.Current.Listen<string>(EMsgCommand.RefreshProfiles.ToString()).Subscribe(OnNext);
|
AppEvents.ProfilesRefreshRequested
|
||||||
|
.AsObservable()
|
||||||
|
.ObserveOn(RxApp.MainThreadScheduler)
|
||||||
|
.Subscribe(async _ => await RefreshServersBiz()); //.DisposeWith(_disposables);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OnNext(string x)
|
|
||||||
{
|
|
||||||
await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task CopyProxyCmdToClipboard()
|
private async Task CopyProxyCmdToClipboard()
|
||||||
{
|
{
|
||||||
var cmd = Utils.IsWindows() ? "set" : "export";
|
var cmd = Utils.IsWindows() ? "set" : "export";
|
||||||
|
|
@ -263,7 +262,7 @@ public class StatusBarViewModel : MyReactiveObject
|
||||||
await service.UpdateSubscriptionProcess("", blProxy);
|
await service.UpdateSubscriptionProcess("", blProxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RefreshServersBiz()
|
private async Task RefreshServersBiz()
|
||||||
{
|
{
|
||||||
await RefreshServersMenu();
|
await RefreshServersMenu();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
|
using System.Reactive.Linq;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
|
|
@ -39,7 +40,6 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
|
||||||
menuBackupAndRestore.Click += MenuBackupAndRestore_Click;
|
menuBackupAndRestore.Click += MenuBackupAndRestore_Click;
|
||||||
menuClose.Click += MenuClose_Click;
|
menuClose.Click += MenuClose_Click;
|
||||||
|
|
||||||
MessageBus.Current.Listen<string>(EMsgCommand.SendSnackMsg.ToString()).Subscribe(DelegateSnackMsg);
|
|
||||||
ViewModel = new MainWindowViewModel(UpdateViewHandler);
|
ViewModel = new MainWindowViewModel(UpdateViewHandler);
|
||||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(MainWindowViewModel));
|
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(MainWindowViewModel));
|
||||||
|
|
||||||
|
|
@ -136,6 +136,18 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
|
||||||
this.Bind(ViewModel, vm => vm.TabMainSelectedIndex, v => v.tabMain2.SelectedIndex).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.TabMainSelectedIndex, v => v.tabMain2.SelectedIndex).DisposeWith(disposables);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AppEvents.SendSnackMsgRequested
|
||||||
|
.AsObservable()
|
||||||
|
.ObserveOn(RxApp.MainThreadScheduler)
|
||||||
|
.Subscribe(async content => await DelegateSnackMsg(content))
|
||||||
|
.DisposeWith(disposables);
|
||||||
|
|
||||||
|
AppEvents.AppExitRequested
|
||||||
|
.AsObservable()
|
||||||
|
.ObserveOn(RxApp.MainThreadScheduler)
|
||||||
|
.Subscribe(_ => StorageUI())
|
||||||
|
.DisposeWith(disposables);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Utils.IsWindows())
|
if (Utils.IsWindows())
|
||||||
|
|
@ -156,7 +168,6 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
|
||||||
menuAddServerViaScan.IsVisible = false;
|
menuAddServerViaScan.IsVisible = false;
|
||||||
|
|
||||||
AddHelpMenuItem();
|
AddHelpMenuItem();
|
||||||
MessageBus.Current.Listen<string>(EMsgCommand.AppExit.ToString()).Subscribe(StorageUI);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Event
|
#region Event
|
||||||
|
|
@ -168,11 +179,9 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
|
||||||
DispatcherPriority.Default);
|
DispatcherPriority.Default);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DelegateSnackMsg(string content)
|
private async Task DelegateSnackMsg(string content)
|
||||||
{
|
{
|
||||||
Dispatcher.UIThread.Post(() =>
|
_manager?.Show(new Notification(null, content, NotificationType.Information));
|
||||||
_manager?.Show(new Notification(null, content, NotificationType.Information)),
|
|
||||||
DispatcherPriority.Normal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
|
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
|
||||||
|
|
@ -462,7 +471,7 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StorageUI(string? n = null)
|
private void StorageUI()
|
||||||
{
|
{
|
||||||
ConfigHandler.SaveWindowSizeItem(_config, GetType().Name, Width, Height);
|
ConfigHandler.SaveWindowSizeItem(_config, GetType().Name, Width, Height);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
|
using System.Reactive.Linq;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
|
|
@ -96,11 +97,16 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
|
||||||
this.BindCommand(ViewModel, vm => vm.Export2ClientConfigClipboardCmd, v => v.menuExport2ClientConfigClipboard).DisposeWith(disposables);
|
this.BindCommand(ViewModel, vm => vm.Export2ClientConfigClipboardCmd, v => v.menuExport2ClientConfigClipboard).DisposeWith(disposables);
|
||||||
this.BindCommand(ViewModel, vm => vm.Export2ShareUrlCmd, v => v.menuExport2ShareUrl).DisposeWith(disposables);
|
this.BindCommand(ViewModel, vm => vm.Export2ShareUrlCmd, v => v.menuExport2ShareUrl).DisposeWith(disposables);
|
||||||
this.BindCommand(ViewModel, vm => vm.Export2ShareUrlBase64Cmd, v => v.menuExport2ShareUrlBase64).DisposeWith(disposables);
|
this.BindCommand(ViewModel, vm => vm.Export2ShareUrlBase64Cmd, v => v.menuExport2ShareUrlBase64).DisposeWith(disposables);
|
||||||
|
|
||||||
|
AppEvents.AppExitRequested
|
||||||
|
.AsObservable()
|
||||||
|
.ObserveOn(RxApp.MainThreadScheduler)
|
||||||
|
.Subscribe(_ => StorageUI())
|
||||||
|
.DisposeWith(disposables);
|
||||||
});
|
});
|
||||||
|
|
||||||
RestoreUI();
|
RestoreUI();
|
||||||
ViewModel?.RefreshServers();
|
ViewModel?.RefreshServers();
|
||||||
MessageBus.Current.Listen<string>(EMsgCommand.AppExit.ToString()).Subscribe(StorageUI);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void LstProfiles_Sorting(object? sender, DataGridColumnEventArgs e)
|
private async void LstProfiles_Sorting(object? sender, DataGridColumnEventArgs e)
|
||||||
|
|
@ -187,11 +193,7 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EViewAction.DispatcherRefreshServersBiz:
|
case EViewAction.DispatcherRefreshServersBiz:
|
||||||
Dispatcher.UIThread.Post(() =>
|
Dispatcher.UIThread.Post(RefreshServersBiz, DispatcherPriority.Default);
|
||||||
{
|
|
||||||
_ = RefreshServersBiz();
|
|
||||||
},
|
|
||||||
DispatcherPriority.Default);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -209,13 +211,8 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
|
||||||
await DialogHost.Show(dialog);
|
await DialogHost.Show(dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RefreshServersBiz()
|
public void RefreshServersBiz()
|
||||||
{
|
{
|
||||||
if (ViewModel != null)
|
|
||||||
{
|
|
||||||
await ViewModel.RefreshServersBiz();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lstProfiles.SelectedIndex >= 0)
|
if (lstProfiles.SelectedIndex >= 0)
|
||||||
{
|
{
|
||||||
lstProfiles.ScrollIntoView(lstProfiles.SelectedItem, null);
|
lstProfiles.ScrollIntoView(lstProfiles.SelectedItem, null);
|
||||||
|
|
@ -421,7 +418,7 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StorageUI(string? n = null)
|
private void StorageUI()
|
||||||
{
|
{
|
||||||
List<ColumnItem> lvColumnItem = new();
|
List<ColumnItem> lvColumnItem = new();
|
||||||
foreach (var item2 in lstProfiles.Columns)
|
foreach (var item2 in lstProfiles.Columns)
|
||||||
|
|
|
||||||
|
|
@ -63,12 +63,7 @@ public partial class StatusBarView : ReactiveUserControl<StatusBarViewModel>
|
||||||
ViewModel?.TestServerAvailabilityResult((string)obj),
|
ViewModel?.TestServerAvailabilityResult((string)obj),
|
||||||
DispatcherPriority.Default);
|
DispatcherPriority.Default);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EViewAction.DispatcherRefreshServersBiz:
|
|
||||||
Dispatcher.UIThread.Post(() =>
|
|
||||||
ViewModel?.RefreshServersBiz(),
|
|
||||||
DispatcherPriority.Default);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EViewAction.DispatcherRefreshIcon:
|
case EViewAction.DispatcherRefreshIcon:
|
||||||
Dispatcher.UIThread.Post(() =>
|
Dispatcher.UIThread.Post(() =>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
|
using System.Reactive.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
|
@ -36,7 +37,6 @@ public partial class MainWindow
|
||||||
menuCheckUpdate.Click += MenuCheckUpdate_Click;
|
menuCheckUpdate.Click += MenuCheckUpdate_Click;
|
||||||
menuBackupAndRestore.Click += MenuBackupAndRestore_Click;
|
menuBackupAndRestore.Click += MenuBackupAndRestore_Click;
|
||||||
|
|
||||||
MessageBus.Current.Listen<string>(EMsgCommand.SendSnackMsg.ToString()).Subscribe(DelegateSnackMsg);
|
|
||||||
ViewModel = new MainWindowViewModel(UpdateViewHandler);
|
ViewModel = new MainWindowViewModel(UpdateViewHandler);
|
||||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(MainWindowViewModel));
|
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(MainWindowViewModel));
|
||||||
|
|
||||||
|
|
@ -133,6 +133,18 @@ public partial class MainWindow
|
||||||
this.Bind(ViewModel, vm => vm.TabMainSelectedIndex, v => v.tabMain2.SelectedIndex).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.TabMainSelectedIndex, v => v.tabMain2.SelectedIndex).DisposeWith(disposables);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AppEvents.SendSnackMsgRequested
|
||||||
|
.AsObservable()
|
||||||
|
.ObserveOn(RxApp.MainThreadScheduler)
|
||||||
|
.Subscribe(async content => await DelegateSnackMsg(content))
|
||||||
|
.DisposeWith(disposables);
|
||||||
|
|
||||||
|
AppEvents.AppExitRequested
|
||||||
|
.AsObservable()
|
||||||
|
.ObserveOn(RxApp.MainThreadScheduler)
|
||||||
|
.Subscribe(_ => StorageUI())
|
||||||
|
.DisposeWith(disposables);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.Title = $"{Utils.GetVersion()} - {(Utils.IsAdministrator() ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";
|
this.Title = $"{Utils.GetVersion()} - {(Utils.IsAdministrator() ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";
|
||||||
|
|
@ -144,7 +156,6 @@ public partial class MainWindow
|
||||||
|
|
||||||
AddHelpMenuItem();
|
AddHelpMenuItem();
|
||||||
WindowsManager.Instance.RegisterGlobalHotkey(_config, OnHotkeyHandler, null);
|
WindowsManager.Instance.RegisterGlobalHotkey(_config, OnHotkeyHandler, null);
|
||||||
MessageBus.Current.Listen<string>(EMsgCommand.AppExit.ToString()).Subscribe(StorageUI);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Event
|
#region Event
|
||||||
|
|
@ -157,12 +168,9 @@ public partial class MainWindow
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DelegateSnackMsg(string content)
|
private async Task DelegateSnackMsg(string content)
|
||||||
{
|
{
|
||||||
Application.Current?.Dispatcher.Invoke((() =>
|
MainSnackbar.MessageQueue?.Enqueue(content);
|
||||||
{
|
|
||||||
MainSnackbar.MessageQueue?.Enqueue(content);
|
|
||||||
}), DispatcherPriority.Normal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
|
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
|
||||||
|
|
@ -423,7 +431,7 @@ public partial class MainWindow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StorageUI(string? n = null)
|
private void StorageUI()
|
||||||
{
|
{
|
||||||
ConfigHandler.SaveWindowSizeItem(_config, GetType().Name, Width, Height);
|
ConfigHandler.SaveWindowSizeItem(_config, GetType().Name, Width, Height);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
|
using System.Reactive.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Controls.Primitives;
|
using System.Windows.Controls.Primitives;
|
||||||
|
|
@ -90,11 +91,16 @@ public partial class ProfilesView
|
||||||
this.BindCommand(ViewModel, vm => vm.Export2ClientConfigClipboardCmd, v => v.menuExport2ClientConfigClipboard).DisposeWith(disposables);
|
this.BindCommand(ViewModel, vm => vm.Export2ClientConfigClipboardCmd, v => v.menuExport2ClientConfigClipboard).DisposeWith(disposables);
|
||||||
this.BindCommand(ViewModel, vm => vm.Export2ShareUrlCmd, v => v.menuExport2ShareUrl).DisposeWith(disposables);
|
this.BindCommand(ViewModel, vm => vm.Export2ShareUrlCmd, v => v.menuExport2ShareUrl).DisposeWith(disposables);
|
||||||
this.BindCommand(ViewModel, vm => vm.Export2ShareUrlBase64Cmd, v => v.menuExport2ShareUrlBase64).DisposeWith(disposables);
|
this.BindCommand(ViewModel, vm => vm.Export2ShareUrlBase64Cmd, v => v.menuExport2ShareUrlBase64).DisposeWith(disposables);
|
||||||
|
|
||||||
|
AppEvents.AppExitRequested
|
||||||
|
.AsObservable()
|
||||||
|
.ObserveOn(RxApp.MainThreadScheduler)
|
||||||
|
.Subscribe(_ => StorageUI())
|
||||||
|
.DisposeWith(disposables);
|
||||||
});
|
});
|
||||||
|
|
||||||
RestoreUI();
|
RestoreUI();
|
||||||
ViewModel?.RefreshServers();
|
ViewModel?.RefreshServers();
|
||||||
MessageBus.Current.Listen<string>(EMsgCommand.AppExit.ToString()).Subscribe(StorageUI);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Event
|
#region Event
|
||||||
|
|
@ -168,10 +174,7 @@ public partial class ProfilesView
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EViewAction.DispatcherRefreshServersBiz:
|
case EViewAction.DispatcherRefreshServersBiz:
|
||||||
Application.Current?.Dispatcher.Invoke((() =>
|
Application.Current?.Dispatcher.Invoke(RefreshServersBiz, DispatcherPriority.Normal);
|
||||||
{
|
|
||||||
_ = RefreshServersBiz();
|
|
||||||
}), DispatcherPriority.Normal);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -190,13 +193,8 @@ public partial class ProfilesView
|
||||||
await DialogHost.Show(dialog, "RootDialog");
|
await DialogHost.Show(dialog, "RootDialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RefreshServersBiz()
|
public void RefreshServersBiz()
|
||||||
{
|
{
|
||||||
if (ViewModel != null)
|
|
||||||
{
|
|
||||||
await ViewModel.RefreshServersBiz();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lstProfiles.SelectedIndex > 0)
|
if (lstProfiles.SelectedIndex > 0)
|
||||||
{
|
{
|
||||||
lstProfiles.ScrollIntoView(lstProfiles.SelectedItem, null);
|
lstProfiles.ScrollIntoView(lstProfiles.SelectedItem, null);
|
||||||
|
|
@ -377,7 +375,7 @@ public partial class ProfilesView
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StorageUI(string? n = null)
|
private void StorageUI()
|
||||||
{
|
{
|
||||||
List<ColumnItem> lvColumnItem = new();
|
List<ColumnItem> lvColumnItem = new();
|
||||||
foreach (var t in lstProfiles.Columns)
|
foreach (var t in lstProfiles.Columns)
|
||||||
|
|
|
||||||
|
|
@ -86,12 +86,7 @@ public partial class StatusBarView
|
||||||
}), DispatcherPriority.Normal);
|
}), DispatcherPriority.Normal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EViewAction.DispatcherRefreshServersBiz:
|
|
||||||
Application.Current?.Dispatcher.Invoke((() =>
|
|
||||||
{
|
|
||||||
ViewModel?.RefreshServersBiz();
|
|
||||||
}), DispatcherPriority.Normal);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EViewAction.DispatcherRefreshIcon:
|
case EViewAction.DispatcherRefreshIcon:
|
||||||
Application.Current?.Dispatcher.Invoke((async () =>
|
Application.Current?.Dispatcher.Invoke((async () =>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue