Compare commits

..

1 commit

Author SHA1 Message Date
nirvanalinlei
3faeadacdb
Merge 935d9e0aa3 into b556adaa09 2026-04-01 09:47:24 +08:00
2 changed files with 30 additions and 16 deletions

View file

@ -144,10 +144,16 @@ public sealed class AppManager
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);
return true;
}
#endregion App

View file

@ -469,18 +469,21 @@ public class StatusBarViewModel : MyReactiveObject
return;
}
_config.TunModeItem.EnableTun = EnableTun;
if (EnableTun && AllowEnableTun() == false)
var allowEnableTun = AllowEnableTun();
if (PrepareTunConfigForPrivilegeEscalation(_config, EnableTun, allowEnableTun, Utils.IsWindows()))
{
// When running as a non-administrator, reboot to administrator mode
if (Utils.IsWindows())
await ConfigHandler.SaveConfig(_config);
if (!await AppManager.Instance.RebootAsAdmin())
{
_config.TunModeItem.EnableTun = false;
await AppManager.Instance.RebootAsAdmin();
EnableTun = false;
await ConfigHandler.SaveConfig(_config);
NoticeManager.Instance.SendMessageEx(ResUI.OperationFailed);
}
return;
}
else
if (EnableTun && !allowEnableTun)
{
bool? passwordResult = await _updateView?.Invoke(EViewAction.PasswordInput, null);
if (passwordResult == false)
@ -489,12 +492,17 @@ 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())