use mobiler_core::*;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone)]
pub enum Msg {
EnableReminders,
NotifAllowed(PluginResponse),
ScheduleReminder { id: i64, title: String, body: String, after_seconds: i64 },
Scheduled(PluginResponse),
CancelReminder(i64),
Noop(PluginResponse),
}
impl MyApp {
fn handle(&self, msg: Msg, model: &mut Model, cx: &mut Cx<Msg>) {
match msg {
Msg::EnableReminders => cx.plugin("notifications", "requestPermission", "", Msg::NotifAllowed),
Msg::NotifAllowed(_resp) => { }
Msg::ScheduleReminder { id, title, body, after_seconds } => {
let input = format!(
r#"{{"id":{id},"title":"{title}","body":"{body}","after_seconds":{after_seconds}}}"#
);
cx.plugin("notifications", "schedule", input, Msg::Scheduled);
}
Msg::Scheduled(_resp) => { }
Msg::CancelReminder(id) => {
cx.plugin("notifications", "cancel", format!(r#"{{"id":{id}}}"#), Msg::Noop);
}
Msg::Noop(_) => {}
}
}
}