mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-02 14:38:21 -06:00
Merge pull request #826 from luniiya/feat/theme-favorites
UI: favorite themes and appearance shortcuts
This commit is contained in:
@@ -172,6 +172,8 @@ page!(Appearance {
|
||||
dark_theme: String = "dark".into(),
|
||||
/// The theme used in light appearance: `light`.
|
||||
light_theme: String = "light".into(),
|
||||
/// Theme shortcuts in the appearance context menu.
|
||||
favorite_themes: Vec<String> = Vec::new(),
|
||||
/// User interface brightness, -1 (darker) … 1 (lighter).
|
||||
brightness: f64 = 0.0,
|
||||
/// The size of the whole interface in percent (75–200), on top of the display's own scale.
|
||||
@@ -564,6 +566,8 @@ impl Prefs {
|
||||
a.interval_minutes = a.interval_minutes.clamp(1, 240);
|
||||
a.max_versions = a.max_versions.clamp(1, 99);
|
||||
let ap = &mut self.appearance;
|
||||
let mut seen = std::collections::BTreeSet::new();
|
||||
ap.favorite_themes.retain(|id| is_choice(THEMES, id) && seen.insert(id.clone()));
|
||||
if !is_choice(APPEARANCE_MODES, &ap.appearance_mode) {
|
||||
ap.appearance_mode = Appearance::default().appearance_mode;
|
||||
}
|
||||
@@ -620,6 +624,23 @@ impl Prefs {
|
||||
let all: Vec<&str> = c.iter().map(|(_, v)| *v).collect();
|
||||
return Err(format!("`{key}` expects one of {}", all.join(", ")));
|
||||
}
|
||||
let favorites = if key == "appearance.favoriteThemes" {
|
||||
Some(&value)
|
||||
} else if key == "appearance" {
|
||||
value.get("favoriteThemes")
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(favorites) = favorites {
|
||||
let values = favorites.as_array().ok_or("favorite themes must be a list")?;
|
||||
let mut seen = std::collections::BTreeSet::new();
|
||||
for value in values {
|
||||
let id = value.as_str().ok_or("favorite theme must be a string")?;
|
||||
if !is_choice(THEMES, id) || !seen.insert(id) {
|
||||
return Err("unknown or duplicate favorite theme".into());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Older clients set the single theme (by key, or inside the page object): it still picks
|
||||
// a visible theme, fixing the mode to its family.
|
||||
let legacy_theme = key == "appearance.theme" || (key == "appearance" && value.get("theme").is_some() && value.get("appearanceMode").is_none());
|
||||
|
||||
Reference in New Issue
Block a user