feat(apns): implement push notifications facade for mobile

Signed-off-by: Sam Gammon <s@mg.sv>
pull/2066/head
Sam Gammon 8 months ago
parent 0fe64f103b
commit 63b47afd52

@ -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<R: Runtime, C: DeserializeOwned>(
api: PluginApi<R, C>,
) -> crate::Result<PushNotifications<R>> {
#[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<R: Runtime, C: DeserializeOwned>(
pub struct PushNotifications<R: Runtime>(PluginHandle<R>);
impl<R: Runtime> PushNotifications<R> {
pub fn get_push_token(&self, payload: PushTokenRequest) -> crate::Result<PushTokenResponse> {
Ok(PushTokenResponse {
value: Some("testing-not-real".as_bytes().to_vec()),
})
pub fn get_push_token(
&self,
state: State<Mutex<PushTokenState>>,
_payload: PushTokenRequest,
) -> crate::Result<PushTokenResponse> {
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 }),
}
}
}

Loading…
Cancel
Save