Skip to content

Commit

Permalink
feat: support remove all notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Aug 10, 2024
1 parent cd82f0d commit 79a044c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions lala_bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum LaLaInfo {
#[derive(Debug, Clone)]
struct NotifyUnitWidgetInfo {
uper: i32,

Check warning on line 53 in lala_bar/src/main.rs

View workflow job for this annotation

GitHub Actions / build

"uper" should be "super" or "upper".
counter: usize,
unit: NotifyUnit,
}

Expand Down Expand Up @@ -325,6 +326,26 @@ impl LalaMusicBar {
}
}

impl LalaMusicBar {
fn counter_up(&mut self) {
for (_, unit) in self.notifications.iter_mut() {
unit.counter += 1;
}
}
fn counter_down(&mut self, ids: &Vec<iced::window::Id>) {
for id in ids {
if let Some(NotifyUnitWidgetInfo { counter, .. }) = self.notifications.remove(id) {
for (_, unit) in self.notifications.iter_mut() {
if unit.counter > counter {
unit.counter -= 1;
unit.uper -= 75;

Check warning on line 341 in lala_bar/src/main.rs

View workflow job for this annotation

GitHub Actions / build

"uper" should be "super" or "upper".
}
}
}
}
}
}

impl MultiApplication for LalaMusicBar {
type Message = Message;
type Flags = ();
Expand Down Expand Up @@ -367,9 +388,11 @@ impl MultiApplication for LalaMusicBar {
self.launcherid = Some(id);
}
LaLaInfo::Notify(nofify) => {
self.counter_up();
self.notifications
.entry(id)
.or_insert(NotifyUnitWidgetInfo {
counter: 0,
uper: 10,

Check warning on line 396 in lala_bar/src/main.rs

View workflow job for this annotation

GitHub Actions / build

"uper" should be "super" or "upper".
unit: nofify,
});
Expand Down Expand Up @@ -535,6 +558,15 @@ impl MultiApplication for LalaMusicBar {
return Command::batch(commands);
}
Message::Notify(NotifyMessage::UnitRemove(removed_id)) => {
let removed_ids: Vec<iced::window::Id> = self
.notifications
.iter()
.filter(|(_, info)| {
let NotifyUnit { id, .. } = info.unit;
removed_id == id
})
.map(|(id, _)| id.clone())
.collect();
let mut commands: Vec<_> = self
.notifications
.iter()
Expand All @@ -544,6 +576,18 @@ impl MultiApplication for LalaMusicBar {
})
.map(|(id, _)| Command::single(Action::Window(WindowAction::Close(*id))))
.collect();

self.counter_down(&removed_ids);
for (id, unit) in self.notifications.iter() {
commands.push(Command::single(
LaLaShellIdAction::new(
*id,
LalaShellAction::MarginChange((unit.uper, 10, 10, 10)),

Check warning on line 585 in lala_bar/src/main.rs

View workflow job for this annotation

GitHub Actions / build

"uper" should be "super" or "upper".
)
.into(),
));
}

commands.push(Command::perform(async {}, |_| Message::CheckOutput));

return Command::batch(commands);
Expand Down

0 comments on commit 79a044c

Please sign in to comment.