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 AddServerViaClipboardCmd { get; } public ReactiveCommand SubUpdateCmd { get; } public ReactiveCommand SubUpdateViaProxyCmd { get; } public ReactiveCommand ExitCmd { get; } public AppViewModel() { _config = LazyConfig.Instance.Config; _noticeHandler = Locator.Current.GetService(); AddServerViaClipboardCmd = ReactiveCommand.Create(() => { if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { var clipboardData = AvaUtils.GetClipboardData(desktop.MainWindow).Result; Locator.Current.GetService()?.AddServerViaClipboardAsync(clipboardData); } }); SubUpdateCmd = ReactiveCommand.Create(() => { Locator.Current.GetService()?.UpdateSubscriptionProcess("", false); }); SubUpdateViaProxyCmd = ReactiveCommand.Create(() => { Locator.Current.GetService()?.UpdateSubscriptionProcess("", true); }); ExitCmd = ReactiveCommand.Create(() => { if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { Locator.Current.GetService()?.MyAppExitAsync(false); desktop.Shutdown(); } }); } } }