65 lines
1.6 KiB
Rust
65 lines
1.6 KiB
Rust
use anyhow::{Context, Result};
|
|
use serde::{Deserialize, Serialize};
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Config {
|
|
#[serde(rename = "screenshot")]
|
|
pub effects: EffectsConfig,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct EffectsConfig {
|
|
pub rounded_corners: bool,
|
|
pub corner_radius: f32,
|
|
pub drop_shadow: bool,
|
|
pub shadow_blur_radius: f32,
|
|
pub shadow_offset_x: f32,
|
|
pub shadow_offset_y: f32,
|
|
pub shadow_color: [u8; 4],
|
|
}
|
|
|
|
impl Default for EffectsConfig {
|
|
fn default() -> Self {
|
|
Self {
|
|
rounded_corners: false,
|
|
corner_radius: 12.0,
|
|
drop_shadow: false,
|
|
shadow_blur_radius: 20.0,
|
|
shadow_offset_x: 5.0,
|
|
shadow_offset_y: 8.0,
|
|
shadow_color: [0, 0, 0, 160],
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for Config {
|
|
fn default() -> Self {
|
|
Self {
|
|
effects: EffectsConfig::default(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Config {
|
|
pub fn config_path() -> Option<PathBuf> {
|
|
let home = std::env::var("HOME").ok()?;
|
|
Some(
|
|
PathBuf::from(home)
|
|
.join(".config")
|
|
.join("zshell")
|
|
.join("config.json"),
|
|
)
|
|
}
|
|
|
|
pub fn load() -> Result<Self> {
|
|
let path = Self::config_path().context("Could not determine HOME directory")?;
|
|
|
|
let raw = std::fs::read_to_string(&path)
|
|
.with_context(|| format!("Failed to read config at {}", path.display()))?;
|
|
|
|
serde_json::from_str(&raw)
|
|
.with_context(|| format!("Failed to parse JSON config at {}", path.display()))
|
|
}
|
|
}
|