refactor autostart

This commit is contained in:
sqlerrorthing
2025-11-03 05:35:33 +08:00
parent fc5cc814d6
commit d59340a5c9
2 changed files with 11 additions and 10 deletions

View File

@@ -1,20 +1,21 @@
use tokio::fs::File;
use tokio::fs;
use crate::MODULE_PATH;
use std::path::PathBuf;
use std::sync::LazyLock;
use tokio::fs;
use tokio::fs::File;
static AUTOSTART: LazyLock<PathBuf> = LazyLock::new(|| MODULE_PATH.join("autostart"));
pub async fn set_autostart(autostart: bool) -> Result<(), anyhow::Error> {
let autostart_path = MODULE_PATH.join("autostart");
if autostart {
File::create(autostart_path).await?;
File::create(&*AUTOSTART).await?;
} else {
fs::remove_file(autostart_path).await?;
fs::remove_file(&*AUTOSTART).await?;
}
Ok(())
}
pub fn get_autostart() {
let file = MODULE_PATH.join("autostart");
println!("{}", file.exists());
pub fn get_autostart() -> bool {
AUTOSTART.exists()
}

View File

@@ -58,7 +58,7 @@ impl Command {
error!("Failed to set auto start: {err}")
}
}
Command::GetAutostart => get_autostart(),
Command::GetAutostart => println!("{}", get_autostart()),
Command::ModuleVersion => module_version(),
Command::BinaryVersion => bin_version(),
}