Skip to content

Commit

Permalink
feat: add time widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Sep 10, 2024
1 parent 30af33d commit 3ba0e74
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
44 changes: 44 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions lala_bar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ xdg = "2.5.2"
url.workspace = true
futures.workspace = true
zbus_notification.workspace = true
chrono = "0.4.38"
41 changes: 38 additions & 3 deletions lala_bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use zbus_notification::{
NOTIFICATION_SERVICE_PATH,
};

use chrono::prelude::*;
use iced_layershell::reexport::{Anchor, KeyboardInteractivity, Layer, NewLayerShellSettings};
use iced_layershell::settings::{LayerShellSettings, Settings};
use iced_layershell::MultiApplication;
Expand Down Expand Up @@ -197,9 +198,30 @@ struct LalaMusicBar {
sender: Sender<NotifyCommand>,
receiver: Arc<Mutex<Receiver<NotifyCommand>>>,
quite_mode: bool,

datetime: DateTime<Utc>,
}

impl LalaMusicBar {
fn date_widget(&self) -> Element<Message> {
let date = self.datetime.date_naive();
let dateday = date.format("%m-%d").to_string();
let week = date.format("%A").to_string();
let time = self.datetime.time();
let time_info = time.format("%H:%M").to_string();

container(row![
text(week),
Space::with_width(2.),
text(time_info),
Space::with_width(2.),
text(dateday)
])
.center_x()
.center_y()
.height(Length::Fill)
.into()
}
fn update_hidden_notification(&mut self) {
let mut hiddened: Vec<NotifyUnitWidgetInfo> = self
.notifications
Expand Down Expand Up @@ -491,6 +513,7 @@ enum Message {
RequestPause,
RequestPlay,
RequestDBusInfoUpdate,
RequestUpdateTime,
UpdateBalance,
DBusInfoUpdate(Option<ServiceInfo>),
BalanceChanged(u8),
Expand Down Expand Up @@ -556,7 +579,9 @@ impl LalaMusicBar {
toggle_launcher,
Space::with_width(Length::Fill),
container(sound_slider).width(700.),
Space::with_width(Length::Fixed(10.)),
Space::with_width(Length::Fixed(3.)),
self.date_widget(),
Space::with_width(Length::Fixed(3.)),
button(text(panel_text)).on_press(Message::ToggleRightPanel)
]
.spacing(10);
Expand Down Expand Up @@ -648,7 +673,9 @@ impl LalaMusicBar {
Space::with_width(Length::Fill),
buttons,
sound_slider,
Space::with_width(Length::Fixed(10.)),
Space::with_width(Length::Fixed(3.)),
self.date_widget(),
Space::with_width(Length::Fixed(3.)),
button(text(panel_text)).on_press(Message::ToggleRightPanel)
]
.spacing(10)
Expand All @@ -659,7 +686,9 @@ impl LalaMusicBar {
Space::with_width(Length::Fill),
buttons,
sound_slider,
Space::with_width(Length::Fixed(10.)),
Space::with_width(Length::Fixed(3.)),
self.date_widget(),
Space::with_width(Length::Fixed(3.)),
button(text(panel_text)).on_press(Message::ToggleRightPanel)
]
.spacing(10)
Expand Down Expand Up @@ -700,6 +729,7 @@ impl MultiApplication for LalaMusicBar {
sender,
receiver: Arc::new(Mutex::new(receiver)),
quite_mode: false,
datetime: Utc::now(),
},
Command::perform(get_metadata_initial(), Message::DBusInfoUpdate),
)
Expand Down Expand Up @@ -1174,6 +1204,9 @@ impl MultiApplication for LalaMusicBar {
Message::CloseErrorNotification(id) => {
return Command::single(Action::Window(WindowAction::Close(id)));
}
Message::RequestUpdateTime => {
self.datetime = Utc::now();
}
}
Command::none()
}
Expand Down Expand Up @@ -1241,6 +1274,8 @@ impl MultiApplication for LalaMusicBar {
iced::subscription::Subscription::batch([
iced::time::every(std::time::Duration::from_secs(1))
.map(|_| Message::RequestDBusInfoUpdate),
iced::time::every(std::time::Duration::from_secs(60))
.map(|_| Message::RequestUpdateTime),
iced::time::every(std::time::Duration::from_secs(5)).map(|_| Message::UpdateBalance),
iced::event::listen()
.map(|event| Message::LauncherInfo(LaunchMessage::IcedEvent(event))),
Expand Down

0 comments on commit 3ba0e74

Please sign in to comment.