mirror of
https://github.com/2dust/v2rayN.git
synced 2025-04-19 21:52:25 +00:00
parent
e530789739
commit
4eb443e547
4 changed files with 18 additions and 7 deletions
|
@ -2,11 +2,14 @@
|
|||
{
|
||||
public sealed class AppHandler
|
||||
{
|
||||
#region Property
|
||||
|
||||
private static readonly Lazy<AppHandler> _instance = new(() => new());
|
||||
private Config _config;
|
||||
private int? _statePort;
|
||||
private int? _statePort2;
|
||||
private Job? _processJob;
|
||||
private bool? _isAdministrator;
|
||||
public static AppHandler Instance => _instance.Value;
|
||||
public Config Config => _config;
|
||||
|
||||
|
@ -28,6 +31,17 @@
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsAdministrator
|
||||
{
|
||||
get
|
||||
{
|
||||
_isAdministrator ??= Utils.IsAdministrator();
|
||||
return _isAdministrator.Value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Property
|
||||
|
||||
#region Init
|
||||
|
||||
public AppHandler()
|
||||
|
|
|
@ -10,8 +10,6 @@ namespace ServiceLib.ViewModels
|
|||
{
|
||||
public class StatusBarViewModel : MyReactiveObject
|
||||
{
|
||||
private bool _isAdministrator { get; set; }
|
||||
|
||||
#region ObservableCollection
|
||||
|
||||
private IObservableCollection<RoutingItem> _routingItems = new ObservableCollectionExtended<RoutingItem>();
|
||||
|
@ -119,8 +117,7 @@ namespace ServiceLib.ViewModels
|
|||
SelectedRouting = new();
|
||||
SelectedServer = new();
|
||||
|
||||
_isAdministrator = Utils.IsAdministrator();
|
||||
if (_config.tunModeItem.enableTun && _isAdministrator)
|
||||
if (_config.tunModeItem.enableTun && AppHandler.Instance.IsAdministrator)
|
||||
{
|
||||
EnableTun = true;
|
||||
}
|
||||
|
@ -414,7 +411,7 @@ namespace ServiceLib.ViewModels
|
|||
{
|
||||
_config.tunModeItem.enableTun = EnableTun;
|
||||
// When running as a non-administrator, reboot to administrator mode
|
||||
if (EnableTun && !_isAdministrator)
|
||||
if (EnableTun && !AppHandler.Instance.IsAdministrator)
|
||||
{
|
||||
_config.tunModeItem.enableTun = false;
|
||||
Locator.Current.GetService<MainWindowViewModel>()?.RebootAsAdmin();
|
||||
|
|
|
@ -103,7 +103,7 @@ namespace v2rayN.Desktop.Views
|
|||
}
|
||||
});
|
||||
|
||||
this.Title = $"{Utils.GetVersion()} - {(Utils.IsAdministrator() ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";
|
||||
this.Title = $"{Utils.GetVersion()} - {(AppHandler.Instance.IsAdministrator ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";
|
||||
if (Utils.IsWindows())
|
||||
{
|
||||
menuGlobalHotkeySetting.IsVisible = false;
|
||||
|
|
|
@ -122,7 +122,7 @@ namespace v2rayN.Views
|
|||
}
|
||||
});
|
||||
|
||||
this.Title = $"{Utils.GetVersion()} - {(Utils.IsAdministrator() ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";
|
||||
this.Title = $"{Utils.GetVersion()} - {(AppHandler.Instance.IsAdministrator ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";
|
||||
|
||||
if (!_config.guiItem.enableHWA)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue