mirror of
https://github.com/2dust/v2rayN.git
synced 2026-04-14 19:45:45 +00:00
按上游意见回滚 TUN 提权时保留启用状态的改动
This commit is contained in:
parent
935d9e0aa3
commit
4521e022aa
2 changed files with 16 additions and 30 deletions
|
|
@ -144,16 +144,10 @@ public sealed class AppManager
|
||||||
AppEvents.ShutdownRequested.Publish(byUser);
|
AppEvents.ShutdownRequested.Publish(byUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> RebootAsAdmin()
|
public async Task RebootAsAdmin()
|
||||||
{
|
{
|
||||||
var started = ProcUtils.RebootAsAdmin();
|
ProcUtils.RebootAsAdmin();
|
||||||
if (!started)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
await AppManager.Instance.AppExitAsync(true);
|
await AppManager.Instance.AppExitAsync(true);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion App
|
#endregion App
|
||||||
|
|
|
||||||
|
|
@ -469,40 +469,32 @@ public class StatusBarViewModel : MyReactiveObject
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var allowEnableTun = AllowEnableTun();
|
_config.TunModeItem.EnableTun = EnableTun;
|
||||||
if (PrepareTunConfigForPrivilegeEscalation(_config, EnableTun, allowEnableTun, Utils.IsWindows()))
|
|
||||||
{
|
|
||||||
await ConfigHandler.SaveConfig(_config);
|
|
||||||
if (!await AppManager.Instance.RebootAsAdmin())
|
|
||||||
{
|
|
||||||
_config.TunModeItem.EnableTun = false;
|
|
||||||
EnableTun = false;
|
|
||||||
await ConfigHandler.SaveConfig(_config);
|
|
||||||
NoticeManager.Instance.SendMessageEx(ResUI.OperationFailed);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EnableTun && !allowEnableTun)
|
if (EnableTun && AllowEnableTun() == false)
|
||||||
{
|
{
|
||||||
bool? passwordResult = await _updateView?.Invoke(EViewAction.PasswordInput, null);
|
// When running as a non-administrator, reboot to administrator mode
|
||||||
if (passwordResult == false)
|
if (Utils.IsWindows())
|
||||||
{
|
{
|
||||||
_config.TunModeItem.EnableTun = false;
|
_config.TunModeItem.EnableTun = false;
|
||||||
|
await AppManager.Instance.RebootAsAdmin();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool? passwordResult = await _updateView?.Invoke(EViewAction.PasswordInput, null);
|
||||||
|
if (passwordResult == false)
|
||||||
|
{
|
||||||
|
_config.TunModeItem.EnableTun = false;
|
||||||
|
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