Skip to content

Commit

Permalink
chore: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sundaram123krishnan committed Nov 17, 2024
1 parent eb3ba02 commit 406d4b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
3 changes: 1 addition & 2 deletions lala_bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ pub enum Message {
Ready(Sender<NotifyCommand>),
#[allow(unused)]
LinkClicked(markdown::Url),
Close(iced::window::Id),
NewWindowRight,
ToggleCalendar,
Cancel,
Submit(Date),
}
Expand Down
47 changes: 22 additions & 25 deletions lala_bar/src/music_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,7 @@ impl LalaMusicBar {
let week = date.format("%A").to_string();
let time = self.datetime.time();
let time_info = time.format("%H:%M").to_string();
let mut week_btn = button(text(week.clone())).on_press(Message::NewWindowRight);
if self.is_calendar_open && self.calendar_id.is_some() {
week_btn =
button(text(week.clone())).on_press(Message::Close(self.calendar_id.unwrap()));
} else {
week_btn = button(text(week.clone())).on_press(Message::NewWindowRight);
}
let week_btn = button(text(week.clone())).on_press(Message::ToggleCalendar);
container(row![
week_btn,
Space::with_width(5.),
Expand Down Expand Up @@ -602,24 +596,27 @@ impl MultiApplication for LalaMusicBar {
Message::RequestDBusInfoUpdate => {
return Command::perform(get_metadata(), Message::DBusInfoUpdate)
}
Message::Close(id) => {
self.is_calendar_open = false;
return iced_runtime::task::effect(Action::Window(WindowAction::Close(id)));
}
Message::NewWindowRight => {
self.is_calendar_open = true;
return Command::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
size: Some((400, 350)),
exclusive_zone: None,
anchor: Anchor::Right | Anchor::Bottom,
layer: Layer::Top,
margin: Some((10, 10, 10, 10)),
keyboard_interactivity: KeyboardInteractivity::Exclusive,
use_last_output: false,
},
info: LaLaInfo::Calendar,
});
Message::ToggleCalendar => {
if self.is_calendar_open && self.calendar_id.is_some() {
self.is_calendar_open = false;
return iced_runtime::task::effect(Action::Window(WindowAction::Close(
self.calendar_id.unwrap(),
)));
} else {
self.is_calendar_open = true;
return Command::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
size: Some((400, 350)),
exclusive_zone: None,
anchor: Anchor::Right | Anchor::Bottom,
layer: Layer::Top,
margin: Some((10, 10, 10, 10)),
keyboard_interactivity: KeyboardInteractivity::Exclusive,
use_last_output: false,
},
info: LaLaInfo::Calendar,
});
}
}

Message::Submit(date) => {
Expand Down

0 comments on commit 406d4b2

Please sign in to comment.