Updated the config handling, all in one TOML
Moorly CI / windows-build (push) Successful in 3m5s
Moorly CI / linux-build (push) Successful in 3m35s

This commit is contained in:
Squid committed 2026-11-06 22:14:33 +01:00
1 parent 188e4f64d4
commit 2e1248d7df
2 files changed
+1715 -74

No files matched your search

+1673 -50
View File
File diff suppressed because it is too large. Load diff
+42 -24
View File
@@ -5,7 +5,6 @@
//! changes while the app is running). //! changes while the app is running).
use std::env; use std::env;
use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
use iced::border::Radius; use iced::border::Radius;
@@ -72,28 +71,6 @@ impl std::fmt::Display for Preference {
} }
} }
/// Loads the persisted preference, falling back to `System`.
pub fn load() -> Preference {
config_path()
.and_then(|path| fs::read_to_string(path).ok())
.and_then(|value| Preference::parse(value.trim()))
.unwrap_or_default()
}
/// Persists the preference. Failures are ignored so theme selection never
/// blocks the UI; the in-memory choice still applies for this session.
pub fn save(preference: Preference) {
let Some(path) = config_path() else {
return;
};
if let Some(parent) = path.parent() {
let _ = fs::create_dir_all(parent);
}
let _ = fs::write(path, preference.as_str());
}
pub(crate) fn config_path() -> Option<PathBuf> { pub(crate) fn config_path() -> Option<PathBuf> {
let base = if cfg!(windows) { let base = if cfg!(windows) {
env::var_os("APPDATA").map(PathBuf::from) env::var_os("APPDATA").map(PathBuf::from)
@@ -103,7 +80,7 @@ pub(crate) fn config_path() -> Option<PathBuf> {
.or_else(|| env::var_os("HOME").map(|home| PathBuf::from(home).join(".config"))) .or_else(|| env::var_os("HOME").map(|home| PathBuf::from(home).join(".config")))
}?; }?;
Some(base.join("moorly").join("theme")) Some(base.join("moorly").join("config.toml"))
} }
/// Style for the top menubar. /// Style for the top menubar.
@@ -194,6 +171,22 @@ pub fn settings_active(_theme: &Theme, _status: button::Status, accent: Color) -
} }
} }
/// Style for the currently selected option in a group of choice buttons.
pub fn selected_option(theme: &Theme, _status: button::Status) -> button::Style {
let palette = theme.extended_palette();
button::Style {
background: Some(palette.primary.base.color.into()),
text_color: palette.primary.base.text,
border: Border {
color: palette.primary.base.color,
width: 1.0,
radius: 4.0.into(),
},
..button::Style::default()
}
}
/// Style for an unselected choice button: outlined so it reads as a button /// Style for an unselected choice button: outlined so it reads as a button
/// rather than a plain text label. /// rather than a plain text label.
pub fn outlined_option(theme: &Theme, status: button::Status) -> button::Style { pub fn outlined_option(theme: &Theme, status: button::Status) -> button::Style {
@@ -218,6 +211,15 @@ pub fn positive_option(theme: &Theme, status: button::Status) -> button::Style {
}) })
} }
/// Style for a destructive/cancelling action button (red).
pub fn danger_option(theme: &Theme, status: button::Status) -> button::Style {
let danger = theme.extended_palette().danger;
filled_option(match status {
button::Status::Hovered | button::Status::Pressed => danger.strong,
_ => danger.base,
})
}
fn filled_option(pair: iced::theme::palette::Pair) -> button::Style { fn filled_option(pair: iced::theme::palette::Pair) -> button::Style {
button::Style { button::Style {
background: Some(pair.color.into()), background: Some(pair.color.into()),
@@ -231,6 +233,22 @@ fn filled_option(pair: iced::theme::palette::Pair) -> button::Style {
} }
} }
/// Style for the password eye button while the password is revealed.
pub fn revealed_eye(theme: &Theme, status: button::Status) -> button::Style {
let palette = theme.extended_palette();
button::Style {
background: None,
text_color: palette.background.base.text,
border: Border {
color: palette.primary.base.color,
width: 1.0,
radius: 4.0.into(),
},
..button::text(theme, status)
}
}
/// Style for a selectable list row; the selected one gets a tinted background. /// Style for a selectable list row; the selected one gets a tinted background.
pub fn selectable_row(theme: &Theme, status: button::Status, selected: bool) -> button::Style { pub fn selectable_row(theme: &Theme, status: button::Status, selected: bool) -> button::Style {
if selected { if selected {