From 63b47afd521006190481b05a2451c4000062ef45 Mon Sep 17 00:00:00 2001 From: Sam Gammon Date: Mon, 18 Nov 2024 00:07:40 -0800 Subject: [PATCH] feat(apns): implement push notifications facade for mobile Signed-off-by: Sam Gammon --- plugins/push-notifications/src/mobile.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) 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 }), + } } }