2dust 2 months ago
parent
commit
054f0f2bc7
  1. 21
      v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
  2. 17
      v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs
  3. 18
      v2rayN/v2rayN/Views/MainWindow.xaml.cs

21
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<EViewAction, object?, Task<bool>>? updateView)
public MainWindowViewModel(bool isAdministrator, Func<EViewAction, object?, Task<bool>>? updateView)
{
_config = LazyConfig.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView;
_isAdministrator = isAdministrator;
MessageBus.Current.Listen<string>(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();
}
}

17
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<string>(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;

18
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<string>(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;

Loading…
Cancel
Save