mirror of
https://github.com/2dust/v2rayN.git
synced 2026-05-14 10:05:51 +00:00
Compare commits
1 commit
2a1642f3d5
...
3faeadacdb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3faeadacdb |
2 changed files with 30 additions and 16 deletions
|
|
@ -144,10 +144,16 @@ public sealed class AppManager
|
||||||
AppEvents.ShutdownRequested.Publish(byUser);
|
AppEvents.ShutdownRequested.Publish(byUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RebootAsAdmin()
|
public async Task<bool> RebootAsAdmin()
|
||||||
{
|
{
|
||||||
ProcUtils.RebootAsAdmin();
|
var started = ProcUtils.RebootAsAdmin();
|
||||||
|
if (!started)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
await AppManager.Instance.AppExitAsync(true);
|
await AppManager.Instance.AppExitAsync(true);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion App
|
#endregion App
|
||||||
|
|
|
||||||
|
|
@ -469,18 +469,21 @@ public class StatusBarViewModel : MyReactiveObject
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_config.TunModeItem.EnableTun = EnableTun;
|
var allowEnableTun = AllowEnableTun();
|
||||||
|
if (PrepareTunConfigForPrivilegeEscalation(_config, EnableTun, allowEnableTun, Utils.IsWindows()))
|
||||||
if (EnableTun && AllowEnableTun() == false)
|
|
||||||
{
|
{
|
||||||
// When running as a non-administrator, reboot to administrator mode
|
await ConfigHandler.SaveConfig(_config);
|
||||||
if (Utils.IsWindows())
|
if (!await AppManager.Instance.RebootAsAdmin())
|
||||||
{
|
{
|
||||||
_config.TunModeItem.EnableTun = false;
|
_config.TunModeItem.EnableTun = false;
|
||||||
await AppManager.Instance.RebootAsAdmin();
|
EnableTun = false;
|
||||||
|
await ConfigHandler.SaveConfig(_config);
|
||||||
|
NoticeManager.Instance.SendMessageEx(ResUI.OperationFailed);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (EnableTun && !allowEnableTun)
|
||||||
{
|
{
|
||||||
bool? passwordResult = await _updateView?.Invoke(EViewAction.PasswordInput, null);
|
bool? passwordResult = await _updateView?.Invoke(EViewAction.PasswordInput, null);
|
||||||
if (passwordResult == false)
|
if (passwordResult == false)
|
||||||
|
|
@ -489,12 +492,17 @@ public class StatusBarViewModel : MyReactiveObject
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
await ConfigHandler.SaveConfig(_config);
|
await ConfigHandler.SaveConfig(_config);
|
||||||
AppEvents.ReloadRequested.Publish();
|
AppEvents.ReloadRequested.Publish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool PrepareTunConfigForPrivilegeEscalation(Config config, bool enableTun, bool allowEnableTun, bool isWindows)
|
||||||
|
{
|
||||||
|
config.TunModeItem.EnableTun = enableTun;
|
||||||
|
return enableTun && !allowEnableTun && isWindows;
|
||||||
|
}
|
||||||
|
|
||||||
private bool AllowEnableTun()
|
private bool AllowEnableTun()
|
||||||
{
|
{
|
||||||
if (Utils.IsWindows())
|
if (Utils.IsWindows())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue