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