diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs
index c0d3f60e..45fdab2f 100644
--- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs
+++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs
@@ -870,6 +870,15 @@ namespace ServiceLib.Resx {
}
}
+ ///
+ /// 查找类似 Are you sure to exit? 的本地化字符串。
+ ///
+ public static string menuExitTips {
+ get {
+ return ResourceManager.GetString("menuExitTips", resourceCulture);
+ }
+ }
+
///
/// 查找类似 Export selected server for complete configuration 的本地化字符串。
///
diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx
index 93b3bcdb..2b3ea353 100644
--- a/v2rayN/ServiceLib/Resx/ResUI.resx
+++ b/v2rayN/ServiceLib/Resx/ResUI.resx
@@ -1363,4 +1363,7 @@
Install the font to the system and restart the settings
+
+ Are you sure to exit?
+
\ No newline at end of file
diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
index 318e1239..304bb387 100644
--- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
+++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
@@ -1360,4 +1360,7 @@
安装字体到系统中,重启设置
+
+ 是否确定退出?
+
\ No newline at end of file
diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
index f677ea4c..78113195 100644
--- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
+++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
@@ -1240,4 +1240,7 @@
安裝字體到系統中,重新啟動設定
+
+ 是否確定退出?
+
\ No newline at end of file
diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
index dc0b6bfe..9d254556 100644
--- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
@@ -52,6 +52,8 @@ namespace ServiceLib.ViewModels
public ReactiveCommand ReloadCmd { get; }
+ public ReactiveCommand 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
diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml
index 6dd66d40..d927b846 100644
--- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml
+++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml
@@ -114,7 +114,7 @@
diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs
index 12cefcae..d8e7867e 100644
--- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs
+++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs
@@ -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;
@@ -28,12 +29,11 @@ namespace v2rayN.Desktop.Views
_config = AppHandler.Instance.Config;
_manager = new WindowNotificationManager(TopLevel.GetTopLevel(this)) { MaxItems = 3, Position = NotificationPosition.BottomRight };
-
+
this.Closing += MainWindow_Closing;
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()?.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}");
@@ -376,8 +379,16 @@ namespace v2rayN.Desktop.Views
}
else
{
- this.Hide();
+ if (Utils.IsWindows())
+ {
+ this.Hide();
+ }
+ else
+ {
+ this.WindowState = WindowState.Minimized;
+ }
}
+
_config.UiItem.ShowInTaskbar = bl;
}
diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs
index c323486b..e9a18a73 100644
--- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs
+++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs
@@ -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;
}