diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index 7977bce2..3d6e4ee9 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -14,6 +14,7 @@ namespace ServiceLib.ViewModels #region private prop private CoreHandler _coreHandler; + private bool _isAdministrator { get; set; } #endregion private prop @@ -139,17 +140,16 @@ namespace ServiceLib.ViewModels [Reactive] public int TabMainSelectedIndex { get; set; } - public bool IsAdministrator { get; set; } - #endregion UI #region Init - public MainWindowViewModel(Func>? updateView) + public MainWindowViewModel(bool isAdministrator, Func>? updateView) { _config = LazyConfig.Instance.Config; _noticeHandler = Locator.Current.GetService(); _updateView = updateView; + _isAdministrator = isAdministrator; MessageBus.Current.Listen(Global.CommandRefreshProfiles).Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null)); @@ -158,6 +158,16 @@ namespace ServiceLib.ViewModels Init(); + _config.uiItem.showInTaskbar = true; + if (_config.tunModeItem.enableTun && _isAdministrator) + { + EnableTun = true; + } + else + { + _config.tunModeItem.enableTun = EnableTun = false; + } + #region WhenAnyValue && ReactiveCommand this.WhenAnyValue( @@ -319,8 +329,6 @@ namespace ServiceLib.ViewModels #endregion WhenAnyValue && ReactiveCommand AutoHideStartup(); - - _config.uiItem.showInTaskbar = true; } private void Init() @@ -853,12 +861,13 @@ namespace ServiceLib.ViewModels { _config.tunModeItem.enableTun = EnableTun; // When running as a non-administrator, reboot to administrator mode - if (EnableTun && !IsAdministrator) + if (EnableTun && !_isAdministrator) { _config.tunModeItem.enableTun = false; RebootAsAdmin(); return; } + ConfigHandler.SaveConfig(_config); Reload(); } } diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index d0f31977..65fefdf5 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -34,8 +34,9 @@ namespace v2rayN.Desktop.Views menuPromotion.Click += menuPromotion_Click; menuClose.Click += menuClose_Click; + var IsAdministrator = true;//WindowsUtils.IsAdministrator(); MessageBus.Current.Listen(Global.CommandSendSnackMsg).Subscribe(x => DelegateSnackMsg(x)); - ViewModel = new MainWindowViewModel(UpdateViewHandler); + ViewModel = new MainWindowViewModel(IsAdministrator, UpdateViewHandler); Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(MainWindowViewModel)); //WindowsHandler.Instance.RegisterGlobalHotkey(_config, OnHotkeyHandler, null); @@ -114,24 +115,10 @@ namespace v2rayN.Desktop.Views if (Utils.IsWindows()) { - var IsAdministrator = false;//WindowsUtils.IsAdministrator(); - ViewModel.IsAdministrator = IsAdministrator; this.Title = $"{Utils.GetVersion()} - {(IsAdministrator ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}"; - if (_config.tunModeItem.enableTun) - { - if (IsAdministrator) - { - ViewModel.EnableTun = true; - } - else - { - _config.tunModeItem.enableTun = ViewModel.EnableTun = false; - } - } } else { - ViewModel.IsAdministrator = true; this.Title = $"{Utils.GetVersion()}"; menuRebootAsAdmin.IsVisible = false; menuSettingsSetUWP.IsVisible = false; diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index a72718bb..8fdbb166 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -36,8 +36,9 @@ namespace v2rayN.Views menuCheckUpdate.Click += MenuCheckUpdate_Click; menuBackupAndRestore.Click += MenuBackupAndRestore_Click; + var IsAdministrator = WindowsUtils.IsAdministrator(); MessageBus.Current.Listen(Global.CommandSendSnackMsg).Subscribe(x => DelegateSnackMsg(x)); - ViewModel = new MainWindowViewModel(UpdateViewHandler); + ViewModel = new MainWindowViewModel(IsAdministrator, UpdateViewHandler); Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(MainWindowViewModel)); WindowsHandler.Instance.RegisterGlobalHotkey(_config, OnHotkeyHandler, null); @@ -143,21 +144,8 @@ namespace v2rayN.Views } }); - var IsAdministrator = WindowsUtils.IsAdministrator(); - ViewModel.IsAdministrator = IsAdministrator; this.Title = $"{Utils.GetVersion()} - {(IsAdministrator ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}"; - if (_config.tunModeItem.enableTun) - { - if (IsAdministrator) - { - ViewModel.EnableTun = true; - } - else - { - _config.tunModeItem.enableTun = ViewModel.EnableTun = false; - } - } - + if (!_config.guiItem.enableHWA) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;