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

@@ -223,6 +223,12 @@ enum Module {
id: String,
},
/// run action for module <id>
Action {
// module id
id: String,
},
/// list all modules
List,
@@ -306,6 +312,7 @@ pub fn run() -> Result<()> {
Module::Uninstall { id } => module::uninstall_module(&id),
Module::Enable { id } => module::enable_module(&id),
Module::Disable { id } => module::disable_module(&id),
Module::Action { id } => module::run_action(&id),
Module::List => module::list_modules(),
Module::Shrink => module::shrink_ksu_images(),
}

View File

@@ -30,6 +30,7 @@ pub const SYSTEM_RW_DIR: &str = concatcp!(MODULE_DIR, ".rw/");
pub const TEMP_DIR: &str = "/debug_ramdisk";
pub const MODULE_WEB_DIR: &str = "webroot";
pub const MODULE_ACTION_SH: &str = "action.sh";
pub const DISABLE_FILE_NAME: &str = "disable";
pub const UPDATE_FILE_NAME: &str = "update";
pub const REMOVE_FILE_NAME: &str = "remove";

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());