Browse Source

Add exit function to the main interface for Desktop

pull/5983/head
2dust 3 weeks ago
parent
commit
258e822c13
  1. 9
      v2rayN/ServiceLib/Resx/ResUI.Designer.cs
  2. 3
      v2rayN/ServiceLib/Resx/ResUI.resx
  3. 3
      v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
  4. 3
      v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
  5. 17
      v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
  6. 2
      v2rayN/v2rayN.Desktop/Views/MainWindow.axaml
  7. 29
      v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs
  8. 12
      v2rayN/v2rayN/Views/MainWindow.xaml.cs

9
v2rayN/ServiceLib/Resx/ResUI.Designer.cs generated

@ -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>

3
v2rayN/ServiceLib/Resx/ResUI.resx

@ -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>

3
v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx

@ -1360,4 +1360,7 @@
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
<value>安装字体到系统中,重启设置</value>
</data>
<data name="menuExitTips" xml:space="preserve">
<value>是否确定退出?</value>
</data>
</root>

3
v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx

@ -1240,4 +1240,7 @@
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
<value>安裝字體到系統中,重新啟動設定</value>
</data>
<data name="menuExitTips" xml:space="preserve">
<value>是否確定退出?</value>
</data>
</root>

17
v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs

@ -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

2
v2rayN/v2rayN.Desktop/Views/MainWindow.axaml

@ -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>

29
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<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}");
@ -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;
}

12
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;
}

Loading…
Cancel
Save