manager: Add action.sh for user to manually trigger modules' functionality from manager (#2156)

Commits:
- manager: Add `action.sh` for user to manually trigger modules'
functionality from manager
- manager: Optimize ModuleItem
- manager: uninstall button: TextButton -> FilledTonalButton
- Optimize `run_action` function

Commit Author & Thank:
- @lightsummer233
- @lingqiqi5211
- [APatch](https://github.com/bmax121/APatch)

Demo Show:

![image](https://github.com/user-attachments/assets/a5778a86-fa60-485f-ac49-2b581711f60e)

---------

Co-authored-by: Light summer <93428659+lightsummer233@users.noreply.github.com>
This commit is contained in:
铃柒柒
2024-10-27 17:07:13 +08:00
committed by GitHub
parent 7b3e732404
commit aefb1aaed2
10 changed files with 319 additions and 84 deletions

View File

@@ -570,6 +570,11 @@ pub fn uninstall_module(id: &str) -> Result<()> {
})
}
pub fn run_action(id: &str) -> Result<()> {
let action_script_path = format!("/data/adb/modules/{}/action.sh", id);
exec_script(&action_script_path, true)
}
fn _enable_module(module_dir: &str, mid: &str, enable: bool) -> Result<()> {
let src_module_path = format!("{module_dir}/{mid}");
let src_module = Path::new(&src_module_path);
@@ -668,11 +673,13 @@ fn _list_modules(path: &str) -> Vec<HashMap<String, String>> {
let update = path.join(defs::UPDATE_FILE_NAME).exists();
let remove = path.join(defs::REMOVE_FILE_NAME).exists();
let web = path.join(defs::MODULE_WEB_DIR).exists();
let action = path.join(defs::MODULE_ACTION_SH).exists();
module_prop_map.insert("enabled".to_owned(), enabled.to_string());
module_prop_map.insert("update".to_owned(), update.to_string());
module_prop_map.insert("remove".to_owned(), remove.to_string());
module_prop_map.insert("web".to_owned(), web.to_string());
module_prop_map.insert("action".to_owned(), action.to_string());
if result.is_err() {
warn!("Failed to parse module.prop: {}", module_prop.display());