Merge pull request #3 from lbl8603/main

update from upstream
This commit is contained in:
Droid-MAX
2023-05-12 17:01:32 +08:00
committed by GitHub
3 changed files with 14 additions and 19 deletions
+6 -3
View File
@@ -188,7 +188,9 @@ impl ArgsConfig {
pub fn lock_file() -> io::Result<File> {
let path = SWITCH_HOME_PATH.lock().clone().unwrap().join(".lock");
Ok(File::create(path)?)
let file = File::create(path)?;
file.sync_all()?;
Ok(file)
}
pub fn save_config(config: ArgsConfig) -> io::Result<()> {
@@ -198,10 +200,11 @@ pub fn save_config(config: ArgsConfig) -> io::Result<()> {
fn save_config_(config: ArgsConfig, config_path: PathBuf) -> io::Result<()> {
let mut config_lock = CONFIG.lock();
config_lock.take();
config_lock.replace(config.clone());
let str = serde_yaml::to_string(&config).unwrap();
let mut file = File::create(config_path)?;
file.write_all(str.as_bytes())
file.write_all(str.as_bytes())?;
file.sync_all()
}
pub fn update_pid(pid: u32) -> io::Result<()> {
+8 -1
View File
@@ -146,9 +146,16 @@ fn main() {
#[cfg(any(target_os = "linux", target_os = "macos"))]
fn main() {
if sudo::RunningAs::Root != sudo::check() {
println!(
"{}",
style("需要使用root权限执行(Need to execute with root permission)...").red()
);
sudo::escalate_if_needed().unwrap();
}
let args = BaseArgs::parse();
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();
-15
View File
@@ -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 {