feat: add entry in left panel

This commit is contained in:
Kingtous
2023-05-08 13:10:39 +08:00
parent 77fa807b57
commit 229df038fc
38 changed files with 178 additions and 34 deletions

View File

@@ -58,6 +58,33 @@ impl PluginNativeHandler for PluginNativeUIHandler {
data: "missing cb field message".as_ptr() as _,
});
}
"register_ui_entry" => {
let title;
if let Some(v) = data.get("title") {
title = v.as_str().unwrap_or("");
} else {
title = "";
}
if let Some(on_tap_cb) = data.get("on_tap_cb") {
if let Some(on_tap_cb) = on_tap_cb.as_u64() {
let user_data = match data.get("user_data") {
Some(user_data) => {
user_data.as_u64().unwrap_or(0)
},
None => 0,
};
self.register_ui_entry(title, on_tap_cb, user_data);
return Some(super::NR {
return_type: 0,
data: std::ptr::null(),
});
}
}
return Some(super::NR {
return_type: -1,
data: "missing cb field message".as_ptr() as _,
});
}
_ => {}
}
None
@@ -97,4 +124,26 @@ impl PluginNativeUIHandler {
serde_json::to_string(&param).unwrap_or("".to_string()),
);
}
/// Call with method `register_ui_entry` and the following json:
/// ```
/// {
///
/// "on_tap_cb": 0, // The function address
/// "user_data": 0, // An opaque pointer value passed to the callback.
/// "title": "entry name"
/// }
/// ```
fn register_ui_entry(&self, title: &str, on_tap_cb: u64, user_data: u64) {
let mut param = HashMap::new();
param.insert("name", json!("native_ui"));
param.insert("action", json!("register_ui_entry"));
param.insert("title", json!(title));
param.insert("cb", json!(on_tap_cb));
param.insert("user_data", json!(user_data));
crate::flutter::push_global_event(
APP_TYPE_MAIN,
serde_json::to_string(&param).unwrap_or("".to_string()),
);
}
}