From 366bb2154578026ba5113087c1b3547765f5534a Mon Sep 17 00:00:00 2001 From: Admire Date: Wed, 11 Sep 2024 12:29:06 +0800 Subject: [PATCH 1/2] action rust ready action ready --- apd/src/cli.rs | 6 ++++++ apd/src/module.rs | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/apd/src/cli.rs b/apd/src/cli.rs index c94e06c8c..d0ab5dcf0 100644 --- a/apd/src/cli.rs +++ b/apd/src/cli.rs @@ -58,6 +58,11 @@ enum Module { id: String, }, + Run { + /// module id,Run Action for action.sh mannual + id: String, + }, + /// enable module Enable { /// module id @@ -121,6 +126,7 @@ pub fn run() -> Result<()> { match command { Module::Install { zip } => module::install_module(&zip), Module::Uninstall { id } => module::uninstall_module(&id), + Module::Run { id } => module::run_action(&id), Module::Enable { id } => module::enable_module(&id), Module::Disable { id } => module::disable_module(&id), Module::List => module::list_modules(), diff --git a/apd/src/module.rs b/apd/src/module.rs index 10b2113b9..e0503965c 100644 --- a/apd/src/module.rs +++ b/apd/src/module.rs @@ -587,6 +587,27 @@ pub fn uninstall_module(id: &str) -> Result<()> { Ok(()) }) } +pub fn run_action(id: &str) -> Result<()> { + let action_script_path = format!("/data/adb/modules/{}/action.sh", id); + let result = Command::new(assets::BUSYBOX_PATH) + .args(["sh", "-c", &action_script_path]) + .env("ASH_STANDALONE", "1") + .env( + "PATH", + format!( + "{}:{}", + env_var("PATH").unwrap(), + defs::BINARY_DIR.trim_end_matches('/') + ), + ) + .env("APATCH", "true") + .env("APATCH_VER", defs::VERSION_NAME) + .env("APATCH_VER_CODE", defs::VERSION_CODE) + .env("OUTFD", "1") + .status()?; + ensure!(result.success(), "Failed to install action script"); + Ok(()) +} fn _enable_module(module_dir: &str, mid: &str, enable: bool) -> Result<()> { let src_module_path = format!("{module_dir}/{mid}"); From 260931d180e9d670e7819274cc49a3d5f9a716fd Mon Sep 17 00:00:00 2001 From: Admire Date: Thu, 12 Sep 2024 18:20:16 +0800 Subject: [PATCH 2/2] action ui --- app/src/main/java/me/bmax/apatch/ui/screen/APM.kt | 15 ++++++++++++--- .../bmax/apatch/ui/viewmodel/APModuleViewModel.kt | 4 +++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/me/bmax/apatch/ui/screen/APM.kt b/app/src/main/java/me/bmax/apatch/ui/screen/APM.kt index b52a373e6..d42025edd 100644 --- a/app/src/main/java/me/bmax/apatch/ui/screen/APM.kt +++ b/app/src/main/java/me/bmax/apatch/ui/screen/APM.kt @@ -190,7 +190,7 @@ fun APModuleScreen(navigator: DestinationsNavigator) { onInstallModule = { navigator.navigate(InstallScreenDestination(it)) }, - onClickModule = { id, name, hasWebUi -> + onClickModule = { id, name, hasWebUi, hasAction -> if (hasWebUi) { context.startActivity( Intent( @@ -199,6 +199,15 @@ fun APModuleScreen(navigator: DestinationsNavigator) { .putExtra("name", name) ) } + if (hasAction){ + context.startActivity( + Intent( + context, WebUIActivity::class.java + ).setData(Uri.parse("apatch://webui/$id")).putExtra("id", id) + .putExtra("name", name) + ) + } + }) } } @@ -212,7 +221,7 @@ private fun ModuleList( modifier: Modifier = Modifier, state: LazyListState, onInstallModule: (Uri) -> Unit, - onClickModule: (id: String, name: String, hasWebUi: Boolean) -> Unit + onClickModule: (id: String, name: String, hasWebUi: Boolean ,hasAction: Boolean) -> Unit ) { val failedEnable = stringResource(R.string.apm_failed_to_enable) val failedDisable = stringResource(R.string.apm_failed_to_disable) @@ -414,7 +423,7 @@ private fun ModuleList( ) } }, onClick = { - onClickModule(it.id, it.name, it.hasWebUi) + onClickModule(it.id, it.name, it.hasWebUi,it.hasAction) }) // fix last item shadow incomplete in LazyColumn Spacer(Modifier.height(1.dp)) diff --git a/app/src/main/java/me/bmax/apatch/ui/viewmodel/APModuleViewModel.kt b/app/src/main/java/me/bmax/apatch/ui/viewmodel/APModuleViewModel.kt index eed6b20ac..334d6ce86 100644 --- a/app/src/main/java/me/bmax/apatch/ui/viewmodel/APModuleViewModel.kt +++ b/app/src/main/java/me/bmax/apatch/ui/viewmodel/APModuleViewModel.kt @@ -35,6 +35,7 @@ class APModuleViewModel : ViewModel() { val remove: Boolean, val updateJson: String, val hasWebUi: Boolean, + val hasAction: Boolean, ) data class ModuleUpdateInfo( @@ -96,7 +97,8 @@ class APModuleViewModel : ViewModel() { obj.getBoolean("update"), obj.getBoolean("remove"), obj.optString("updateJson"), - obj.optBoolean("web") + obj.optBoolean("web"), + obj.optBoolean("action") ) }.toList() isNeedRefresh = false