|
@@ -118,20 +118,35 @@ impl<R: Runtime, C: DeserializeOwned> PluginApi<R, C> {
|
|
|
#[cfg(target_os = "ios")]
|
|
|
pub fn register_ios_plugin(
|
|
|
&self,
|
|
|
- init_fn: unsafe fn(&swift_rs::SRString, *const std::ffi::c_void),
|
|
|
+ init_fn: unsafe fn() -> *const std::ffi::c_void,
|
|
|
) -> Result<PluginHandle<R>, PluginInvokeError> {
|
|
|
if let Some(window) = self.handle.manager.windows().values().next() {
|
|
|
let (tx, rx) = channel();
|
|
|
let name = self.name;
|
|
|
+ let config = self.raw_config.clone();
|
|
|
window
|
|
|
.with_webview(move |w| {
|
|
|
- unsafe { init_fn(&name.into(), w.inner() as _) };
|
|
|
+ unsafe {
|
|
|
+ crate::ios::register_plugin(
|
|
|
+ &name.into(),
|
|
|
+ init_fn(),
|
|
|
+ crate::ios::json_to_dictionary(&config) as _,
|
|
|
+ w.inner() as _,
|
|
|
+ )
|
|
|
+ };
|
|
|
tx.send(()).unwrap();
|
|
|
})
|
|
|
.map_err(|_| PluginInvokeError::UnreachableWebview)?;
|
|
|
rx.recv().unwrap();
|
|
|
} else {
|
|
|
- unsafe { init_fn(&self.name.into(), std::ptr::null()) };
|
|
|
+ unsafe {
|
|
|
+ crate::ios::register_plugin(
|
|
|
+ &self.name.into(),
|
|
|
+ init_fn(),
|
|
|
+ crate::ios::json_to_dictionary(&self.raw_config) as _,
|
|
|
+ std::ptr::null(),
|
|
|
+ )
|
|
|
+ };
|
|
|
}
|
|
|
Ok(PluginHandle {
|
|
|
name: self.name,
|
|
@@ -155,6 +170,7 @@ impl<R: Runtime, C: DeserializeOwned> PluginApi<R, C> {
|
|
|
runtime_handle: &R::Handle,
|
|
|
plugin_name: &'static str,
|
|
|
plugin_class: String,
|
|
|
+ plugin_config: &serde_json::Value,
|
|
|
) -> Result<(), JniError> {
|
|
|
let plugin_manager = env
|
|
|
.call_method(
|
|
@@ -177,11 +193,12 @@ impl<R: Runtime, C: DeserializeOwned> PluginApi<R, C> {
|
|
|
env.call_method(
|
|
|
plugin_manager,
|
|
|
"load",
|
|
|
- "(Landroid/webkit/WebView;Ljava/lang/String;Lapp/tauri/plugin/Plugin;)V",
|
|
|
+ "(Landroid/webkit/WebView;Ljava/lang/String;Lapp/tauri/plugin/Plugin;Lapp/tauri/plugin/JSObject;)V",
|
|
|
&[
|
|
|
webview.into(),
|
|
|
env.new_string(plugin_name)?.into(),
|
|
|
plugin.into(),
|
|
|
+ crate::jni_helpers::to_jsobject::<R>(env, activity, runtime_handle, plugin_config)?
|
|
|
],
|
|
|
)?;
|
|
|
|
|
@@ -190,6 +207,7 @@ impl<R: Runtime, C: DeserializeOwned> PluginApi<R, C> {
|
|
|
|
|
|
let plugin_class = format!("{}/{}", plugin_identifier.replace('.', "/"), class_name);
|
|
|
let plugin_name = self.name;
|
|
|
+ let plugin_config = self.raw_config.clone();
|
|
|
let runtime_handle = self.handle.runtime_handle.clone();
|
|
|
let (tx, rx) = channel();
|
|
|
self
|
|
@@ -203,6 +221,7 @@ impl<R: Runtime, C: DeserializeOwned> PluginApi<R, C> {
|
|
|
&runtime_handle,
|
|
|
plugin_name,
|
|
|
plugin_class,
|
|
|
+ &plugin_config,
|
|
|
);
|
|
|
tx.send(result).unwrap();
|
|
|
});
|
|
@@ -288,7 +307,7 @@ impl<R: Runtime> PluginHandle<R> {
|
|
|
id,
|
|
|
&self.name.into(),
|
|
|
&method.as_ref().into(),
|
|
|
- crate::ios::json_to_dictionary(serde_json::to_value(payload).unwrap()) as _,
|
|
|
+ crate::ios::json_to_dictionary(&serde_json::to_value(payload).unwrap()) as _,
|
|
|
crate::ios::PluginMessageCallback(plugin_method_response_handler),
|
|
|
);
|
|
|
}
|
|
@@ -317,7 +336,7 @@ impl<R: Runtime> PluginHandle<R> {
|
|
|
id: i32,
|
|
|
plugin: &'static str,
|
|
|
method: String,
|
|
|
- payload: serde_json::Value,
|
|
|
+ payload: &serde_json::Value,
|
|
|
runtime_handle: &R::Handle,
|
|
|
env: JNIEnv<'_>,
|
|
|
activity: JObject<'_>,
|
|
@@ -373,7 +392,7 @@ impl<R: Runtime> PluginHandle<R> {
|
|
|
);
|
|
|
|
|
|
handle.run_on_android_context(move |env, activity, _webview| {
|
|
|
- if let Err(e) = run::<R>(id, plugin_name, method, payload, &handle_, env, activity) {
|
|
|
+ if let Err(e) = run::<R>(id, plugin_name, method, &payload, &handle_, env, activity) {
|
|
|
tx_.send(Err(e)).unwrap();
|
|
|
}
|
|
|
});
|