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)]
pub enum PowerProfile {
Performance,
Balanced,
Battery,
Balanced,
Performance,
}
impl PowerProfile {
fn from_string(s: &str) -> PowerProfile {
match s {
"Performance" | "performance" => Self::Performance,
"Battery" | "power-saver" => Self::Battery,
"Performance" | "performance" => Self::Performance,
_ => Self::Balanced,
}
}
pub fn title(&self) -> String {
match self {
Self::Performance => fl!("power-profiles", "performance"),
Self::Balanced => fl!("power-profiles", "balanced"),
Self::Battery => fl!("power-profiles", "battery"),
Self::Battery => fl!("power-mode", "battery"),
Self::Balanced => fl!("power-mode", "balanced"),
Self::Performance => fl!("power-mode", "performance"),
}
}
pub fn description(&self) -> String {
match self {
Self::Performance => fl!("power-profiles", "performance-desc"),
Self::Balanced => fl!("power-profiles", "balanced-desc"),
Self::Battery => fl!("power-profiles", "battery-desc"),
Self::Battery => fl!("power-mode", "battery-desc"),
Self::Balanced => fl!("power-mode", "balanced-desc"),
Self::Performance => fl!("power-mode", "performance-desc"),
}
}
}
pub fn get_power_profiles() -> Vec<PowerProfile> {
vec![
PowerProfile::Performance,
PowerProfile::Balanced,
PowerProfile::Battery,
PowerProfile::Balanced,
PowerProfile::Performance,
]
}
@ -108,16 +108,16 @@ impl SetPowerProfile for S76Backend {
};
match profile {
PowerProfile::Performance => match daemon.performance().await {
Ok(x) => tracing::info!("Performance mode activated."),
PowerProfile::Battery => match daemon.battery().await {
Ok(x) => tracing::info!("Battery mode activated."),
Err(e) => tracing::error!("{e}"),
},
PowerProfile::Balanced => match daemon.balanced().await {
Ok(x) => tracing::info!("Balanced mode activated."),
Err(e) => tracing::error!("{e}"),
},
PowerProfile::Battery => match daemon.battery().await {
Ok(x) => tracing::info!("Battery mode activated."),
PowerProfile::Performance => match daemon.performance().await {
Ok(x) => tracing::info!("Performance mode activated."),
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 {
Ok(d) => Ok(d),
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(())
}
}
@ -180,16 +180,16 @@ impl SetPowerProfile for PPBackend {
};
match profile {
PowerProfile::Performance => match daemon.set_active_profile("performance").await {
Ok(x) => tracing::info!("Performance mode activated."),
PowerProfile::Battery => match daemon.set_active_profile("power-saver").await {
Ok(x) => tracing::info!("Battery mode activated."),
Err(e) => tracing::error!("{e}"),
},
PowerProfile::Balanced => match daemon.set_active_profile("balanced").await {
Ok(x) => tracing::info!("Balanced mode activated."),
Err(e) => tracing::error!("{e}"),
},
PowerProfile::Battery => match daemon.set_active_profile("power-saver").await {
Ok(x) => tracing::info!("Battery mode activated."),
PowerProfile::Performance => match daemon.set_active_profile("performance").await {
Ok(x) => tracing::info!("Performance mode activated."),
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 {
Ok(d) => Ok(d),
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(())
}
}

View file

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

View file

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