Skip to content

Commit

Permalink
Enhance: set dark mode in config (#206)
Browse files Browse the repository at this point in the history
* Set Dark mode in config

* enhance: use snake_case for Antialias and Theme in configuration

* refactor: move theme Configuration to inner ConfigWindowSection

* docs: write down the config changes in the CHANGELOG

* style: remove redundant serde renames on Antialias

* docs: delete entry for inner changes invisible to the user in CHANGELOG
  • Loading branch information
carrascomj authored Sep 16, 2021
1 parent 8b3950f commit ffe4336
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Unreleased

### Added
- Added configuration keyword to switch between dark and light mode.

### Changed
- Fix for not being able to delete images on some systems.

Expand Down
8 changes: 4 additions & 4 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};

use serde::{Deserialize, Serialize};

#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Serialize, Deserialize, Copy, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum Theme {
Light,
Dark,
Expand All @@ -30,12 +31,10 @@ impl Theme {
}

#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Antialias {
#[serde(rename = "auto")]
Auto,
#[serde(rename = "always")]
Always,
#[serde(rename = "never")]
Never,
}
impl Default for Antialias {
Expand Down Expand Up @@ -74,6 +73,7 @@ pub struct ConfigWindowSection {
pub start_fullscreen: Option<bool>,
pub start_maximized: Option<bool>,
pub show_bottom_bar: Option<bool>,
pub theme: Option<Theme>,
pub use_last_window_area: Option<bool>,
pub win_w: Option<u32>,
pub win_h: Option<u32>,
Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,13 @@ fn main() {

let update_available = Arc::new(AtomicBool::new(false));
let update_check_done = Arc::new(AtomicBool::new(false));
let theme = Rc::new(Cell::new(cache.lock().unwrap().theme()));

let theme = {
Rc::new(Cell::new(match &config.borrow().window {
Some(ConfigWindowSection { theme: Some(theme_cfg), .. }) => *theme_cfg,
_ => cache.lock().unwrap().theme(),
}))
};

let set_theme = {
let update_label = update_label;
Expand Down

0 comments on commit ffe4336

Please sign in to comment.