power management new
This commit is contained in:
parent
99b2e565b9
commit
632a0abd10
2 changed files with 34 additions and 15 deletions
|
|
@ -1,35 +1,52 @@
|
|||
use std::ops::Index;
|
||||
|
||||
use iced::{Subscription, Task};
|
||||
use ppd::PpdProxy;
|
||||
use zbus::connection::Connection;
|
||||
use ppd::PpdProxyBlocking;
|
||||
use zbus::blocking::Connection;
|
||||
|
||||
use crate::widget::{Message, PanelWidget};
|
||||
|
||||
pub struct PowerManagementWidget {
|
||||
pub struct PowerManagementWidget<'a> {
|
||||
window: Option<iced::window::Id>,
|
||||
current_mode: usize,
|
||||
names: Vec<Box<str>>,
|
||||
modes: Box<[Box<str>]>,
|
||||
proxy: PpdProxyBlocking<'a>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum PowerManagement {
|
||||
ToggleWindow,
|
||||
SetMode(SetMode),
|
||||
SetMode(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum SetMode {
|
||||
Saver,
|
||||
Medium,
|
||||
Performant,
|
||||
}
|
||||
|
||||
impl PowerManagementWidget {
|
||||
impl PowerManagementWidget<'_> {
|
||||
pub fn new() -> Self {
|
||||
let conn = Connection::system().await.unwrap();
|
||||
let conn = Connection::system().unwrap();
|
||||
let proxy = PpdProxyBlocking::new(&conn).unwrap();
|
||||
|
||||
let modes: Box<[Box<str>]> = proxy
|
||||
.profiles()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|f| f.profile.clone().into_boxed_str())
|
||||
.collect();
|
||||
|
||||
let current_mode_str = proxy.active_profile().unwrap();
|
||||
let current_mode = modes
|
||||
.iter()
|
||||
.position(|m| m.as_ref() == current_mode_str.as_str())
|
||||
.unwrap();
|
||||
|
||||
Self {
|
||||
window: None,
|
||||
modes,
|
||||
current_mode,
|
||||
proxy,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PanelWidget for PowerManagementWidget {
|
||||
impl PanelWidget for PowerManagementWidget<'_> {
|
||||
fn update(&mut self, message: &crate::widget::Message) -> iced::Task<crate::widget::Message> {
|
||||
let Message::PowerManagement(msg) = message else {
|
||||
return Task::none();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue