mirror of https://github.com/2dust/v2rayN
2dust
2 months ago
3 changed files with 62 additions and 37 deletions
@ -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(); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue