feat: unify runtime mode detection; support TUN and service installation in admin mode

This commit is contained in:
wonfen
2025-03-31 08:16:14 +08:00
parent 8e99672265
commit c53514e060
8 changed files with 109 additions and 61 deletions

View File

@@ -64,12 +64,12 @@ pub fn get_app_uptime() -> CmdResult<i64> {
#[cfg(target_os = "windows")]
pub fn is_admin() -> CmdResult<bool> {
use deelevate::{PrivilegeLevel, Token};
let result = Token::with_current_process()
.and_then(|token| token.privilege_level())
.map(|level| level != PrivilegeLevel::NotPrivileged)
.unwrap_or(false);
Ok(result)
}
@@ -81,12 +81,12 @@ pub fn is_admin() -> CmdResult<bool> {
{
Ok(unsafe { libc::geteuid() } == 0)
}
#[cfg(target_os = "linux")]
{
Ok(unsafe { libc::geteuid() } == 0)
}
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
{
Ok(false)