generated from cosmic-utils/cosmic-app-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ahoneybun/add-theme+settings
Add theme+settings
- Loading branch information
Showing
6 changed files
with
200 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use crate::app::App; | ||
use cosmic::{ | ||
cosmic_config::{self, cosmic_config_derive::CosmicConfigEntry, Config, CosmicConfigEntry}, | ||
theme, Application, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
pub const CONFIG_VERSION: u64 = 1; | ||
|
||
#[derive(Clone, Default, Debug, Eq, PartialEq, Deserialize, Serialize, CosmicConfigEntry)] | ||
pub struct CosmicBackupsConfig { | ||
pub app_theme: AppTheme, | ||
} | ||
|
||
impl CosmicBackupsConfig { | ||
pub fn config_handler() -> Option<Config> { | ||
Config::new(App::APP_ID, CONFIG_VERSION).ok() | ||
} | ||
|
||
pub fn config() -> CosmicBackupsConfig { | ||
match Self::config_handler() { | ||
Some(config_handler) => { | ||
let config = CosmicBackupsConfig::get_entry(&config_handler).unwrap_or_else( | ||
|(errs, config)| { | ||
log::info!("errors loading config: {:?}", errs); | ||
config | ||
}, | ||
); | ||
config | ||
} | ||
None => CosmicBackupsConfig::default(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] | ||
pub enum AppTheme { | ||
Dark, | ||
Light, | ||
#[default] | ||
System, | ||
} | ||
|
||
impl AppTheme { | ||
pub fn theme(&self) -> theme::Theme { | ||
match self { | ||
Self::Dark => theme::Theme::dark(), | ||
Self::Light => theme::Theme::light(), | ||
Self::System => theme::system_preference(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.