mirror of https://github.com/2dust/v2rayN
Add exit function to the main interface for Desktop
parent
4f05b93d63
commit
258e822c13
|
@ -870,6 +870,15 @@ namespace ServiceLib.Resx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 Are you sure to exit? 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string menuExitTips {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("menuExitTips", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Export selected server for complete configuration 的本地化字符串。
|
/// 查找类似 Export selected server for complete configuration 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -1363,4 +1363,7 @@
|
||||||
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
||||||
<value>Install the font to the system and restart the settings</value>
|
<value>Install the font to the system and restart the settings</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="menuExitTips" xml:space="preserve">
|
||||||
|
<value>Are you sure to exit?</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -1360,4 +1360,7 @@
|
||||||
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
||||||
<value>安装字体到系统中,重启设置</value>
|
<value>安装字体到系统中,重启设置</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="menuExitTips" xml:space="preserve">
|
||||||
|
<value>是否确定退出?</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -1240,4 +1240,7 @@
|
||||||
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
||||||
<value>安裝字體到系統中,重新啟動設定</value>
|
<value>安裝字體到系統中,重新啟動設定</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="menuExitTips" xml:space="preserve">
|
||||||
|
<value>是否確定退出?</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -52,6 +52,8 @@ namespace ServiceLib.ViewModels
|
||||||
|
|
||||||
public ReactiveCommand<Unit, Unit> ReloadCmd { get; }
|
public ReactiveCommand<Unit, Unit> ReloadCmd { get; }
|
||||||
|
|
||||||
|
public ReactiveCommand<Unit, Unit> ExitCmd { get; }
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public bool BlReloadEnabled { get; set; }
|
public bool BlReloadEnabled { get; set; }
|
||||||
|
|
||||||
|
@ -187,6 +189,11 @@ namespace ServiceLib.ViewModels
|
||||||
await Reload();
|
await Reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ExitCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
|
{
|
||||||
|
await Exit();
|
||||||
|
});
|
||||||
|
|
||||||
RegionalPresetDefaultCmd = ReactiveCommand.CreateFromTask(async () =>
|
RegionalPresetDefaultCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||||
{
|
{
|
||||||
await ApplyRegionalPreset(EPresetType.Default);
|
await ApplyRegionalPreset(EPresetType.Default);
|
||||||
|
@ -588,6 +595,16 @@ namespace ServiceLib.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task Exit()
|
||||||
|
{
|
||||||
|
if (await _updateView?.Invoke(EViewAction.ShowYesNo, null) == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await MyAppExitAsync(false);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion core job
|
#endregion core job
|
||||||
|
|
||||||
#region Presets
|
#region Presets
|
||||||
|
|
|
@ -114,7 +114,7 @@
|
||||||
<MenuItem x:Name="menuClose" Padding="8,0">
|
<MenuItem x:Name="menuClose" Padding="8,0">
|
||||||
<MenuItem.Header>
|
<MenuItem.Header>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<TextBlock Text="{x:Static resx:ResUI.menuClose}" />
|
<TextBlock Text="{x:Static resx:ResUI.menuExit}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</MenuItem.Header>
|
</MenuItem.Header>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
|
@ -7,6 +7,7 @@ using Avalonia.Interactivity;
|
||||||
using Avalonia.ReactiveUI;
|
using Avalonia.ReactiveUI;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using DialogHostAvalonia;
|
using DialogHostAvalonia;
|
||||||
|
using MsBox.Avalonia.Enums;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using Splat;
|
using Splat;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
@ -28,12 +29,11 @@ namespace v2rayN.Desktop.Views
|
||||||
|
|
||||||
_config = AppHandler.Instance.Config;
|
_config = AppHandler.Instance.Config;
|
||||||
_manager = new WindowNotificationManager(TopLevel.GetTopLevel(this)) { MaxItems = 3, Position = NotificationPosition.BottomRight };
|
_manager = new WindowNotificationManager(TopLevel.GetTopLevel(this)) { MaxItems = 3, Position = NotificationPosition.BottomRight };
|
||||||
|
|
||||||
this.Closing += MainWindow_Closing;
|
this.Closing += MainWindow_Closing;
|
||||||
this.KeyDown += MainWindow_KeyDown;
|
this.KeyDown += MainWindow_KeyDown;
|
||||||
menuSettingsSetUWP.Click += menuSettingsSetUWP_Click;
|
menuSettingsSetUWP.Click += menuSettingsSetUWP_Click;
|
||||||
menuPromotion.Click += menuPromotion_Click;
|
menuPromotion.Click += menuPromotion_Click;
|
||||||
menuClose.Click += menuClose_Click;
|
|
||||||
menuCheckUpdate.Click += MenuCheckUpdate_Click;
|
menuCheckUpdate.Click += MenuCheckUpdate_Click;
|
||||||
menuBackupAndRestore.Click += MenuBackupAndRestore_Click;
|
menuBackupAndRestore.Click += MenuBackupAndRestore_Click;
|
||||||
|
|
||||||
|
@ -80,6 +80,7 @@ namespace v2rayN.Desktop.Views
|
||||||
|
|
||||||
this.BindCommand(ViewModel, vm => vm.ReloadCmd, v => v.menuReload).DisposeWith(disposables);
|
this.BindCommand(ViewModel, vm => vm.ReloadCmd, v => v.menuReload).DisposeWith(disposables);
|
||||||
this.OneWayBind(ViewModel, vm => vm.BlReloadEnabled, v => v.menuReload.IsEnabled).DisposeWith(disposables);
|
this.OneWayBind(ViewModel, vm => vm.BlReloadEnabled, v => v.menuReload.IsEnabled).DisposeWith(disposables);
|
||||||
|
this.BindCommand(ViewModel, vm => vm.ExitCmd, v => v.menuClose).DisposeWith(disposables);
|
||||||
|
|
||||||
switch (_config.UiItem.MainGirdOrientation)
|
switch (_config.UiItem.MainGirdOrientation)
|
||||||
{
|
{
|
||||||
|
@ -242,6 +243,14 @@ namespace v2rayN.Desktop.Views
|
||||||
Locator.Current.GetService<ProfilesViewModel>()?.AutofitColumnWidthAsync(),
|
Locator.Current.GetService<ProfilesViewModel>()?.AutofitColumnWidthAsync(),
|
||||||
DispatcherPriority.Default);
|
DispatcherPriority.Default);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case EViewAction.ShowYesNo:
|
||||||
|
if (await UI.ShowYesNo(this, ResUI.menuExitTips) == ButtonResult.No)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
StorageUI();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await Task.FromResult(true);
|
return await Task.FromResult(true);
|
||||||
|
@ -304,12 +313,6 @@ namespace v2rayN.Desktop.Views
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void menuClose_Click(object? sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
StorageUI();
|
|
||||||
ShowHideWindow(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void menuPromotion_Click(object? sender, RoutedEventArgs e)
|
private void menuPromotion_Click(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Utils.ProcessStart($"{Utils.Base64Decode(Global.PromotionUrl)}?t={DateTime.Now.Ticks}");
|
Utils.ProcessStart($"{Utils.Base64Decode(Global.PromotionUrl)}?t={DateTime.Now.Ticks}");
|
||||||
|
@ -376,8 +379,16 @@ namespace v2rayN.Desktop.Views
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.Hide();
|
if (Utils.IsWindows())
|
||||||
|
{
|
||||||
|
this.Hide();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.WindowState = WindowState.Minimized;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_config.UiItem.ShowInTaskbar = bl;
|
_config.UiItem.ShowInTaskbar = bl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -367,17 +367,17 @@ namespace v2rayN.Views
|
||||||
var bl = blShow ?? !_config.UiItem.ShowInTaskbar;
|
var bl = blShow ?? !_config.UiItem.ShowInTaskbar;
|
||||||
if (bl)
|
if (bl)
|
||||||
{
|
{
|
||||||
Application.Current.MainWindow.Show();
|
this?.Show();
|
||||||
if (Application.Current.MainWindow.WindowState == WindowState.Minimized)
|
if (this?.WindowState == WindowState.Minimized)
|
||||||
{
|
{
|
||||||
Application.Current.MainWindow.WindowState = WindowState.Normal;
|
this.WindowState = WindowState.Normal;
|
||||||
}
|
}
|
||||||
Application.Current.MainWindow.Activate();
|
this?.Activate();
|
||||||
Application.Current.MainWindow.Focus();
|
this?.Focus();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Application.Current.MainWindow.Hide();
|
this?.Hide();
|
||||||
}
|
}
|
||||||
_config.UiItem.ShowInTaskbar = bl;
|
_config.UiItem.ShowInTaskbar = bl;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue