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