Skip to content

Commit

Permalink
refactor: simplify scheduled notifications handling & remove unused `…
Browse files Browse the repository at this point in the history
…ShowLast` action
  • Loading branch information
jsonmaf1a committed Dec 11, 2024
1 parent e29825e commit 7a7a2c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
24 changes: 12 additions & 12 deletions crates/backend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::sync::{Arc, Mutex};
use std::thread;

use anyhow::Context;
Expand All @@ -21,7 +22,10 @@ use render::Renderer;

pub async fn run(config: Config) -> anyhow::Result<()> {
let (sender, mut receiver) = unbounded_channel();
let server = Server::init(sender).await?;
let sender = Arc::new(Mutex::new(sender));

let sender_lock = sender.lock().unwrap();
let server = Server::init(sender_lock.clone()).await?;
info!("Backend: Server initialized");

let (server_internal_channel, mut renderer) = Renderer::init(config)?;
Expand Down Expand Up @@ -56,23 +60,19 @@ pub async fn run(config: Config) -> anyhow::Result<()> {
Action::Close(None) => {
warn!("Backend: Unsupported method 'Close'. Ignored");
}
Action::ShowLast => {
//TODO: make decision about this action. It may be very useless
warn!("Backend: Unsupported method 'ShowLast'. Ignored");
}
Action::CloseAll => {
warn!("Backend: Unsupported method 'CloseAll'. Ignored");
}
}
}

let due_notifications = scheduler.pop_due_notifications();

for scheduled_notification in due_notifications {
server_internal_channel.send_to_renderer(
internal_messages::ServerMessage::ShowNotification(scheduled_notification.data),
)?;
}
scheduler
.pop_due_notifications()
.into_iter()
.for_each(|notification| {
let sender = sender.lock().unwrap();
sender.send(Action::Show(notification.data)).unwrap();
});

while let Ok(message) = server_internal_channel.try_recv_from_renderer() {
match message {
Expand Down
1 change: 0 additions & 1 deletion crates/dbus/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use super::notification::Notification;
pub enum Action {
Show(Box<Notification>),
Schedule(ScheduledNotification),
ShowLast, // NOTE: consider removing this
Close(Option<u32>),
CloseAll,
}
Expand Down

0 comments on commit 7a7a2c5

Please sign in to comment.