Add AppViewModel for Desktop
This commit is contained in:
51
v2rayN/v2rayN.Desktop/ViewModels/AppViewModel.cs
Normal file
51
v2rayN/v2rayN.Desktop/ViewModels/AppViewModel.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using ReactiveUI;
|
||||
using Splat;
|
||||
using System.Reactive;
|
||||
using v2rayN.Desktop.Common;
|
||||
|
||||
namespace v2rayN.Desktop.ViewModels
|
||||
{
|
||||
public class AppViewModel : MyReactiveObject
|
||||
{
|
||||
public ReactiveCommand<Unit, Unit> AddServerViaClipboardCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> SubUpdateCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> SubUpdateViaProxyCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> ExitCmd { get; }
|
||||
|
||||
public AppViewModel()
|
||||
{
|
||||
_config = LazyConfig.Instance.Config;
|
||||
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
|
||||
|
||||
AddServerViaClipboardCmd = ReactiveCommand.Create(() =>
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
var clipboardData = AvaUtils.GetClipboardData(desktop.MainWindow).Result;
|
||||
Locator.Current.GetService<MainWindowViewModel>()?.AddServerViaClipboardAsync(clipboardData);
|
||||
}
|
||||
});
|
||||
|
||||
SubUpdateCmd = ReactiveCommand.Create(() =>
|
||||
{
|
||||
Locator.Current.GetService<MainWindowViewModel>()?.UpdateSubscriptionProcess("", false);
|
||||
});
|
||||
SubUpdateViaProxyCmd = ReactiveCommand.Create(() =>
|
||||
{
|
||||
Locator.Current.GetService<MainWindowViewModel>()?.UpdateSubscriptionProcess("", true);
|
||||
});
|
||||
|
||||
ExitCmd = ReactiveCommand.Create(() =>
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
Locator.Current.GetService<MainWindowViewModel>()?.MyAppExitAsync(false);
|
||||
|
||||
desktop.Shutdown();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user