From 8734722cc354fefb9d1e860aba9ad8d949042f3d Mon Sep 17 00:00:00 2001 From: 7a72 Date: Sun, 11 Jan 2026 10:53:01 +0000 Subject: [PATCH] feat: add Apatch support --- template/customize.sh | 15 +++++++ webui/src/components/ConfigView.svelte | 38 +++++++++++------- webui/src/lib/utils.js | 54 ++++++++++++++++++++++++-- 3 files changed, 88 insertions(+), 19 deletions(-) diff --git a/template/customize.sh b/template/customize.sh index 253e99e..701c0b2 100644 --- a/template/customize.sh +++ b/template/customize.sh @@ -158,6 +158,18 @@ for d in ${module_dirs}; do ui_print " ✓ Installed: $d/" done +if [ "x$KSU" = "xtrue" ] && [ "x$APATCH" = "xtrue" ]; then + abort "err" +elif [ "x$KSU" = "xtrue" ]; then + AOK="KSU" + echo "AOK=KSU" > "$MODPATH/aok" +elif [ "x$APATCH" = "xtrue" ]; then + AOK="APATCH" + ui_print "AOK=APATCH" > "$MODPATH/aok" +else + abort "err" +fi + ui_print "- Initializing configuration" # Create data directory @@ -179,6 +191,9 @@ if [ ! -f "$module_data_dir/mm.conf" ]; then else ui_print " ℹ Existing configuration preserved" fi +if [ "$AOK" = "APATCH" ]; then + sed -i '/^[[:space:]]*umount=true[[:space:]]*$/d' "$module_data_dir/mm.conf" +fi ui_print "- Managing metamodule status" diff --git a/webui/src/components/ConfigView.svelte b/webui/src/components/ConfigView.svelte index 35d7ecb..009ec7e 100644 --- a/webui/src/components/ConfigView.svelte +++ b/webui/src/components/ConfigView.svelte @@ -10,12 +10,17 @@ let message = null; let partitionsInput = ""; + let hideUmount = false; + const CONFIG_FILE_PATH = "/data/adb/magic_mount/mm.conf"; async function load() { loading = true; message = null; try { + const aok = await utils.loadAOK(); + hideUmount = aok === "APATCH"; + config = await utils.loadConfig(); partitionsInput = config.partitions.join(", "); message = $L.config.loadSuccess; @@ -35,7 +40,8 @@ .split(",") .map((s) => s.trim()) .filter(Boolean); - await utils.saveConfig(config); + + await utils.saveConfig(config, { omitUmount: hideUmount }); message = $L.config.saveSuccess; } catch (e) { console.error(e); @@ -70,21 +76,23 @@ -
- {$L.config.umountLabel} -
- - + {#if !hideUmount} +
+ {$L.config.umountLabel} +
+ + +
-
+ {/if}
diff --git a/webui/src/lib/utils.js b/webui/src/lib/utils.js index 97c74da..dd4034b 100644 --- a/webui/src/lib/utils.js +++ b/webui/src/lib/utils.js @@ -12,6 +12,18 @@ export const DEFAULT_CONFIG = { }; const CONFIG_PATH = "/data/adb/magic_mount/mm.conf"; +const AOK_PATH = "/data/adb/metamodule/aok"; + +function stripQuotes(s) { + const t = String(s).trim(); + if ( + (t.startsWith('"') && t.endsWith('"')) || + (t.startsWith("'") && t.endsWith("'")) + ) { + return t.slice(1, -1); + } + return t; +} function isTrueValue(v) { const s = String(v).trim().toLowerCase(); @@ -69,24 +81,31 @@ export async function loadConfig() { return result; } -export async function saveConfig(cfg) { +export async function saveConfig(cfg, opts = {}) { if (import.meta.env.DEV) { return MockAPI.saveConfig(cfg); } + const omitUmount = !!opts.omitUmount; + const lines = [ "# Magic Mount Configuration File", "# Generated by Web UI", "", ]; + lines.push(`module_dir=${cfg.moduledir || DEFAULT_CONFIG.moduledir}`); if (cfg.tempdir) lines.push(`temp_dir=${cfg.tempdir}`); lines.push(`mount_source=${cfg.mountsource || DEFAULT_CONFIG.mountsource}`); if (cfg.logfile) lines.push(`log_file=${cfg.logfile}`); lines.push(`debug=${cfg.verbose ? "true" : "false"}`); - lines.push(`umount=${cfg.umount ? "true" : "false"}`); - if (cfg.partitions.length > 0) - lines.push(`partitions=${cfg.partitions.join(",")}`); + + if (!omitUmount) { + lines.push(`umount=${cfg.umount ? "true" : "false"}`); + } + + const parts = Array.isArray(cfg.partitions) ? cfg.partitions : []; + if (parts.length > 0) lines.push(`partitions=${parts.join(",")}`); const content = lines.join("\n").replace(/'/g, "'\\''"); const shell = `mkdir -p "$(dirname "${CONFIG_PATH}")" && printf '%s\n' '${content}' > "${CONFIG_PATH}"`; @@ -157,3 +176,30 @@ export async function toggleModuleSkip(moduleDir, modName, shouldSkip) { const { errno, stderr } = await exec(cmd); if (errno !== 0) throw new Error(stderr); } + +export async function loadAOK() { + if (import.meta.env.DEV) { + return "KSU"; + } + + const { errno, stdout } = await exec( + `[ -f "${AOK_PATH}" ] && cat "${AOK_PATH}" || echo ""`, + ); + if (errno !== 0) throw new Error("Read AOK failed"); + + const lines = (stdout || "").split("\n"); + for (let line of lines) { + line = line.trim(); + if (!line || line.startsWith("#")) continue; + + const [key, ...vals] = line.split("="); + if (!key || !vals.length) continue; + + if (key.trim() === "AOK") { + const value = stripQuotes(vals.join("=").trim()); + return value; + } + } + + return ""; +}