diff --git a/lala_bar/src/main.rs b/lala_bar/src/main.rs index 565c0c6..7b71260 100644 --- a/lala_bar/src/main.rs +++ b/lala_bar/src/main.rs @@ -85,7 +85,7 @@ struct NotifyUnitWidgetInfo { } impl NotifyUnitWidgetInfo { - fn notify_button<'a>(&self) -> Element<'a, Message> { + fn notify_button<'a>(&self, from_hidden_view: bool) -> Element<'a, Message> { let notify = &self.unit; match notify.image() { Some(ImageInfo::Svg(path)) => button(row![ @@ -107,7 +107,7 @@ impl NotifyUnitWidgetInfo { .style(iced::theme::Button::Secondary) .width(Length::Fill) .height(Length::Fill) - .on_press(Message::RemoveNotify(self.unit.id)) + .on_press(Message::RemoveNotify(self.unit.id, from_hidden_view)) .into(), Some(ImageInfo::Data { width, @@ -134,7 +134,7 @@ impl NotifyUnitWidgetInfo { .width(Length::Fill) .height(Length::Fill) .style(iced::theme::Button::Secondary) - .on_press(Message::RemoveNotify(self.unit.id)) + .on_press(Message::RemoveNotify(self.unit.id, from_hidden_view)) .into(), Some(ImageInfo::Png(path)) | Some(ImageInfo::Jpg(path)) => button(row![ image(image::Handle::from_path(path)).height(Length::Fill), @@ -153,7 +153,7 @@ impl NotifyUnitWidgetInfo { .width(Length::Fill) .height(Length::Fill) .style(iced::theme::Button::Secondary) - .on_press(Message::RemoveNotify(self.unit.id)) + .on_press(Message::RemoveNotify(self.unit.id, from_hidden_view)) .into(), _ => button(column![ text(notify.summery.clone()).shaping(text::Shaping::Advanced), @@ -162,7 +162,7 @@ impl NotifyUnitWidgetInfo { .width(Length::Fill) .height(Length::Fill) .style(iced::theme::Button::Secondary) - .on_press(Message::RemoveNotify(self.unit.id)) + .on_press(Message::RemoveNotify(self.unit.id, from_hidden_view)) .into(), } } @@ -318,7 +318,7 @@ impl LalaMusicBar { let btns: Vec> = self .hidden_notifications() .map(|wdgetinfo| { - container(wdgetinfo.notify_button()) + container(wdgetinfo.notify_button(true)) .height(Length::Fixed(100.)) .into() }) @@ -396,8 +396,12 @@ enum Message { ToggleLauncher, ToggleRightPanel, LauncherInfo(LaunchMessage), - Notify(NotifyMessage), - RemoveNotify(u32), + /// NOTE: The bool value marked if it is from hidden_view + /// if it is from hidden_view, the notification should be removed immedietaly + Notify(NotifyMessage, bool), + /// NOTE: The bool value marked if it is from hidden_view + /// if it is from hidden_view, the notification should be removed immedietaly + RemoveNotify(u32, bool), InlineReply((u32, String)), InlineReplyMsgUpdate((iced::window::Id, String)), CheckOutput, @@ -408,7 +412,7 @@ enum Message { impl From for Message { fn from(value: NotifyMessage) -> Self { - Self::Notify(value) + Self::Notify(value, false) } } @@ -781,7 +785,7 @@ impl MultiApplication for LalaMusicBar { .into(), ); } - Message::Notify(NotifyMessage::UnitAdd(notify)) => { + Message::Notify(NotifyMessage::UnitAdd(notify), _) => { if let Some(onotify) = self.notifications.get_mut(¬ify.id) { onotify.unit = notify; return Command::none(); @@ -962,7 +966,7 @@ impl MultiApplication for LalaMusicBar { return Command::batch(commands); } - Message::Notify(NotifyMessage::UnitRemove(removed_id)) => { + Message::Notify(NotifyMessage::UnitRemove(removed_id), from_hidden_view) => { let mut commands = vec![]; if let Some((id, nid)) = self .showned_notifications @@ -986,6 +990,9 @@ impl MultiApplication for LalaMusicBar { // NOTE: already removed return Command::none(); }; + if from_hidden_view { + self.notifications.remove(&removed_id); + } for (_, notify) in self.notifications.iter_mut() { if notify.counter > removed_counter { @@ -1080,10 +1087,10 @@ impl MultiApplication for LalaMusicBar { }) .ok(); return Command::perform(async {}, move |_| { - Message::Notify(NotifyMessage::UnitRemove(notify_id)) + Message::Notify(NotifyMessage::UnitRemove(notify_id), false) }); } - Message::RemoveNotify(notify_id) => { + Message::RemoveNotify(notify_id, from_hidden_view) => { self.sender .try_send(NotifyCommand::ActionInvoked { id: notify_id, @@ -1091,7 +1098,7 @@ impl MultiApplication for LalaMusicBar { }) .ok(); return Command::perform(async {}, move |_| { - Message::Notify(NotifyMessage::UnitRemove(notify_id)) + Message::Notify(NotifyMessage::UnitRemove(notify_id), from_hidden_view) }); } Message::InlineReplyMsgUpdate((id, msg)) => { @@ -1130,7 +1137,7 @@ impl MultiApplication for LalaMusicBar { } } LaLaInfo::Notify(unitwidgetinfo) => { - let btnwidgets: Element = unitwidgetinfo.notify_button(); + let btnwidgets: Element = unitwidgetinfo.notify_button(false); let notify = &unitwidgetinfo.unit; if notify.inline_reply_support() {