From 675e0c52ff27e47d16018d8063133c7433eacf20 Mon Sep 17 00:00:00 2001 From: lubeilin <1791778603@qq.com> Date: Thu, 11 May 2023 20:56:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81=E9=A1=BA?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- switch-desktop/src/main.rs | 22 +++++++++++++++++----- switch-desktop/src/unix/mod.rs | 15 --------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/switch-desktop/src/main.rs b/switch-desktop/src/main.rs index 4b898cd..d024343 100644 --- a/switch-desktop/src/main.rs +++ b/switch-desktop/src/main.rs @@ -146,13 +146,25 @@ fn main() { #[cfg(any(target_os = "linux", target_os = "macos"))] fn main() { - let home = dirs::home_dir().unwrap().join(".switch_desktop"); - config::set_home(home); let args = BaseArgs::parse(); - if let Commands::Start(start_args) = &args.command { - if start_args.log { - let _ = log_init(); + match args.command { + Commands::Start(_) | Commands::Stop => { + if sudo::RunningAs::Root != sudo::check() { + println!( + "{}", + style("需要使用root权限执行(Need to execute with root permission)...").red() + ); + sudo::escalate_if_needed().unwrap(); + } + let home = dirs::home_dir().unwrap().join(".switch_desktop"); + config::set_home(home); + if let Commands::Start(start_args) = &args.command { + if start_args.log { + let _ = log_init(); + } + } } + _ => {} } unix::main0(args); } diff --git a/switch-desktop/src/unix/mod.rs b/switch-desktop/src/unix/mod.rs index b1181ca..7697548 100644 --- a/switch-desktop/src/unix/mod.rs +++ b/switch-desktop/src/unix/mod.rs @@ -15,14 +15,6 @@ pub fn main0(base_args: BaseArgs) { let off_command_server = args.off_command_server; match config::default_config(args) { Ok(start_config) => { - if sudo::RunningAs::Root != sudo::check() { - println!( - "{}", - style("需要使用root权限执行(Need to execute with root permission)...").red() - ); - sudo::escalate_if_needed().unwrap(); - } - let config = Config::new( start_config.tap, start_config.token.clone(), @@ -100,13 +92,6 @@ pub fn main0(base_args: BaseArgs) { } } Commands::Stop => { - if sudo::RunningAs::Root != sudo::check() { - println!( - "{}", - style("需要使用root权限执行(Need to execute with root permission)...").red() - ); - sudo::escalate_if_needed().unwrap(); - } command(CommandEnum::Stop); if let Ok(pid) = config::read_pid() { if pid != 0 {