Skip to content

Commit

Permalink
fix: flash problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Aug 14, 2024
1 parent b8874c6 commit b2460c4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lala_bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ struct LalaMusicBar {
right_panel: Option<iced::window::Id>,
notifications: HashMap<u32, NotifyUnitWidgetInfo>,
showned_notifications: HashMap<iced::window::Id, u32>,
cached_notifications: HashMap<iced::window::Id, NotifyUnitWidgetInfo>,
sender: Sender<NotifyCommand>,
receiver: Arc<Mutex<Receiver<NotifyCommand>>>,
quite_mode: bool,
Expand Down Expand Up @@ -552,6 +553,7 @@ impl MultiApplication for LalaMusicBar {
hidenid: None,
notifications: HashMap::new(),
showned_notifications: HashMap::new(),
cached_notifications: HashMap::new(),
sender,
receiver: Arc::new(Mutex::new(receiver)),
quite_mode: false,
Expand All @@ -572,6 +574,9 @@ impl MultiApplication for LalaMusicBar {
} else if self.right_panel.is_some_and(|tid| tid == id) {
Some(LaLaInfo::RightPanel)
} else {
if let Some(info) = self.cached_notifications.get(&id) {
return Some(LaLaInfo::Notify(Box::new(info.clone())));
}
let notify_id = self.showned_notifications.get(&id)?;
self.notifications
.get(notify_id)
Expand Down Expand Up @@ -608,6 +613,7 @@ impl MultiApplication for LalaMusicBar {
self.hidenid.take();
}
self.showned_notifications.remove(&id);
self.cached_notifications.remove(&id);
}

fn update(&mut self, message: Message) -> Command<Message> {
Expand Down Expand Up @@ -934,12 +940,13 @@ impl MultiApplication for LalaMusicBar {

Message::Notify(NotifyMessage::UnitRemove(removed_id)) => {
let mut commands = vec![];
if let Some(id) = self
if let Some((id, nid)) = self
.showned_notifications
.iter()
.find(|(_, nid)| **nid == removed_id)
.map(|(id, _)| id)
{
self.cached_notifications
.insert(*id, self.notifications.get(nid).cloned().unwrap());
commands.push(Command::single(Action::Window(WindowAction::Close(*id))));
}

Expand Down

0 comments on commit b2460c4

Please sign in to comment.