cleanup: remove methods that aren't used anymore
This commit is contained in:
parent
c819f94e74
commit
ea09abb892
4 changed files with 4 additions and 113 deletions
|
|
@ -18,13 +18,10 @@ theme-from-image = ["kmeans_colors", "image"]
|
||||||
# palette = {version = "0.7", features = ["serializing"] }
|
# palette = {version = "0.7", features = ["serializing"] }
|
||||||
almost = "0.2"
|
almost = "0.2"
|
||||||
palette = {git = "https://github.com/Ogeon/palette", features = ["serializing"] }
|
palette = {git = "https://github.com/Ogeon/palette", features = ["serializing"] }
|
||||||
anyhow = "1.0"
|
|
||||||
kmeans_colors = { version = "0.5", features = ["palette_color"], default-features = false, optional = true }
|
kmeans_colors = { version = "0.5", features = ["palette_color"], default-features = false, optional = true }
|
||||||
image = {version = "0.24.1", optional = true }
|
image = {version = "0.24.1", optional = true }
|
||||||
serde = { version = "1.0.129", features = ["derive"] }
|
serde = { version = "1.0.129", features = ["derive"] }
|
||||||
ron = "0.8"
|
ron = "0.8"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
csscolorparser = {version = "0.6.2", features = ["serde"]}
|
csscolorparser = {version = "0.6.2", features = ["serde"]}
|
||||||
directories = { git = "https://github.com/edfloreshz/directories-rs", version = "4.0.1" }
|
|
||||||
cosmic-config = { path = "../cosmic-config/", default-features = false, features = ["subscription"] }
|
cosmic-config = { path = "../cosmic-config/", default-features = false, features = ["subscription"] }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,5 @@ pub mod util;
|
||||||
|
|
||||||
/// name of cosmic theme
|
/// name of cosmic theme
|
||||||
pub const NAME: &'static str = "com.system76.CosmicTheme";
|
pub const NAME: &'static str = "com.system76.CosmicTheme";
|
||||||
/// Name of the theme directory
|
|
||||||
pub const THEME_DIR: &str = "themes";
|
|
||||||
/// name of the palette directory
|
|
||||||
pub const PALETTE_DIR: &str = "palettes";
|
|
||||||
|
|
||||||
pub use palette;
|
pub use palette;
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,10 @@
|
||||||
use std::{
|
use std::fmt;
|
||||||
fmt,
|
|
||||||
fs::File,
|
|
||||||
io::Write,
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::Context;
|
|
||||||
use directories::{BaseDirsExt, ProjectDirsExt};
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use palette::Srgba;
|
use palette::Srgba;
|
||||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{util::CssColor, NAME, PALETTE_DIR};
|
use crate::util::CssColor;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
/// built in light palette
|
/// built in light palette
|
||||||
|
|
@ -236,49 +229,6 @@ where
|
||||||
CosmicPalette::HighContrastDark(p) => &p.name,
|
CosmicPalette::HighContrastDark(p) => &p.name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// save the theme to the theme directory
|
|
||||||
pub fn save(&self) -> anyhow::Result<()> {
|
|
||||||
let ron_path: PathBuf = [NAME, PALETTE_DIR].iter().collect();
|
|
||||||
let ron_dirs = directories::ProjectDirs::from_path(ron_path)
|
|
||||||
.context("Failed to get project directories.")?;
|
|
||||||
let ron_name = format!("{}.ron", self.name());
|
|
||||||
|
|
||||||
if let Ok(p) = ron_dirs.place_config_file(ron_name) {
|
|
||||||
let mut f = File::create(p)?;
|
|
||||||
f.write_all(ron::ser::to_string_pretty(self, Default::default())?.as_bytes())?;
|
|
||||||
} else {
|
|
||||||
anyhow::bail!("Failed to write RON theme.");
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// init the theme directory
|
|
||||||
pub fn init() -> anyhow::Result<PathBuf> {
|
|
||||||
let ron_path: PathBuf = [NAME, PALETTE_DIR].iter().collect();
|
|
||||||
let base_dirs = directories::BaseDirs::new().context("Failed to get base directories.")?;
|
|
||||||
Ok(base_dirs.create_config_directory(ron_path)?)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// load a theme by name
|
|
||||||
pub fn load_from_name(name: &str) -> anyhow::Result<Self> {
|
|
||||||
let ron_path: PathBuf = [NAME, PALETTE_DIR].iter().collect();
|
|
||||||
let ron_dirs = directories::ProjectDirs::from_path(ron_path)
|
|
||||||
.context("Failed to get project directories.")?;
|
|
||||||
|
|
||||||
let ron_name = format!("{}.ron", name);
|
|
||||||
if let Some(p) = ron_dirs.find_config_file(ron_name) {
|
|
||||||
let f = File::open(p)?;
|
|
||||||
Ok(ron::de::from_reader(f)?)
|
|
||||||
} else {
|
|
||||||
anyhow::bail!("Failed to write RON theme.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// load a theme by path
|
|
||||||
pub fn load(p: &dyn AsRef<Path>) -> anyhow::Result<Self> {
|
|
||||||
let f = File::open(p)?;
|
|
||||||
Ok(ron::de::from_reader(f)?)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<CosmicPalette<Srgba>> for CosmicPalette<CssColor> {
|
impl Into<CosmicPalette<Srgba>> for CosmicPalette<CssColor> {
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,11 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
steps::*, Component, Container, CornerRadii, CosmicPalette, CosmicPaletteInner, Spacing,
|
steps::*, Component, Container, CornerRadii, CosmicPalette, CosmicPaletteInner, Spacing,
|
||||||
DARK_PALETTE, LIGHT_PALETTE, NAME, THEME_DIR,
|
DARK_PALETTE, LIGHT_PALETTE, NAME,
|
||||||
};
|
};
|
||||||
use anyhow::Context;
|
|
||||||
use cosmic_config::{Config, ConfigGet, ConfigSet, CosmicConfigEntry};
|
use cosmic_config::{Config, ConfigGet, ConfigSet, CosmicConfigEntry};
|
||||||
use directories::{BaseDirsExt, ProjectDirsExt};
|
|
||||||
use palette::{Srgb, Srgba};
|
use palette::{Srgb, Srgba};
|
||||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||||
use std::{
|
use std::{fmt, num::NonZeroUsize};
|
||||||
fmt,
|
|
||||||
fs::File,
|
|
||||||
io::Write,
|
|
||||||
num::NonZeroUsize,
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
||||||
/// Theme layer type
|
/// Theme layer type
|
||||||
|
|
@ -177,50 +169,6 @@ where
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// save the theme to the theme directory
|
|
||||||
pub fn save(&self) -> anyhow::Result<()> {
|
|
||||||
let ron_path: PathBuf = [NAME, THEME_DIR].iter().collect();
|
|
||||||
let ron_dirs = directories::ProjectDirs::from_path(ron_path)
|
|
||||||
.context("Failed to get project directories.")?;
|
|
||||||
let ron_name = format!("{}.ron", &self.name);
|
|
||||||
|
|
||||||
if let Ok(p) = ron_dirs.place_config_file(ron_name) {
|
|
||||||
let mut f = File::create(p)?;
|
|
||||||
f.write_all(ron::ser::to_string_pretty(self, Default::default())?.as_bytes())?;
|
|
||||||
} else {
|
|
||||||
anyhow::bail!("Failed to write RON theme.");
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// init the theme directory
|
|
||||||
pub fn init() -> anyhow::Result<PathBuf> {
|
|
||||||
let ron_path: PathBuf = [NAME, THEME_DIR].iter().collect();
|
|
||||||
let base_dirs = directories::BaseDirs::new().context("Failed to get base directories.")?;
|
|
||||||
Ok(base_dirs.create_config_directory(ron_path)?)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// load a theme by name
|
|
||||||
pub fn load_from_name(name: &str) -> anyhow::Result<Self> {
|
|
||||||
let ron_path: PathBuf = [NAME, THEME_DIR].iter().collect();
|
|
||||||
let ron_dirs = directories::ProjectDirs::from_path(ron_path)
|
|
||||||
.context("Failed to get project directories.")?;
|
|
||||||
|
|
||||||
let ron_name = format!("{}.ron", name);
|
|
||||||
if let Some(p) = ron_dirs.find_config_file(ron_name) {
|
|
||||||
let f = File::open(p)?;
|
|
||||||
Ok(ron::de::from_reader(f)?)
|
|
||||||
} else {
|
|
||||||
anyhow::bail!("Failed to write RON theme.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// load a theme by path
|
|
||||||
pub fn load(p: &dyn AsRef<Path>) -> anyhow::Result<Self> {
|
|
||||||
let f = File::open(p)?;
|
|
||||||
Ok(ron::de::from_reader(f)?)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO convenient getter functions for each named color variable
|
// TODO convenient getter functions for each named color variable
|
||||||
/// get @accent_color
|
/// get @accent_color
|
||||||
pub fn accent_color(&self) -> Srgba {
|
pub fn accent_color(&self) -> Srgba {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue