From d59340a5c9844f5d854bf7b516ccef78919cf6f9 Mon Sep 17 00:00:00 2001 From: sqlerrorthing <148702857+sqlerrorthing@users.noreply.github.com> Date: Mon, 3 Nov 2025 05:35:33 +0800 Subject: [PATCH] refactor autostart --- rust/crates/zaprett/src/autostart.rs | 19 ++++++++++--------- rust/crates/zaprett/src/cli/commands.rs | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/rust/crates/zaprett/src/autostart.rs b/rust/crates/zaprett/src/autostart.rs index 371e1fd..d56aa67 100644 --- a/rust/crates/zaprett/src/autostart.rs +++ b/rust/crates/zaprett/src/autostart.rs @@ -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 = 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() } diff --git a/rust/crates/zaprett/src/cli/commands.rs b/rust/crates/zaprett/src/cli/commands.rs index abdde1f..af6695c 100644 --- a/rust/crates/zaprett/src/cli/commands.rs +++ b/rust/crates/zaprett/src/cli/commands.rs @@ -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(), }