Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manager: Action Feature Added #664

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apd/src/cli.rs
Original file line number Diff line number Diff line change
@@ -58,6 +58,11 @@ enum Module {
id: String,
},

Run {
/// module id,Run Action for action.sh mannual
id: String,
},

/// enable module <id>
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(),
21 changes: 21 additions & 0 deletions apd/src/module.rs
Original file line number Diff line number Diff line change
@@ -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}");
15 changes: 12 additions & 3 deletions app/src/main/java/me/bmax/apatch/ui/screen/APM.kt
Original file line number Diff line number Diff line change
@@ -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))
Original file line number Diff line number Diff line change
@@ -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