Skip to content

Commit

Permalink
fix: notify cannot be deleted from hidden view
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Aug 14, 2024
1 parent 9503c19 commit c826518
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions lala_bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand All @@ -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,
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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(),
}
}
Expand Down Expand Up @@ -318,7 +318,7 @@ impl LalaMusicBar {
let btns: Vec<Element<Message>> = self
.hidden_notifications()
.map(|wdgetinfo| {
container(wdgetinfo.notify_button())
container(wdgetinfo.notify_button(true))
.height(Length::Fixed(100.))
.into()
})
Expand Down Expand Up @@ -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,
Expand All @@ -408,7 +412,7 @@ enum Message {

impl From<NotifyMessage> for Message {
fn from(value: NotifyMessage) -> Self {
Self::Notify(value)
Self::Notify(value, false)
}
}

Expand Down Expand Up @@ -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(&notify.id) {
onotify.unit = notify;
return Command::none();
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -1080,18 +1087,18 @@ 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,
action_key: DEFAULT_ACTION.to_string(),
})
.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)) => {
Expand Down Expand Up @@ -1130,7 +1137,7 @@ impl MultiApplication for LalaMusicBar {
}
}
LaLaInfo::Notify(unitwidgetinfo) => {
let btnwidgets: Element<Message> = unitwidgetinfo.notify_button();
let btnwidgets: Element<Message> = unitwidgetinfo.notify_button(false);

let notify = &unitwidgetinfo.unit;
if notify.inline_reply_support() {
Expand Down

0 comments on commit c826518

Please sign in to comment.