Skip to content

Commit

Permalink
Send a browser notification when receiving an email
Browse files Browse the repository at this point in the history
  • Loading branch information
rustmaestro authored and marlonbaeten committed Oct 20, 2024
1 parent 862edbd commit 4baf603
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ web-sys = { version = "0.3", features = [
"HtmlIFrameElement",
"HtmlLinkElement",
"MediaQueryList",
"NodeList"
"NodeList",
"Notification",
"NotificationOptions",
] }
yew = "0.21"
yew-hooks = "0.3"
14 changes: 14 additions & 0 deletions frontend/src/overview.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use futures::{channel::mpsc::Sender, StreamExt};
use gloo_console::error;
use wasm_bindgen_futures::spawn_local;
use web_sys::NotificationOptions;
use yew::prelude::*;

use crate::{
Expand Down Expand Up @@ -64,6 +65,8 @@ impl Component for Overview {
init_dark_mode();
});

web_sys::Notification::request_permission().ok();

Self {
messages: vec![],
tab: Tab::Formatted,
Expand All @@ -79,6 +82,17 @@ impl Component for Overview {
self.loading = value;
}
Msg::Message(message) => {
let notif_options = NotificationOptions::default();
notif_options.set_body(&message.subject);
let _ = web_sys::Notification::new_with_options(
&format!(
"MailCrab: {} <{}>",
message.from.name.clone().unwrap_or_default(),
message.from.email.clone().unwrap_or_default()
),
&notif_options,
);

self.messages.push(*message);
}
Msg::Messages(messages) => {
Expand Down

0 comments on commit 4baf603

Please sign in to comment.