调整代码顺序
This commit is contained in:
@@ -146,13 +146,25 @@ fn main() {
|
|||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||||
fn main() {
|
fn main() {
|
||||||
let home = dirs::home_dir().unwrap().join(".switch_desktop");
|
|
||||||
config::set_home(home);
|
|
||||||
let args = BaseArgs::parse();
|
let args = BaseArgs::parse();
|
||||||
if let Commands::Start(start_args) = &args.command {
|
match args.command {
|
||||||
if start_args.log {
|
Commands::Start(_) | Commands::Stop => {
|
||||||
let _ = log_init();
|
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);
|
unix::main0(args);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,14 +15,6 @@ pub fn main0(base_args: BaseArgs) {
|
|||||||
let off_command_server = args.off_command_server;
|
let off_command_server = args.off_command_server;
|
||||||
match config::default_config(args) {
|
match config::default_config(args) {
|
||||||
Ok(start_config) => {
|
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(
|
let config = Config::new(
|
||||||
start_config.tap,
|
start_config.tap,
|
||||||
start_config.token.clone(),
|
start_config.token.clone(),
|
||||||
@@ -100,13 +92,6 @@ pub fn main0(base_args: BaseArgs) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Commands::Stop => {
|
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);
|
command(CommandEnum::Stop);
|
||||||
if let Ok(pid) = config::read_pid() {
|
if let Ok(pid) = config::read_pid() {
|
||||||
if pid != 0 {
|
if pid != 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user