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>
|
||||
/// 查找类似 Export selected server for complete configuration 的本地化字符串。
|
||||
/// </summary>
|
||||
|
|
|
@ -1363,4 +1363,7 @@
|
|||
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
||||
<value>Install the font to the system and restart the settings</value>
|
||||
</data>
|
||||
<data name="menuExitTips" xml:space="preserve">
|
||||
<value>Are you sure to exit?</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1360,4 +1360,7 @@
|
|||
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
||||
<value>安装字体到系统中,重启设置</value>
|
||||
</data>
|
||||
<data name="menuExitTips" xml:space="preserve">
|
||||
<value>是否确定退出?</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1240,4 +1240,7 @@
|
|||
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
||||
<value>安裝字體到系統中,重新啟動設定</value>
|
||||
</data>
|
||||
<data name="menuExitTips" xml:space="preserve">
|
||||
<value>是否確定退出?</value>
|
||||
</data>
|
||||
</root>
|
|
@ -52,6 +52,8 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
public ReactiveCommand<Unit, Unit> ReloadCmd { get; }
|
||||
|
||||
public ReactiveCommand<Unit, Unit> ExitCmd { get; }
|
||||
|
||||
[Reactive]
|
||||
public bool BlReloadEnabled { get; set; }
|
||||
|
||||
|
@ -187,6 +189,11 @@ namespace ServiceLib.ViewModels
|
|||
await Reload();
|
||||
});
|
||||
|
||||
ExitCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||
{
|
||||
await Exit();
|
||||
});
|
||||
|
||||
RegionalPresetDefaultCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||
{
|
||||
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
|
||||
|
||||
#region Presets
|
||||
|
|
|
@ -114,7 +114,7 @@
|
|||
<MenuItem x:Name="menuClose" Padding="8,0">
|
||||
<MenuItem.Header>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{x:Static resx:ResUI.menuClose}" />
|
||||
<TextBlock Text="{x:Static resx:ResUI.menuExit}" />
|
||||
</StackPanel>
|
||||
</MenuItem.Header>
|
||||
</MenuItem>
|
||||
|
|
|
@ -7,6 +7,7 @@ using Avalonia.Interactivity;
|
|||
using Avalonia.ReactiveUI;
|
||||
using Avalonia.Threading;
|
||||
using DialogHostAvalonia;
|
||||
using MsBox.Avalonia.Enums;
|
||||
using ReactiveUI;
|
||||
using Splat;
|
||||
using System.ComponentModel;
|
||||
|
@ -33,7 +34,6 @@ namespace v2rayN.Desktop.Views
|
|||
this.KeyDown += MainWindow_KeyDown;
|
||||
menuSettingsSetUWP.Click += menuSettingsSetUWP_Click;
|
||||
menuPromotion.Click += menuPromotion_Click;
|
||||
menuClose.Click += menuClose_Click;
|
||||
menuCheckUpdate.Click += MenuCheckUpdate_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.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)
|
||||
{
|
||||
|
@ -242,6 +243,14 @@ namespace v2rayN.Desktop.Views
|
|||
Locator.Current.GetService<ProfilesViewModel>()?.AutofitColumnWidthAsync(),
|
||||
DispatcherPriority.Default);
|
||||
break;
|
||||
|
||||
case EViewAction.ShowYesNo:
|
||||
if (await UI.ShowYesNo(this, ResUI.menuExitTips) == ButtonResult.No)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
StorageUI();
|
||||
break;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Utils.ProcessStart($"{Utils.Base64Decode(Global.PromotionUrl)}?t={DateTime.Now.Ticks}");
|
||||
|
@ -375,9 +378,17 @@ namespace v2rayN.Desktop.Views
|
|||
this.Focus();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Utils.IsWindows())
|
||||
{
|
||||
this.Hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.WindowState = WindowState.Minimized;
|
||||
}
|
||||
}
|
||||
|
||||
_config.UiItem.ShowInTaskbar = bl;
|
||||
}
|
||||
|
||||
|
|
|
@ -367,17 +367,17 @@ namespace v2rayN.Views
|
|||
var bl = blShow ?? !_config.UiItem.ShowInTaskbar;
|
||||
if (bl)
|
||||
{
|
||||
Application.Current.MainWindow.Show();
|
||||
if (Application.Current.MainWindow.WindowState == WindowState.Minimized)
|
||||
this?.Show();
|
||||
if (this?.WindowState == WindowState.Minimized)
|
||||
{
|
||||
Application.Current.MainWindow.WindowState = WindowState.Normal;
|
||||
this.WindowState = WindowState.Normal;
|
||||
}
|
||||
Application.Current.MainWindow.Activate();
|
||||
Application.Current.MainWindow.Focus();
|
||||
this?.Activate();
|
||||
this?.Focus();
|
||||
}
|
||||
else
|
||||
{
|
||||
Application.Current.MainWindow.Hide();
|
||||
this?.Hide();
|
||||
}
|
||||
_config.UiItem.ShowInTaskbar = bl;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue