use serde::de::DeserializeOwned; use tauri::{ plugin::{PluginApi, PluginHandle}, AppHandle, Runtime, }; use crate::models::*; #[cfg(target_os = "ios")] tauri::ios_plugin_binding!(init_plugin_native_bridge); // initializes the Kotlin or Swift plugin classes pub fn init( _app: &AppHandle, api: PluginApi, ) -> crate::Result> { #[cfg(target_os = "android")] let handle = api.register_android_plugin("com.readest.native_bridge", "NativeBridgePlugin")?; #[cfg(target_os = "ios")] let handle = api.register_ios_plugin(init_plugin_native_bridge)?; Ok(NativeBridge(handle)) } /// Access to the native-bridge APIs. pub struct NativeBridge(PluginHandle); impl NativeBridge { pub fn auth_with_safari(&self, payload: AuthRequest) -> crate::Result { self.0 .run_mobile_plugin("auth_with_safari", payload) .map_err(Into::into) } } impl NativeBridge { pub fn auth_with_custom_tab(&self, payload: AuthRequest) -> crate::Result { self.0 .run_mobile_plugin("auth_with_custom_tab", payload) .map_err(Into::into) } } impl NativeBridge { pub fn copy_uri_to_path(&self, payload: CopyURIRequest) -> crate::Result { self.0 .run_mobile_plugin("copy_uri_to_path", payload) .map_err(Into::into) } } impl NativeBridge { pub fn use_background_audio(&self, payload: UseBackgroundAudioRequest) -> crate::Result<()> { self.0 .run_mobile_plugin("use_background_audio", payload) .map_err(Into::into) } } impl NativeBridge { pub fn install_package( &self, payload: InstallPackageRequest, ) -> crate::Result { self.0 .run_mobile_plugin("install_package", payload) .map_err(Into::into) } } impl NativeBridge { pub fn set_system_ui_visibility( &self, payload: SetSystemUIVisibilityRequest, ) -> crate::Result { self.0 .run_mobile_plugin("set_system_ui_visibility", payload) .map_err(Into::into) } } impl NativeBridge { pub fn get_status_bar_height(&self) -> crate::Result { self.0 .run_mobile_plugin("get_status_bar_height", ()) .map_err(Into::into) } } impl NativeBridge { pub fn get_sys_fonts_list(&self) -> crate::Result { self.0 .run_mobile_plugin("get_sys_fonts_list", ()) .map_err(Into::into) } } impl NativeBridge { pub fn intercept_keys(&self, payload: InterceptKeysRequest) -> crate::Result<()> { self.0 .run_mobile_plugin("intercept_keys", payload) .map_err(Into::into) } } impl NativeBridge { pub fn lock_screen_orientation( &self, payload: LockScreenOrientationRequest, ) -> crate::Result<()> { self.0 .run_mobile_plugin("lock_screen_orientation", payload) .map_err(Into::into) } } impl NativeBridge { pub fn iap_is_available(&self) -> crate::Result { self.0 .run_mobile_plugin("iap_is_available", ()) .map_err(Into::into) } } impl NativeBridge { pub fn iap_initialize( &self, payload: IAPInitializeRequest, ) -> crate::Result { self.0 .run_mobile_plugin("iap_initialize", payload) .map_err(Into::into) } } impl NativeBridge { pub fn iap_fetch_products( &self, payload: IAPFetchProductsRequest, ) -> crate::Result { self.0 .run_mobile_plugin("iap_fetch_products", payload) .map_err(Into::into) } } impl NativeBridge { pub fn iap_purchase_product( &self, payload: IAPPurchaseProductRequest, ) -> crate::Result { self.0 .run_mobile_plugin("iap_purchase_product", payload) .map_err(Into::into) } } impl NativeBridge { pub fn iap_restore_purchases(&self) -> crate::Result { self.0 .run_mobile_plugin("iap_restore_purchases", ()) .map_err(Into::into) } } impl NativeBridge { pub fn get_system_color_scheme(&self) -> crate::Result { self.0 .run_mobile_plugin("get_system_color_scheme", ()) .map_err(Into::into) } } impl NativeBridge { pub fn get_safe_area_insets(&self) -> crate::Result { self.0 .run_mobile_plugin("get_safe_area_insets", ()) .map_err(Into::into) } } impl NativeBridge { pub fn get_screen_brightness(&self) -> crate::Result { self.0 .run_mobile_plugin("get_screen_brightness", ()) .map_err(Into::into) } } impl NativeBridge { pub fn set_screen_brightness( &self, payload: SetScreenBrightnessRequest, ) -> crate::Result { self.0 .run_mobile_plugin("set_screen_brightness", payload) .map_err(Into::into) } } impl NativeBridge { pub fn get_external_sdcard_path(&self) -> crate::Result { self.0 .run_mobile_plugin("get_external_sdcard_path", ()) .map_err(Into::into) } } impl NativeBridge { pub fn open_external_url( &self, payload: OpenExternalUrlRequest, ) -> crate::Result { self.0 .run_mobile_plugin("open_external_url", payload) .map_err(Into::into) } } impl NativeBridge { pub fn select_directory(&self) -> crate::Result { self.0 .run_mobile_plugin("select_directory", ()) .map_err(Into::into) } } impl NativeBridge { pub fn get_storefront_region_code(&self) -> crate::Result { self.0 .run_mobile_plugin("get_storefront_region_code", ()) .map_err(Into::into) } } impl NativeBridge { pub fn request_manage_storage_permission( &self, ) -> crate::Result { self.0 .run_mobile_plugin("request_manage_storage_permission", ()) .map_err(Into::into) } }