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); 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

View file

@ -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())