//! The share sheet, on the phone. //! //! Another app's Share → SoulStream (a Spotify playlist, a YouTube set, a //! pasted tracklist) starts the plugin's `ShareActivity`, which keeps the //! text and brings the app to the front. The WebView asks for it with //! `pending_share` → `{ text }` — at boot, and whenever the app comes back //! to the front — and hands it to the playlist import. Read once: the //! second ask answers nothing. On the desktop the plugin is registered so //! the permission set resolves, and the command answers nothing. use serde::{Deserialize, Serialize}; use tauri::{ plugin::{Builder, TauriPlugin}, Runtime, }; #[derive(Debug, Clone, Serialize, Deserialize, Default)] #[serde(rename_all = "camelCase")] pub struct Shared { pub text: Option, } #[cfg(mobile)] pub struct Share(tauri::plugin::PluginHandle); #[tauri::command] fn pending_share(app: tauri::AppHandle) -> Result { #[cfg(mobile)] { use tauri::Manager; let share = app.state::>(); share .0 .run_mobile_plugin::("pendingShare", ()) .map_err(|e| e.to_string()) } #[cfg(not(mobile))] { let _ = app; Ok(Shared::default()) } } pub fn init() -> TauriPlugin { Builder::new("share") .invoke_handler(tauri::generate_handler![pending_share]) .setup(|app, api| { #[cfg(target_os = "android")] { use tauri::Manager; let handle = api.register_android_plugin("com.soulstream.share", "SharePlugin")?; app.manage(Share(handle)); } #[cfg(not(target_os = "android"))] { let _ = (app, api); } Ok(()) }) .build() }