improv(power): match page to designs and fix import

This commit is contained in:
Vukašin Vojinović 2024-06-01 21:32:36 +02:00 committed by GitHub
parent 9294d9d476
commit 257e39d717
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 31 deletions

View file

@ -54,42 +54,42 @@ pub async fn get_backend() -> Option<PowerBackendEnum> {
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum PowerProfile { pub enum PowerProfile {
Performance,
Balanced,
Battery, Battery,
Balanced,
Performance,
} }
impl PowerProfile { impl PowerProfile {
fn from_string(s: &str) -> PowerProfile { fn from_string(s: &str) -> PowerProfile {
match s { match s {
"Performance" | "performance" => Self::Performance,
"Battery" | "power-saver" => Self::Battery, "Battery" | "power-saver" => Self::Battery,
"Performance" | "performance" => Self::Performance,
_ => Self::Balanced, _ => Self::Balanced,
} }
} }
pub fn title(&self) -> String { pub fn title(&self) -> String {
match self { match self {
Self::Performance => fl!("power-profiles", "performance"), Self::Battery => fl!("power-mode", "battery"),
Self::Balanced => fl!("power-profiles", "balanced"), Self::Balanced => fl!("power-mode", "balanced"),
Self::Battery => fl!("power-profiles", "battery"), Self::Performance => fl!("power-mode", "performance"),
} }
} }
pub fn description(&self) -> String { pub fn description(&self) -> String {
match self { match self {
Self::Performance => fl!("power-profiles", "performance-desc"), Self::Battery => fl!("power-mode", "battery-desc"),
Self::Balanced => fl!("power-profiles", "balanced-desc"), Self::Balanced => fl!("power-mode", "balanced-desc"),
Self::Battery => fl!("power-profiles", "battery-desc"), Self::Performance => fl!("power-mode", "performance-desc"),
} }
} }
} }
pub fn get_power_profiles() -> Vec<PowerProfile> { pub fn get_power_profiles() -> Vec<PowerProfile> {
vec![ vec![
PowerProfile::Performance,
PowerProfile::Balanced,
PowerProfile::Battery, PowerProfile::Battery,
PowerProfile::Balanced,
PowerProfile::Performance,
] ]
} }
@ -108,16 +108,16 @@ impl SetPowerProfile for S76Backend {
}; };
match profile { match profile {
PowerProfile::Performance => match daemon.performance().await { PowerProfile::Battery => match daemon.battery().await {
Ok(x) => tracing::info!("Performance mode activated."), Ok(x) => tracing::info!("Battery mode activated."),
Err(e) => tracing::error!("{e}"), Err(e) => tracing::error!("{e}"),
}, },
PowerProfile::Balanced => match daemon.balanced().await { PowerProfile::Balanced => match daemon.balanced().await {
Ok(x) => tracing::info!("Balanced mode activated."), Ok(x) => tracing::info!("Balanced mode activated."),
Err(e) => tracing::error!("{e}"), Err(e) => tracing::error!("{e}"),
}, },
PowerProfile::Battery => match daemon.battery().await { PowerProfile::Performance => match daemon.performance().await {
Ok(x) => tracing::info!("Battery mode activated."), Ok(x) => tracing::info!("Performance mode activated."),
Err(e) => tracing::error!("{e}"), Err(e) => tracing::error!("{e}"),
}, },
} }
@ -159,7 +159,7 @@ async fn get_s76power_daemon_proxy<'a>() -> Result<s76powerdaemon::PowerDaemonPr
match s76powerdaemon::PowerDaemonProxy::new(&connection).await { match s76powerdaemon::PowerDaemonProxy::new(&connection).await {
Ok(d) => Ok(d), Ok(d) => Ok(d),
Err(e) => { Err(e) => {
tracing::error!("Power daemon proxy can't created. Is it installed? {e}"); tracing::error!("Power daemon proxy can't be created. Is it installed? {e}");
Err(()) Err(())
} }
} }
@ -180,16 +180,16 @@ impl SetPowerProfile for PPBackend {
}; };
match profile { match profile {
PowerProfile::Performance => match daemon.set_active_profile("performance").await { PowerProfile::Battery => match daemon.set_active_profile("power-saver").await {
Ok(x) => tracing::info!("Performance mode activated."), Ok(x) => tracing::info!("Battery mode activated."),
Err(e) => tracing::error!("{e}"), Err(e) => tracing::error!("{e}"),
}, },
PowerProfile::Balanced => match daemon.set_active_profile("balanced").await { PowerProfile::Balanced => match daemon.set_active_profile("balanced").await {
Ok(x) => tracing::info!("Balanced mode activated."), Ok(x) => tracing::info!("Balanced mode activated."),
Err(e) => tracing::error!("{e}"), Err(e) => tracing::error!("{e}"),
}, },
PowerProfile::Battery => match daemon.set_active_profile("power-saver").await { PowerProfile::Performance => match daemon.set_active_profile("performance").await {
Ok(x) => tracing::info!("Battery mode activated."), Ok(x) => tracing::info!("Performance mode activated."),
Err(e) => tracing::error!("{e}"), Err(e) => tracing::error!("{e}"),
}, },
} }
@ -232,7 +232,7 @@ async fn get_power_profiles_proxy<'a>() -> Result<ppdaemon::PowerProfilesProxy<'
match ppdaemon::PowerProfilesProxy::new(&connection).await { match ppdaemon::PowerProfilesProxy::new(&connection).await {
Ok(d) => Ok(d), Ok(d) => Ok(d),
Err(e) => { Err(e) => {
tracing::error!("Power daemon proxy can't created. Is it installed? {e}"); tracing::error!("Power daemon proxy can't be created. Is it installed? {e}");
Err(()) Err(())
} }
} }

View file

@ -1,5 +1,5 @@
use backend::PowerProfile; use backend::PowerProfile;
use cosmic::iced::widget; use cosmic::widget;
use cosmic::{widget::settings, Apply}; use cosmic::{widget::settings, Apply};
use cosmic_settings_page::{self as page, section, Section}; use cosmic_settings_page::{self as page, section, Section};
use slotmap::SlotMap; use slotmap::SlotMap;
@ -49,7 +49,7 @@ impl Page {
fn profiles() -> Section<crate::pages::Message> { fn profiles() -> Section<crate::pages::Message> {
Section::default() Section::default()
.title(fl!("power-profiles")) .title(fl!("power-mode"))
.descriptions(vec![fl!("power", "desc").into()]) .descriptions(vec![fl!("power", "desc").into()])
.view::<Page>(|_binder, page, section| { .view::<Page>(|_binder, page, section| {
let mut section = settings::view_section(&section.title); let mut section = settings::view_section(&section.title);
@ -85,7 +85,7 @@ fn profiles() -> Section<crate::pages::Message> {
section = section.add(item); section = section.add(item);
} }
} else { } else {
let item = widget::Text::new(fl!("power-profiles", "nobackend")); let item = widget::text::body(fl!("power-mode", "nobackend"));
section = section.add(item); section = section.add(item);
} }

View file

@ -445,11 +445,11 @@ open-workspaces-view = Open Workspaces Overview
power = Power power = Power
.desc = Manage power settings .desc = Manage power settings
power-profiles = Power Profiles power-mode = Power Mode
.performance = Performance Mode .performance = High performance
.balanced = Balanced Mode .balanced = Balanced
.battery = Power Save Mode .battery = Extended battery life
.performance-desc = Maximum performance but high power consumption. .performance-desc = Peak performance and power usage.
.balanced-desc = Balanced performance and power consumption. .balanced-desc = Quiet performance and moderate power usage.
.battery-desc = Low performance but low power consumption. .battery-desc = Reduced power usage and silent performance.
.nobackend = Backend not found. Install system76-power or power-profiles-daemon. .nobackend = Backend not found. Install system76-power or power-profiles-daemon.