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 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> { pub async fn set_autostart(autostart: bool) -> Result<(), anyhow::Error> {
let autostart_path = MODULE_PATH.join("autostart");
if autostart { if autostart {
File::create(autostart_path).await?; File::create(&*AUTOSTART).await?;
} else { } else {
fs::remove_file(autostart_path).await?; fs::remove_file(&*AUTOSTART).await?;
} }
Ok(()) Ok(())
} }
pub fn get_autostart() { pub fn get_autostart() -> bool {
let file = MODULE_PATH.join("autostart"); AUTOSTART.exists()
println!("{}", file.exists());
} }

View File

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