diff --git a/i18n/en/cosmic_ext_applet_external_monitor_brightness.ftl b/i18n/en/cosmic_ext_applet_external_monitor_brightness.ftl index f0677d9..a966a93 100644 --- a/i18n/en/cosmic_ext_applet_external_monitor_brightness.ftl +++ b/i18n/en/cosmic_ext_applet_external_monitor_brightness.ftl @@ -1,3 +1,4 @@ dark_mode = Dark Mode gamma_map = Gamma Map -refresh = Refresh \ No newline at end of file +refresh = Refresh +no_monitor = No external monitors found diff --git a/src/app.rs b/src/app.rs index 808126b..be05edd 100644 --- a/src/app.rs +++ b/src/app.rs @@ -4,10 +4,8 @@ use std::time::{SystemTime, UNIX_EPOCH}; use crate::config::{self, Config, MonitorConfig}; use crate::monitor; use crate::monitor::{DisplayId, EventToSub, MonitorInfo, ScreenBrightness}; -use anyhow::anyhow; use cosmic::app::{Core, Task}; use cosmic::cosmic_config::Config as CosmicConfig; -use cosmic::cosmic_config::CosmicConfigEntry; use cosmic::cosmic_theme::{THEME_MODE_ID, ThemeMode}; use cosmic::iced::window::Id; use cosmic::iced::{Limits, Subscription}; @@ -168,7 +166,6 @@ pub enum AppMsg { ConfigChanged(Config), ThemeModeConfigChanged(ThemeMode), - SetDarkMode(bool), SetScreenBrightness(DisplayId, f32), ToggleMinMaxBrightness(DisplayId), @@ -298,34 +295,6 @@ impl cosmic::Application for AppState { AppMsg::ThemeModeConfigChanged(config) => { self.theme_mode_config = config; } - AppMsg::SetDarkMode(dark) => { - #[allow(dead_code)] - fn set_theme_mode(mode: &ThemeMode) -> anyhow::Result<()> { - let home_dir = dirs::home_dir().ok_or(anyhow!("no home dir"))?; - - let helper = cosmic::cosmic_config::Config::with_custom_path( - THEME_MODE_ID, - ThemeMode::VERSION, - home_dir.join(".config"), - )?; - - mode.write_entry(&helper)?; - - Ok(()) - } - - fn set_theme_mode2(mode: &ThemeMode) -> anyhow::Result<()> { - let helper = ThemeMode::config()?; - mode.write_entry(&helper)?; - Ok(()) - } - - self.theme_mode_config.is_dark = dark; - - if let Err(e) = set_theme_mode2(&self.theme_mode_config) { - error!("can't write theme mode {e}"); - } - } AppMsg::SubscriptionReady((monitors, sender)) => { self.monitors = monitors .into_iter() diff --git a/src/view.rs b/src/view.rs index bba4da8..4a7cab4 100644 --- a/src/view.rs +++ b/src/view.rs @@ -4,11 +4,10 @@ use crate::app::{AppMsg, AppState, MonitorState}; use crate::fl; use crate::icon::{icon_high, icon_low, icon_medium, icon_off}; use cosmic::Element; -use cosmic::applet::padded_control; use cosmic::iced::{Alignment, Length}; use cosmic::widget::{ - button, column, container, divider, horizontal_space, icon, mouse_area, row, slider, text, - toggler, tooltip, + button, column, container, horizontal_space, icon, mouse_area, row, slider, text, toggler, + tooltip, }; impl AppState { @@ -59,18 +58,13 @@ impl AppState { } pub fn popup_view(&self) -> Element { - column() - .padding(10) - .push_maybe(self.monitors_view()) - .push_maybe( - (!self.monitors.is_empty()).then(|| padded_control(divider::horizontal::default())), - ) - .push(self.dark_mode_view()) - .into() + column().padding(10).push(self.monitors_view()).into() } - fn monitors_view(&self) -> Option> { - (!self.monitors.is_empty()).then(|| { + fn monitors_view(&self) -> Element { + if self.monitors.is_empty() { + column().push(text(fl!("no_monitor"))).into() + } else { column() .padding(8) .extend( @@ -79,7 +73,7 @@ impl AppState { .map(|(id, monitor)| self.monitor_view(id, monitor)), ) .into() - }) + } } fn monitor_view<'a>(&self, id: &'a str, monitor: &'a MonitorState) -> Element<'a, AppMsg> { @@ -244,20 +238,6 @@ impl AppState { // })) // .into() // } - - fn dark_mode_view(&self) -> Element { - padded_control( - mouse_area( - row() - .align_y(Alignment::Center) - .push(text(fl!("dark_mode"))) - .push(horizontal_space()) - .push(toggler(self.theme_mode_config.is_dark).on_toggle(AppMsg::SetDarkMode)), - ) - .on_press(AppMsg::SetDarkMode(!self.theme_mode_config.is_dark)), - ) - .into() - } } fn brightness_icon(brightness: f32) -> icon::Handle {