forked from max_ag/wayland_panel
batery and time working (POC more than anything)
This commit is contained in:
parent
70ad7e9b65
commit
958b7714da
7 changed files with 107 additions and 25 deletions
73
src/main.rs
73
src/main.rs
|
|
@ -1,16 +1,21 @@
|
|||
use chrono::Local;
|
||||
use iced::Color;
|
||||
use iced::Element;
|
||||
use iced::Subscription;
|
||||
use iced::Task;
|
||||
use iced::widget::Row;
|
||||
use iced::widget::container;
|
||||
use iced::widget::row;
|
||||
use iced::widget::text;
|
||||
use iced_layershell::daemon;
|
||||
use iced_layershell::reexport::Anchor;
|
||||
use iced_layershell::settings::LayerShellSettings;
|
||||
use iced_layershell::settings::Settings;
|
||||
use iced_layershell::to_layer_message;
|
||||
use std::time::Duration;
|
||||
|
||||
pub fn main() -> Result<(), iced_layershell::Error> {
|
||||
daemon(App::default, || "rbaw".into(), App::update, App::view)
|
||||
.style(App::style)
|
||||
.theme(App::theme)
|
||||
.subscription(App::subscription)
|
||||
.settings(Settings {
|
||||
layer_settings: LayerShellSettings {
|
||||
|
|
@ -25,29 +30,66 @@ pub fn main() -> Result<(), iced_layershell::Error> {
|
|||
.run()
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct App {}
|
||||
struct App {
|
||||
time: chrono::DateTime<chrono::Local>,
|
||||
battery: String,
|
||||
}
|
||||
|
||||
impl Default for App {
|
||||
fn default() -> Self {
|
||||
let mut output = Self {
|
||||
time: Default::default(),
|
||||
battery: Default::default(),
|
||||
};
|
||||
let _ = output.update(Message::Clock);
|
||||
|
||||
output
|
||||
}
|
||||
}
|
||||
|
||||
impl App {
|
||||
fn view(&self, _id: iced::window::Id) -> Element<'_, Message> {
|
||||
let content = Row::new();
|
||||
let display_time = self.time.format("%H:%M");
|
||||
|
||||
container(content)
|
||||
.width(iced::Length::Fill)
|
||||
.height(iced::Length::Fill)
|
||||
.into()
|
||||
let content = row![
|
||||
text!("{}", display_time),
|
||||
iced::widget::space().width(iced::Length::Fill),
|
||||
text!("{}", self.battery),
|
||||
]
|
||||
.padding(iced::Padding::from([0, 5]))
|
||||
.height(iced::Length::Fill)
|
||||
.width(iced::Length::Fill)
|
||||
.align_y(iced::Alignment::Center);
|
||||
|
||||
container(content).into()
|
||||
}
|
||||
fn update(&mut self, _message: Message) -> Task<Message> {
|
||||
|
||||
fn update(&mut self, message: Message) -> Task<Message> {
|
||||
if let Message::Clock = message {
|
||||
self.time = Local::now();
|
||||
self.battery = format!(
|
||||
"{} ",
|
||||
std::fs::read_to_string(std::path::Path::new(
|
||||
"/sys/class/power_supply/BAT0/capacity",
|
||||
))
|
||||
.unwrap()
|
||||
.trim_ascii_end()
|
||||
);
|
||||
}
|
||||
|
||||
Task::none()
|
||||
}
|
||||
fn style(&self, _theme: &iced::Theme) -> iced::theme::Style {
|
||||
todo!()
|
||||
fn style(&self, theme: &iced::Theme) -> iced::theme::Style {
|
||||
iced::theme::Style {
|
||||
background_color: Color::TRANSPARENT,
|
||||
text_color: theme.palette().text,
|
||||
}
|
||||
}
|
||||
fn theme(&self) -> iced::Theme {
|
||||
todo!()
|
||||
fn theme(&self, _id: iced::window::Id) -> iced::Theme {
|
||||
iced::Theme::GruvboxDark
|
||||
}
|
||||
fn subscription(&self) -> iced::Subscription<Message> {
|
||||
Subscription::none()
|
||||
iced::time::every(Duration::from_secs(1)).map(|_| Message::Clock)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -55,4 +97,5 @@ impl App {
|
|||
#[derive(Debug)]
|
||||
enum Message {
|
||||
IcedEvent(iced::Event),
|
||||
Clock,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue