Merge branch 'main' into refactor/rust/autostart

This commit is contained in:
egor-white
2025-11-03 16:28:13 +03:00
committed by GitHub
2 changed files with 18 additions and 10 deletions

View File

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

View File

@@ -12,10 +12,14 @@ use std::ffi::CString;
use std::os::raw::c_char; use std::os::raw::c_char;
use std::path::Path; use std::path::Path;
use std::sync::LazyLock; use std::sync::LazyLock;
use anyhow::bail;
use tokio::fs::File; use tokio::fs::File;
use tokio::io::{copy, AsyncWriteExt}; use tokio::io::{copy, AsyncWriteExt};
use tokio::task::spawn_blocking;
pub static MODULE_PATH: LazyLock<&Path> =
LazyLock::new(|| Path::new("/data/adb/modules/zaprett"));
pub static MODULE_PATH: LazyLock<&Path> = LazyLock::new(|| Path::new("/data/adb/modules/zaprett"));
pub static ZAPRETT_DIR_PATH: LazyLock<&Path> = pub static ZAPRETT_DIR_PATH: LazyLock<&Path> =
LazyLock::new(|| Path::new("/storage/emulated/0/zaprett")); LazyLock::new(|| Path::new("/storage/emulated/0/zaprett"));
@@ -28,17 +32,21 @@ pub static DEFAULT_START: &str = "
--filter-udp=443 --dpi-desync=fake --dpi-desync-repeats=6 $hostlist --filter-udp=443 --dpi-desync=fake --dpi-desync-repeats=6 $hostlist
"; ";
fn module_version() { async fn module_version() -> anyhow::Result<String> {
if let Ok(prop) = Ini::load_from_file(MODULE_PATH.join("module.prop")) let prop = spawn_blocking(|| Ini::load_from_file(MODULE_PATH.join("module.prop")))
&& let Some(props) = prop.section::<String>(None) .await??;
if let Some(props) = prop.section::<String>(None)
&& let Some(version) = props.get("version") && let Some(version) = props.get("version")
{ {
println!("{version}"); return Ok(version.into());
} }
bail!("Failed to get version, prop not found")
} }
fn bin_version() { fn bin_version() -> &'static str {
println!("{}", env!("ZAPRET_VERSION")); env!("ZAPRET_VERSION")
} }
pub async fn merge_files( pub async fn merge_files(