forked from 2dust/v2rayN
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
62 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
}); | ||
} | ||
} | ||
} |