mirror of
https://github.com/egor-white/zaprett.git
synced 2025-12-10 21:40:12 +05:00
refactor autostart
This commit is contained in:
@@ -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());
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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(),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user