use mobiler_core::*;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone)]
pub enum Msg {
EnableFetch,
Fetch(PluginResponse),
Noop(PluginResponse),
}
#[derive(Default, Serialize, Deserialize)]
pub struct Model {
pub fetches: u32,
}
impl MyApp {
fn handle(&self, msg: Msg, model: &mut Model, cx: &mut Cx<Msg>) {
match msg {
Msg::EnableFetch => {
cx.plugin(
"background-fetch",
"schedule",
r#"{"id":"refresh","min_interval_seconds":3600,"notify_title":"Updated","notify_body":"New data ready"}"#,
Msg::Noop,
);
cx.subscribe("background-fetch", "background-fetch", "events", "", Msg::Fetch);
}
Msg::Fetch(r) => {
if r.ok {
model.fetches += 1;
}
}
Msg::Noop(_r) => {}
}
}
}