use serde::Deserialize;
#[derive(Debug, Default, Deserialize)]
pub struct RawConfig {
#[serde(default)]
pub app: RawApp,
#[serde(default)]
pub input: RawInput,
#[serde(default)]
pub output: OutputConfig,
#[serde(default)]
pub platforms: PlatformConfig,
#[serde(default)]
pub linux: LinuxConfig,
#[serde(default)]
pub effects: EffectsConfig,
#[serde(default)]
pub packaging: PackagingConfig,
}
#[derive(Debug, Default, Deserialize)]
pub struct RawApp {
pub id: Option<String>,
pub name: Option<String>,
pub generic_name: Option<String>,
pub comment: Option<String>,
pub exec: Option<String>,
#[serde(default)]
pub categories: Vec<String>,
#[serde(default)]
pub keywords: Vec<String>,
pub startup_wm_class: Option<String>,
#[serde(default)]
pub mime_types: Vec<String>,
pub license: Option<String>,
pub metadata_license: Option<String>,
pub description: Option<String>,
pub homepage_url: Option<String>,
pub developer_name: Option<String>,
}
#[derive(Debug, Default, Deserialize)]
pub struct RawInput {
pub svg: Option<String>,
pub symbolic_svg: Option<String>,
}
impl RawConfig {
pub fn load(path: &str) -> anyhow::Result<Self> {
let content = std::fs::read_to_string(path).map_err(|e| {
if e.kind() == std::io::ErrorKind::NotFound {
anyhow::anyhow!(
"config file not found: '{}'\n \
Run iconsmaker from your project directory, \
or pass --config path/to/icons.toml",
path
)
} else {
anyhow::anyhow!("cannot read '{}': {}", path, e)
}
})?;
toml::from_str(&content)
.map_err(|e| anyhow::anyhow!("cannot parse '{}': {}", path, e))
}
}
#[derive(Debug)]
pub struct Config {
pub app: AppConfig,
pub input: InputConfig,
pub output: OutputConfig,
pub platforms: PlatformConfig,
pub linux: LinuxConfig,
pub effects: EffectsConfig,
pub packaging: PackagingConfig,
}
#[derive(Debug)]
pub struct AppConfig {
pub id: String,
pub name: String,
pub generic_name: Option<String>,
pub comment: Option<String>,
pub exec: String,
pub categories: Vec<String>,
pub keywords: Vec<String>,
pub startup_wm_class: Option<String>,
pub mime_types: Vec<String>,
pub license: Option<String>,
pub metadata_license: Option<String>,
pub description: Option<String>,
pub homepage_url: Option<String>,
pub developer_name: Option<String>,
}
#[derive(Debug)]
pub struct InputConfig {
pub svg: String,
pub symbolic_svg: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct OutputConfig {
#[serde(default = "default_dist")]
pub dir: String,
}
#[derive(Debug, Deserialize)]
pub struct PlatformConfig {
#[serde(default = "default_true")]
pub macos: bool,
#[serde(default = "default_true")]
pub windows: bool,
#[serde(default = "default_true")]
pub linux: bool,
}
#[derive(Debug, Deserialize)]
pub struct LinuxConfig {
#[serde(default = "default_hicolor_sizes")]
pub hicolor_sizes: Vec<u32>,
}
#[derive(Debug, Deserialize)]
pub struct EffectsConfig {
#[serde(default = "default_squircle_power")]
pub squircle_power: f32,
#[serde(default)]
pub squircle_depth: bool,
#[serde(default = "default_gloss_strength")]
pub gloss_strength: f32,
#[serde(default = "default_depth_blur")]
pub depth_blur: f32,
}
impl Default for EffectsConfig {
fn default() -> Self {
Self {
squircle_power: default_squircle_power(),
squircle_depth: false,
gloss_strength: default_gloss_strength(),
depth_blur: default_depth_blur(),
}
}
}
#[derive(Debug, Default, Deserialize)]
pub struct PackagingConfig {
#[serde(default)]
pub snap: bool,
#[serde(default)]
pub flatpak: bool,
#[serde(default)]
pub appimage: bool,
#[serde(default)]
pub deb: bool,
}
impl Default for OutputConfig {
fn default() -> Self {
Self { dir: default_dist() }
}
}
impl Default for PlatformConfig {
fn default() -> Self {
Self { macos: true, windows: true, linux: true }
}
}
impl Default for LinuxConfig {
fn default() -> Self {
Self { hicolor_sizes: default_hicolor_sizes() }
}
}
fn default_true() -> bool { true }
fn default_dist() -> String { "dist".to_string() }
fn default_hicolor_sizes() -> Vec<u32> { vec![16, 22, 24, 32, 48, 64, 128, 256, 512] }
fn default_squircle_power() -> f32 { 5.0 }
fn default_gloss_strength() -> f32 { 0.35 }
fn default_depth_blur() -> f32 { 0.12 }