diff --git a/plugins/push-notifications/src/mobile.rs b/plugins/push-notifications/src/mobile.rs index e08fc9ad..563c1826 100644 --- a/plugins/push-notifications/src/mobile.rs +++ b/plugins/push-notifications/src/mobile.rs @@ -1,3 +1,4 @@ +use base64::{engine::general_purpose, Engine as _}; use serde::de::DeserializeOwned; use tauri::{ plugin::{PluginApi, PluginHandle}, @@ -15,7 +16,7 @@ pub fn init( api: PluginApi, ) -> crate::Result> { #[cfg(target_os = "android")] - let handle = api.register_android_plugin("", "ExamplePlugin")?; + let handle = api.register_android_plugin("", "PushNotificationsPlugin")?; #[cfg(target_os = "ios")] let handle = api.register_ios_plugin(init_plugin_push_notifications)?; Ok(PushNotifications(handle)) @@ -25,9 +26,20 @@ pub fn init( pub struct PushNotifications(PluginHandle); impl PushNotifications { - pub fn get_push_token(&self, payload: PushTokenRequest) -> crate::Result { - Ok(PushTokenResponse { - value: Some("testing-not-real".as_bytes().to_vec()), - }) + pub fn get_push_token( + &self, + state: State>, + _payload: PushTokenRequest, + ) -> crate::Result { + let state = state.lock().unwrap(); + match &state.token { + Some(token) => { + let encoded = general_purpose::STANDARD.encode(&token); + Ok(PushTokenResponse { + value: Some(encoded.clone()), + }) + } + None => Ok(PushTokenResponse { value: None }), + } } }