mirror of https://github.com/2dust/v2rayN
parent
97347674e7
commit
054f0f2bc7
|
@ -14,6 +14,7 @@ namespace ServiceLib.ViewModels
|
||||||
#region private prop
|
#region private prop
|
||||||
|
|
||||||
private CoreHandler _coreHandler;
|
private CoreHandler _coreHandler;
|
||||||
|
private bool _isAdministrator { get; set; }
|
||||||
|
|
||||||
#endregion private prop
|
#endregion private prop
|
||||||
|
|
||||||
|
@ -139,17 +140,16 @@ namespace ServiceLib.ViewModels
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public int TabMainSelectedIndex { get; set; }
|
public int TabMainSelectedIndex { get; set; }
|
||||||
|
|
||||||
public bool IsAdministrator { get; set; }
|
|
||||||
|
|
||||||
#endregion UI
|
#endregion UI
|
||||||
|
|
||||||
#region Init
|
#region Init
|
||||||
|
|
||||||
public MainWindowViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
|
public MainWindowViewModel(bool isAdministrator, Func<EViewAction, object?, Task<bool>>? updateView)
|
||||||
{
|
{
|
||||||
_config = LazyConfig.Instance.Config;
|
_config = LazyConfig.Instance.Config;
|
||||||
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
|
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
|
||||||
_updateView = updateView;
|
_updateView = updateView;
|
||||||
|
_isAdministrator = isAdministrator;
|
||||||
|
|
||||||
MessageBus.Current.Listen<string>(Global.CommandRefreshProfiles).Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null));
|
MessageBus.Current.Listen<string>(Global.CommandRefreshProfiles).Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null));
|
||||||
|
|
||||||
|
@ -158,6 +158,16 @@ namespace ServiceLib.ViewModels
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
|
_config.uiItem.showInTaskbar = true;
|
||||||
|
if (_config.tunModeItem.enableTun && _isAdministrator)
|
||||||
|
{
|
||||||
|
EnableTun = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_config.tunModeItem.enableTun = EnableTun = false;
|
||||||
|
}
|
||||||
|
|
||||||
#region WhenAnyValue && ReactiveCommand
|
#region WhenAnyValue && ReactiveCommand
|
||||||
|
|
||||||
this.WhenAnyValue(
|
this.WhenAnyValue(
|
||||||
|
@ -319,8 +329,6 @@ namespace ServiceLib.ViewModels
|
||||||
#endregion WhenAnyValue && ReactiveCommand
|
#endregion WhenAnyValue && ReactiveCommand
|
||||||
|
|
||||||
AutoHideStartup();
|
AutoHideStartup();
|
||||||
|
|
||||||
_config.uiItem.showInTaskbar = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Init()
|
private void Init()
|
||||||
|
@ -853,12 +861,13 @@ namespace ServiceLib.ViewModels
|
||||||
{
|
{
|
||||||
_config.tunModeItem.enableTun = EnableTun;
|
_config.tunModeItem.enableTun = EnableTun;
|
||||||
// When running as a non-administrator, reboot to administrator mode
|
// When running as a non-administrator, reboot to administrator mode
|
||||||
if (EnableTun && !IsAdministrator)
|
if (EnableTun && !_isAdministrator)
|
||||||
{
|
{
|
||||||
_config.tunModeItem.enableTun = false;
|
_config.tunModeItem.enableTun = false;
|
||||||
RebootAsAdmin();
|
RebootAsAdmin();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ConfigHandler.SaveConfig(_config);
|
||||||
Reload();
|
Reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,9 @@ namespace v2rayN.Desktop.Views
|
||||||
menuPromotion.Click += menuPromotion_Click;
|
menuPromotion.Click += menuPromotion_Click;
|
||||||
menuClose.Click += menuClose_Click;
|
menuClose.Click += menuClose_Click;
|
||||||
|
|
||||||
|
var IsAdministrator = true;//WindowsUtils.IsAdministrator();
|
||||||
MessageBus.Current.Listen<string>(Global.CommandSendSnackMsg).Subscribe(x => DelegateSnackMsg(x));
|
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));
|
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(MainWindowViewModel));
|
||||||
|
|
||||||
//WindowsHandler.Instance.RegisterGlobalHotkey(_config, OnHotkeyHandler, null);
|
//WindowsHandler.Instance.RegisterGlobalHotkey(_config, OnHotkeyHandler, null);
|
||||||
|
@ -114,24 +115,10 @@ namespace v2rayN.Desktop.Views
|
||||||
|
|
||||||
if (Utils.IsWindows())
|
if (Utils.IsWindows())
|
||||||
{
|
{
|
||||||
var IsAdministrator = false;//WindowsUtils.IsAdministrator();
|
|
||||||
ViewModel.IsAdministrator = IsAdministrator;
|
|
||||||
this.Title = $"{Utils.GetVersion()} - {(IsAdministrator ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";
|
this.Title = $"{Utils.GetVersion()} - {(IsAdministrator ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";
|
||||||
if (_config.tunModeItem.enableTun)
|
|
||||||
{
|
|
||||||
if (IsAdministrator)
|
|
||||||
{
|
|
||||||
ViewModel.EnableTun = true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_config.tunModeItem.enableTun = ViewModel.EnableTun = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ViewModel.IsAdministrator = true;
|
|
||||||
this.Title = $"{Utils.GetVersion()}";
|
this.Title = $"{Utils.GetVersion()}";
|
||||||
menuRebootAsAdmin.IsVisible = false;
|
menuRebootAsAdmin.IsVisible = false;
|
||||||
menuSettingsSetUWP.IsVisible = false;
|
menuSettingsSetUWP.IsVisible = false;
|
||||||
|
|
|
@ -36,8 +36,9 @@ namespace v2rayN.Views
|
||||||
menuCheckUpdate.Click += MenuCheckUpdate_Click;
|
menuCheckUpdate.Click += MenuCheckUpdate_Click;
|
||||||
menuBackupAndRestore.Click += MenuBackupAndRestore_Click;
|
menuBackupAndRestore.Click += MenuBackupAndRestore_Click;
|
||||||
|
|
||||||
|
var IsAdministrator = WindowsUtils.IsAdministrator();
|
||||||
MessageBus.Current.Listen<string>(Global.CommandSendSnackMsg).Subscribe(x => DelegateSnackMsg(x));
|
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));
|
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(MainWindowViewModel));
|
||||||
|
|
||||||
WindowsHandler.Instance.RegisterGlobalHotkey(_config, OnHotkeyHandler, null);
|
WindowsHandler.Instance.RegisterGlobalHotkey(_config, OnHotkeyHandler, null);
|
||||||
|
@ -143,20 +144,7 @@ namespace v2rayN.Views
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var IsAdministrator = WindowsUtils.IsAdministrator();
|
|
||||||
ViewModel.IsAdministrator = IsAdministrator;
|
|
||||||
this.Title = $"{Utils.GetVersion()} - {(IsAdministrator ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";
|
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)
|
if (!_config.guiItem.enableHWA)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue