mirror of
https://github.com/egor-white/zaprett.git
synced 2025-12-10 21:40:12 +05:00
move module
This commit is contained in:
20
rust/crates/zaprett/src/autostart.rs
Normal file
20
rust/crates/zaprett/src/autostart.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use tokio::fs::File;
|
||||
use tokio::fs;
|
||||
use crate::MODULE_PATH;
|
||||
|
||||
pub async fn set_autostart(autostart: bool) -> Result<(), anyhow::Error> {
|
||||
let autostart_path = MODULE_PATH.join("autostart");
|
||||
|
||||
if autostart {
|
||||
File::create(autostart_path).await?;
|
||||
} else {
|
||||
fs::remove_file(autostart_path).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_autostart() {
|
||||
let file = MODULE_PATH.join("autostart");
|
||||
println!("{}", file.exists());
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
use crate::service::{restart_service, service_status, start_service, stop_service};
|
||||
use crate::{bin_version, get_autostart, module_version, set_autostart};
|
||||
use crate::{bin_version, module_version};
|
||||
use clap::Subcommand;
|
||||
use log::error;
|
||||
use crate::autostart::{get_autostart, set_autostart};
|
||||
|
||||
#[derive(Subcommand)]
|
||||
pub enum Command {
|
||||
|
||||
@@ -3,6 +3,7 @@ pub mod config;
|
||||
mod daemon;
|
||||
pub mod iptables_rust;
|
||||
mod service;
|
||||
mod autostart;
|
||||
|
||||
use ini::Ini;
|
||||
use libnfqws::nfqws_main;
|
||||
@@ -11,9 +12,8 @@ use std::ffi::CString;
|
||||
use std::os::raw::c_char;
|
||||
use std::path::Path;
|
||||
use std::sync::LazyLock;
|
||||
use tokio::fs;
|
||||
use tokio::fs::File;
|
||||
use tokio::io::{AsyncWriteExt, copy};
|
||||
use tokio::io::{copy, AsyncWriteExt};
|
||||
|
||||
pub static MODULE_PATH: LazyLock<&Path> = LazyLock::new(|| Path::new("/data/adb/modules/zaprett"));
|
||||
pub static ZAPRETT_DIR_PATH: LazyLock<&Path> =
|
||||
@@ -28,23 +28,6 @@ pub static DEFAULT_START: &str = "
|
||||
--filter-udp=443 --dpi-desync=fake --dpi-desync-repeats=6 $hostlist
|
||||
";
|
||||
|
||||
async fn set_autostart(autostart: bool) -> Result<(), anyhow::Error> {
|
||||
let autostart_path = MODULE_PATH.join("autostart");
|
||||
|
||||
if autostart {
|
||||
File::create(autostart_path).await?;
|
||||
} else {
|
||||
fs::remove_file(autostart_path).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_autostart() {
|
||||
let file = MODULE_PATH.join("autostart");
|
||||
println!("{}", file.exists());
|
||||
}
|
||||
|
||||
fn module_version() {
|
||||
if let Ok(prop) = Ini::load_from_file(MODULE_PATH.join("module.prop"))
|
||||
&& let Some(props) = prop.section::<String>(None)
|
||||
|
||||
Reference in New Issue
Block a user