diff --git a/.cargo/config.toml b/.cargo/config.toml index 4b86087..e94eeaa 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,4 +1,6 @@ [env] -# RUST_LOG = "warn,fan_control=info,ui=info,data=info,hardware=info" +# RUST_LOG = "none,[from_str{appid=com.system76.CosmicPanel.Panel}]=debug" +RUST_LOG = "none,[from_str{appid=testing1}]=debug" +# RUST_LOG = "warn,configurator=debug" RUST_BACKTRACE = "0" diff --git a/Cargo.lock b/Cargo.lock index 65e6740..33a2758 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -159,9 +159,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74f37166d7d48a0284b99dd824694c26119c700b53bf0d1540cdb147dbdaaf13" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" [[package]] name = "apply" @@ -418,9 +418,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.34" +version = "1.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b9470d453346108f93a59222a9a1a5724db32d0a4727b7ab7ace4b4d822dc9" +checksum = "baee610e9452a8f6f0a1b6194ec09ff9e2d85dea54432acdae41aa0761c95d70" dependencies = [ "jobserver", "libc", @@ -617,6 +617,7 @@ dependencies = [ "indexmap 2.6.0", "libcosmic", "light_enum", + "pretty_assertions", "ron", "rust-embed", "schemars", @@ -725,7 +726,7 @@ dependencies = [ [[package]] name = "cosmic-config" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#36b3cfa13aeac6e5cdf7e76ef826ed7d66aaebfe" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "atomicwrites", "cosmic-config-derive", @@ -743,7 +744,7 @@ dependencies = [ [[package]] name = "cosmic-config-derive" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#36b3cfa13aeac6e5cdf7e76ef826ed7d66aaebfe" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "quote", "syn 1.0.109", @@ -775,7 +776,7 @@ dependencies = [ [[package]] name = "cosmic-theme" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#36b3cfa13aeac6e5cdf7e76ef826ed7d66aaebfe" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "almost", "cosmic-config", @@ -984,6 +985,12 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "digest" version = "0.10.7" @@ -1327,9 +1334,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "font-types" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dda6e36206148f69fc6ecb1bb6c0dedd7ee469f3db1d0dc2045beea28430ca43" +checksum = "b3971f9a5ca983419cdc386941ba3b9e1feba01a0ab888adf78739feb2798492" dependencies = [ "bytemuck", ] @@ -1843,7 +1850,7 @@ dependencies = [ [[package]] name = "iced" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#36b3cfa13aeac6e5cdf7e76ef826ed7d66aaebfe" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "dnd", "iced_accessibility", @@ -1861,7 +1868,7 @@ dependencies = [ [[package]] name = "iced_accessibility" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#36b3cfa13aeac6e5cdf7e76ef826ed7d66aaebfe" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "accesskit", "accesskit_winit", @@ -1870,7 +1877,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#36b3cfa13aeac6e5cdf7e76ef826ed7d66aaebfe" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "bitflags 2.6.0", "bytes", @@ -1893,7 +1900,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#36b3cfa13aeac6e5cdf7e76ef826ed7d66aaebfe" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "futures", "iced_core", @@ -1918,7 +1925,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#36b3cfa13aeac6e5cdf7e76ef826ed7d66aaebfe" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "bitflags 2.6.0", "bytemuck", @@ -1940,7 +1947,7 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#36b3cfa13aeac6e5cdf7e76ef826ed7d66aaebfe" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -1952,7 +1959,7 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#36b3cfa13aeac6e5cdf7e76ef826ed7d66aaebfe" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "bytes", "dnd", @@ -1966,7 +1973,7 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#36b3cfa13aeac6e5cdf7e76ef826ed7d66aaebfe" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "bytemuck", "cosmic-text", @@ -1982,7 +1989,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#36b3cfa13aeac6e5cdf7e76ef826ed7d66aaebfe" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "as-raw-xcb-connection", "bitflags 2.6.0", @@ -2013,7 +2020,7 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#36b3cfa13aeac6e5cdf7e76ef826ed7d66aaebfe" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "dnd", "iced_renderer", @@ -2030,7 +2037,7 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#36b3cfa13aeac6e5cdf7e76ef826ed7d66aaebfe" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "dnd", "iced_futures", @@ -2473,7 +2480,7 @@ checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#36b3cfa13aeac6e5cdf7e76ef826ed7d66aaebfe" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "apply", "chrono", @@ -3447,6 +3454,16 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" +[[package]] +name = "pretty_assertions" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" +dependencies = [ + "diff", + "yansi", +] + [[package]] name = "proc-macro-crate" version = "3.2.0" @@ -3785,9 +3802,9 @@ checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustix" -version = "0.38.38" +version = "0.38.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa260229e6538e52293eeb577aabd09945a09d6d9cc0fc550ed7529056c2e32a" +checksum = "375116bee2be9ed569afe2154ea6a99dfdffd257f533f187498c2a8f5feaf4ee" dependencies = [ "bitflags 2.6.0", "errno", @@ -5528,9 +5545,9 @@ dependencies = [ [[package]] name = "xml-rs" -version = "0.8.22" +version = "0.8.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af4e2e2f7cba5a093896c1e150fbfe177d1883e7448200efb81d40b9d339ef26" +checksum = "af310deaae937e48a26602b730250b4949e125f468f11e6990be3e5304ddd96f" [[package]] name = "xmlwriter" diff --git a/Cargo.toml b/Cargo.toml index 6b92cc7..f546a0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,3 +44,4 @@ log = "0.4" # knuffel = "3.2.0" indexmap = "2" bon = "2" +pretty_assertions = "1" diff --git a/SPEC.md b/SPEC.md index 933d6b1..b390327 100644 --- a/SPEC.md +++ b/SPEC.md @@ -5,7 +5,7 @@ The schema must be stored in one of this locations - `$XDG_DATA_HOME/configurator/` - `$XDG_DATA_DIRS/configurator/` -The filename should be the [Application ID](https://docs.flathub.org/docs/for-app-authors/requirements/#application-id) of the application, plus the `.json` extension. E.g: `io.github.cosmic-utils.configurator.json`. +The filename should be the [Application ID](https://docs.flathub.org/docs/for-app-authors/requirements/#application-id) of the application, plus the `.json` extension. E.g: `io.github.cosmic_utils.configurator.json`. ## Additional metadata diff --git a/configurator/Cargo.toml b/configurator/Cargo.toml index b94205b..00d36c1 100644 --- a/configurator/Cargo.toml +++ b/configurator/Cargo.toml @@ -58,3 +58,4 @@ features = [ [dev-dependencies] configurator_schema = { workspace = true } serial_test = "3" +pretty_assertions.workspace = true diff --git a/configurator/src/app.rs b/configurator/src/app.rs index 6ba6079..4c07260 100644 --- a/configurator/src/app.rs +++ b/configurator/src/app.rs @@ -20,7 +20,7 @@ use crate::{ }; pub const QUALIFIER: &str = "io.github"; -pub const ORG: &str = "cosmic-utils"; +pub const ORG: &str = "cosmic_utils"; pub const APP: &str = "configurator"; pub const APPID: &str = constcat::concat!(QUALIFIER, ".", ORG, ".", APP); diff --git a/configurator/src/manual_testing/mod.rs b/configurator/src/manual_testing/mod.rs index c4dac1b..a53945c 100644 --- a/configurator/src/manual_testing/mod.rs +++ b/configurator/src/manual_testing/mod.rs @@ -1,5 +1,6 @@ use std::{fs, path::Path}; +use configurator_utils::ConfigFormat; use figment::{providers, Figment, Profile}; use schemars::JsonSchema; use serde::Serialize; @@ -8,10 +9,11 @@ mod testing1; mod testing2; fn get_schema(name: &str) -> String { - let config_path = format!("{}/test_configs/{}.json", env!("CARGO_MANIFEST_DIR"), name); + let config_path = format!("{}/test_configs/{}", env!("CARGO_MANIFEST_DIR"), name); configurator_schema::gen_schema::() .source_home_path(&config_path) + .format(ConfigFormat::CosmicRon) .call() .unwrap() } diff --git a/configurator/src/manual_testing/testing1.rs b/configurator/src/manual_testing/testing1.rs index b6de4e6..924f83f 100644 --- a/configurator/src/manual_testing/testing1.rs +++ b/configurator/src/manual_testing/testing1.rs @@ -1,9 +1,13 @@ #![allow(clippy::type_complexity)] +#![allow(unreachable_code)] -use std::collections::HashMap; +use std::{collections::HashMap, fmt::Debug}; +use figment::value::Value; use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; +use serde::{de, Deserialize, Serialize}; + +use crate::node::NodeContainer; #[derive(Clone, Debug, JsonSchema, Serialize, Deserialize, Default)] enum ConfigEnum { @@ -16,7 +20,7 @@ enum ConfigEnum { #[serde(default)] #[derive(Default)] struct Config { - opt: Option, + x: ConfigEnum, } #[derive(Clone, Debug, JsonSchema, Serialize, Deserialize, Default)] @@ -56,3 +60,72 @@ fn print_ron() { fn print_schema() { super::print_schema::(NAME); } + +#[test] +#[ignore] +fn t() { + let ron = "(x:A)"; + + let c: Config = ron::from_str(ron).unwrap(); + dbg!(&c); + + let v: ValueDeserializer = ron::from_str(ron).unwrap(); + + dbg!(&v); + + panic!() +} + +struct ValueDeserializer { + value: figment::value::Value, +} + +impl Debug for ValueDeserializer { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("ValueDeserializer") + .field("value", &self.value) + .finish() + } +} + +impl<'de> Deserialize<'de> for ValueDeserializer { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + // let node: NodeContainer = todo!(); + + enum Field { + X, + } + + struct FieldVisitor; + + impl de::Visitor<'_> for FieldVisitor { + type Value = Field; + + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + todo!() + } + } + + struct VisitorStruct {} + + impl<'de> de::Visitor<'de> for VisitorStruct { + type Value = ValueDeserializer; + + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + todo!() + } + + fn visit_map(self, map: A) -> Result + where + A: de::MapAccess<'de>, + { + todo!() + } + } + + deserializer.deserialize_struct("Config", &["x"], VisitorStruct {}) + } +} diff --git a/configurator/src/node/apply_figment.rs b/configurator/src/node/apply_figment.rs index 583b5ab..74c18c6 100644 --- a/configurator/src/node/apply_figment.rs +++ b/configurator/src/node/apply_figment.rs @@ -23,8 +23,7 @@ impl NodeContainer { // todo: the modified logic in the function seems wrong (i probably fixed it) // todo2: analyze the entire logic pub fn apply_value(&mut self, value: Value, modified: bool) -> anyhow::Result<()> { - // info!("merge_figment_rec"); - // dbg!(&self, &value); + // debug!("merge_figment_rec {:?} {:?}", &self, &value); self.modified = modified; match (value, &mut self.node) { @@ -40,7 +39,7 @@ impl NodeContainer { }) .ok_or_else(|| { anyhow!( - "can't find a compatible enum variant for dict {values:#?}. {node_enum:#?}" + "can't find a compatible enum variant for dict \n{values:#?}.\n{node_enum:#?}" ) })?; @@ -54,7 +53,7 @@ impl NodeContainer { .position(|e| e.is_matching(&value)) .ok_or_else(|| { anyhow!( - "can't find a compatible enum variant for {value:#?}. {node_enum:#?}" + "can't find a compatible enum variant for \n{value:#?}.\n{node_enum:#?}" ) })?; @@ -108,7 +107,7 @@ impl NodeContainer { node_array.values = Some(nodes); } (Value::Empty(tag, value), Node::Null) => {} - (value, node) => bail!("no compatible node for value = {value:#?}. {node:#?}"), + (value, node) => bail!("no compatible node for value = \n{value:#?}. \n{node:#?}"), }; Ok(()) diff --git a/configurator/src/node/from_json_schema.rs b/configurator/src/node/from_json_schema.rs index 585691e..46741a1 100644 --- a/configurator/src/node/from_json_schema.rs +++ b/configurator/src/node/from_json_schema.rs @@ -14,24 +14,18 @@ use super::*; impl NodeContainer { pub fn from_json_schema(schema: &RootSchema) -> Self { - // dbg!(&schema); - - // dbg!(&schema.definitions); - - // dbg!(&tree); - schema_object_to_node("root", &schema.definitions, &schema.schema).unwrap() } } /// None means that the schema validate nothing +#[instrument(skip_all)] pub(crate) fn schema_object_to_node( from: &str, def: &schemars::Map, schema_object: &SchemaObject, ) -> Option { - // info!("enter function from {from}"); - // dbg!(&schema_object); + // debug!("enter function from {from}.\n{:#?}", schema_object); let mut res = NodeContainer::from_node(Node::Any); @@ -105,9 +99,6 @@ pub(crate) fn schema_object_to_node( } if let Some(enum_values) = &schema_object.enum_values { - // dbg!(schema_object); - // dbg!(&enum_values); - let node = if enum_values.len() == 1 { NodeContainer::from_node(Node::Value(NodeValue::new(enum_values[0].clone()))) } else { @@ -135,7 +126,6 @@ pub(crate) fn schema_object_to_node( } // items are of type array. SingleOrVec::Vec(vec) => { - // dbg!(&schema_object); let template: Option> = vec .iter() .map(|schema| { @@ -181,8 +171,6 @@ pub(crate) fn schema_object_to_node( for schema in one_of { let node = schema_object_to_node("one_of", def, &schema.to_object())?; - // dbg!(&node); - nodes.push(node); } @@ -195,8 +183,6 @@ pub(crate) fn schema_object_to_node( for schema in any_of { let node = schema_object_to_node("one_of", def, &schema.to_object())?; - // dbg!(&node); - nodes.push(node); } @@ -206,9 +192,6 @@ pub(crate) fn schema_object_to_node( } if let Some(definition) = &schema_object.reference { - // dbg!(&schema_object); - // dbg!(&root_schema.definitions); - if let Some(definition) = definition.strip_prefix("#/definitions/") { let schema = def.get(definition).unwrap(); diff --git a/configurator/src/node/mod.rs b/configurator/src/node/mod.rs index d78fa52..ff3f823 100644 --- a/configurator/src/node/mod.rs +++ b/configurator/src/node/mod.rs @@ -14,6 +14,7 @@ pub mod data_path; pub mod from_json_schema; mod number; pub use number::{NumberValue, NumberValueLight}; +mod ser; #[cfg(test)] mod tests; mod to_figment_value; diff --git a/configurator/src/node/ser.rs b/configurator/src/node/ser.rs new file mode 100644 index 0000000..c239f1f --- /dev/null +++ b/configurator/src/node/ser.rs @@ -0,0 +1,74 @@ +use std::{ + collections::HashSet, + sync::{LazyLock, Mutex}, +}; + +use serde::{ + ser::{SerializeMap, SerializeStruct, SerializeTuple}, + Serialize, +}; + +use super::NodeContainer; + +impl Serialize for NodeContainer { + fn serialize(&self, ser: S) -> Result + where + S: serde::Serializer, + { + match &self.node { + super::Node::Null => todo!(), + super::Node::Bool(node_bool) => ser.serialize_bool(node_bool.value.unwrap()), + super::Node::String(node_string) => todo!(), + super::Node::Number(node_number) => todo!(), + super::Node::Object(node_object) => { + let mut map = ser.serialize_struct("", node_object.nodes.len())?; + + for (key, val) in &node_object.nodes { + let key: &'static str = Box::leak(key.to_string().into_boxed_str()); + + map.serialize_field(key, val)?; + } + + map.end() + } + super::Node::Enum(node_enum) => todo!(), + super::Node::Array(node_array) => todo!(), + super::Node::Value(node_value) => todo!(), + super::Node::Any => todo!(), + } + } +} + +#[cfg(test)] +mod test { + + use crate::test_common::*; + + use super::NodeContainer; + use figment::{providers, value::Tag, Figment, Profile}; + use schemars::{schema_for, JsonSchema}; + use serde::{Deserialize, Serialize}; + + fn test_schema() { + let schema = schema_for!(S); + + let mut tree = NodeContainer::from_json_schema(&schema); + + let config1 = S::default(); + + let figment = Figment::new().join(providers::Serialized::from(&config1, Profile::Default)); + + tree.apply_figment(&figment).unwrap(); + + let str1 = ron::ser::to_string_pretty(&config1, ron::ser::PrettyConfig::new()).unwrap(); + + let str2 = ron::ser::to_string_pretty(&tree, ron::ser::PrettyConfig::new()).unwrap(); + + assert_eq!(str1, str2); + } + + #[test] + fn test_bool_ron() { + test_schema::(); + } +} diff --git a/configurator/src/page.rs b/configurator/src/page.rs index 2a3b58b..f8d8cb5 100644 --- a/configurator/src/page.rs +++ b/configurator/src/page.rs @@ -70,7 +70,7 @@ pub fn create_pages(config: &Config) -> impl Iterator + use<'_> { let appid = appid_from_schema_path(file.path()); if !config.masked.contains(&appid) { - Some(Page::from_str(appid, content).unwrap()) + Some(Page::from_str(&appid, content).unwrap()) } else { None } @@ -106,7 +106,7 @@ pub fn create_pages(config: &Config) -> impl Iterator + use<'_> { if !config.masked.contains(&appid) { match fs::read_to_string(&schema_path) { - Ok(content) => match Page::from_str(appid, &content) { + Ok(content) => match Page::from_str(&appid, &content) { Ok(page) => Some(page), Err(e) => { error!("{}", e); @@ -133,7 +133,9 @@ fn appid_from_schema_path(schema_path: &Path) -> String { } impl Page { - fn from_str(appid: String, content: &str) -> anyhow::Result { + // need &str for appid: https://github.com/tokio-rs/tracing/issues/1181 + #[instrument(skip(content))] + fn from_str(appid: &str, content: &str) -> anyhow::Result { let json_value = json::Value::from_str(content)?; let Some(json_obj) = json_value.as_object() else { @@ -187,14 +189,14 @@ impl Page { system_config = system_config.merge(crate::providers::read_from_format(path, &format)) } - info!("start generating node from schema {}", appid); + info!("start generating node from schema"); let tree = NodeContainer::from_json_schema(&json::from_value(json_value)?); let title = appid.split('.').last().unwrap().to_string(); let mut page = Self { title, - appid, + appid: appid.to_string(), system_config, user_config: Figment::new(), full_config: Figment::new(), @@ -206,11 +208,8 @@ impl Page { format, }; - // dbg!(&page.tree); - if let Err(err) = page.reload() { error!("{err}"); - // panic!() } Ok(page) @@ -220,18 +219,25 @@ impl Page { self.title.clone() } + #[instrument(skip_all)] pub fn reload(&mut self) -> anyhow::Result<()> { + info!("reload the config"); + self.user_config = Figment::new().merge(crate::providers::read_from_format( &self.source_home_path, &self.format, )); + debug!("user_config = {:#?}", self.user_config); + + debug!("system_config = {:#?}", self.system_config); + self.full_config = Figment::new() .merge(self.system_config.clone()) .merge(self.user_config.clone()); - // dbg!(&self.tree); - // dbg!(&self.full_config); + // debug!("tree = {:#?}", self.tree); + debug!("full_config = {:#?}", self.full_config); self.tree.remove_value_rec(); diff --git a/configurator/src/providers/cosmic_ron.rs b/configurator/src/providers/cosmic_ron.rs index 332a99f..a2a8fd3 100644 --- a/configurator/src/providers/cosmic_ron.rs +++ b/configurator/src/providers/cosmic_ron.rs @@ -75,11 +75,17 @@ impl CosmicRonProvider { let content = fs::read_to_string(dir_entry.path())?; + debug!("{}", content); + let value: ron::Value = ron::from_str(&content)?; + debug!("{:?}", value); + ron_map.insert(ron::Value::String(filename.to_string()), value); } + debug!("{:?}", ron_map); + let data = Figment::new() .merge(figment::providers::Serialized::from( ron_map, diff --git a/configurator/src/providers/mod.rs b/configurator/src/providers/mod.rs index d8a2b22..5066973 100644 --- a/configurator/src/providers/mod.rs +++ b/configurator/src/providers/mod.rs @@ -31,7 +31,10 @@ impl Provider for BoxedProvider { } } +#[instrument(skip_all)] pub fn read_from_format>(path: P, format: &ConfigFormat) -> BoxedProvider { + debug!("{:?}:{}", path.as_ref(), format); + match format { ConfigFormat::Json => BoxedProvider(Box::new(providers::Json::file(path))), ConfigFormat::CosmicRon => BoxedProvider(Box::new( diff --git a/configurator/src/providers/tests.rs b/configurator/src/providers/tests.rs index 1dc617f..0ae37f0 100644 --- a/configurator/src/providers/tests.rs +++ b/configurator/src/providers/tests.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, marker::PhantomData, path::Path, sync::LazyLock}; +use std::{collections::HashMap, fs, marker::PhantomData, path::Path, sync::LazyLock}; use configurator_utils::ConfigFormat; use figment::{ @@ -10,9 +10,13 @@ use serial_test::serial; use crate::test_common::*; +use pretty_assertions::assert_eq; + /// 1. write the value /// 2. read the value and assert equal fn write_and_read>(path: P, format: &ConfigFormat, initial_value: &Value) { + let _ = fs::remove_dir_all(path.as_ref()); + super::write(path.as_ref(), format, initial_value).unwrap(); let value = super::read_from_format(path.as_ref(), format); diff --git a/configurator/src/test_common.rs b/configurator/src/test_common.rs index f81e509..ed45a6e 100644 --- a/configurator/src/test_common.rs +++ b/configurator/src/test_common.rs @@ -76,7 +76,7 @@ impl Default for TestVeryComplex { }, }); - v.1.insert("lol".into(), Rec::default()); + v.1.insert("lol".into(), EnumComplex::default()); Self { x, @@ -165,5 +165,5 @@ pub struct TestHashMap { pub struct TestVeryComplex { x: HashMap, y: EnumComplex, - v: (Vec, HashMap), + v: (Vec, HashMap), } diff --git a/configurator/src/view.rs b/configurator/src/view.rs index 8795fb2..ee8ffa1 100644 --- a/configurator/src/view.rs +++ b/configurator/src/view.rs @@ -5,7 +5,7 @@ use cosmic::{ iced_widget::{pick_list, toggler}, prelude::CollectionWidget, widget::{ - button, column, container, horizontal_space, mouse_area, row, + button, column, container, horizontal_space, mouse_area, row, scrollable, segmented_button::Entity, settings::section, text, text_input, @@ -91,7 +91,7 @@ fn view_page(entity: Entity, page: &Page) -> Element<'_, PageMsg> { column() .push(view_data_path(&page.data_path)) - .push(content) + .push(scrollable(content)) .spacing(10) .into() } diff --git a/cosmic_compat/schemas/com.system76.CosmicPanel.Dock.json b/cosmic_compat/schemas/com.system76.CosmicPanel.Dock.json index ba80323..94155ff 100644 --- a/cosmic_compat/schemas/com.system76.CosmicPanel.Dock.json +++ b/cosmic_compat/schemas/com.system76.CosmicPanel.Dock.json @@ -3,7 +3,7 @@ "X_CONFIGURATOR_FORMAT": "cosmic_ron", "X_CONFIGURATOR_SOURCE_HOME_PATH": ".config/cosmic/com.system76.CosmicPanel.Dock/v1", "X_CONFIGURATOR_SOURCE_PATHS": "/usr/share/cosmic/com.system76.CosmicPanel.Dock/v1", - "X_CONFIGURATOR_WRITE_PATH": "/home/fedasus/SSD/Documents/configurator/configurator/test_configs/com.system76.CosmicPanel.Dock", + "X_CONFIGURATOR_WRITE_PATH": "/home/fedasus/Documents/configurator/configurator/test_configs/com.system76.CosmicPanel.Dock", "additionalProperties": false, "definitions": { "AutoHide": { @@ -393,6 +393,50 @@ "default": "M", "description": "configured size for the panel" }, + "size_center": { + "anyOf": [ + { + "$ref": "#/definitions/PanelSize" + }, + { + "type": "null" + } + ], + "default": null, + "description": "optional size override for center" + }, + "size_wings": { + "default": null, + "description": "optional size override for wings", + "items": [ + { + "anyOf": [ + { + "$ref": "#/definitions/PanelSize" + }, + { + "type": "null" + } + ] + }, + { + "anyOf": [ + { + "$ref": "#/definitions/PanelSize" + }, + { + "type": "null" + } + ] + } + ], + "maxItems": 2, + "minItems": 2, + "type": [ + "array", + "null" + ] + }, "spacing": { "default": 4, "description": "space between panel plugins", diff --git a/cosmic_compat/schemas/com.system76.CosmicPanel.Panel.json b/cosmic_compat/schemas/com.system76.CosmicPanel.Panel.json index a48d955..e2a48db 100644 --- a/cosmic_compat/schemas/com.system76.CosmicPanel.Panel.json +++ b/cosmic_compat/schemas/com.system76.CosmicPanel.Panel.json @@ -3,7 +3,7 @@ "X_CONFIGURATOR_FORMAT": "cosmic_ron", "X_CONFIGURATOR_SOURCE_HOME_PATH": ".config/cosmic/com.system76.CosmicPanel.Panel/v1", "X_CONFIGURATOR_SOURCE_PATHS": "/usr/share/cosmic/com.system76.CosmicPanel.Panel/v1", - "X_CONFIGURATOR_WRITE_PATH": "/home/fedasus/SSD/Documents/configurator/configurator/test_configs/com.system76.CosmicPanel.Panel", + "X_CONFIGURATOR_WRITE_PATH": "/home/fedasus/Documents/configurator/configurator/test_configs/com.system76.CosmicPanel.Panel", "additionalProperties": false, "definitions": { "AutoHide": { @@ -393,6 +393,50 @@ "default": "M", "description": "configured size for the panel" }, + "size_center": { + "anyOf": [ + { + "$ref": "#/definitions/PanelSize" + }, + { + "type": "null" + } + ], + "default": null, + "description": "optional size override for center" + }, + "size_wings": { + "default": null, + "description": "optional size override for wings", + "items": [ + { + "anyOf": [ + { + "$ref": "#/definitions/PanelSize" + }, + { + "type": "null" + } + ] + }, + { + "anyOf": [ + { + "$ref": "#/definitions/PanelSize" + }, + { + "type": "null" + } + ] + } + ], + "maxItems": 2, + "minItems": 2, + "type": [ + "array", + "null" + ] + }, "spacing": { "default": 4, "description": "space between panel plugins", diff --git a/dev/TODO.md b/dev/TODO.md index 57cd0c6..981b49a 100644 --- a/dev/TODO.md +++ b/dev/TODO.md @@ -1,6 +1,13 @@ -for libcosmic - - fix slider - push multiple on Row and Column - add_maybe for Setting Section - on_press_with for button +- nest #[instrument] tracing + +- retrieve the actual config on the system with figment::Value +- implementer Serialize on Node +- ron::Value can't be serialized from str + - https://github.com/ron-rs/ron/issues/189 + - https://github.com/ron-rs/ron/issues/122 +- créer un nouveau type struct ValueDeserializer(NodeContainer) +et implementer Deserializer dessu. \ No newline at end of file diff --git a/io.github.cosmic-utils.configurator.json b/io.github.cosmic-utils.configurator.json deleted file mode 100644 index b6b3f45..0000000 --- a/io.github.cosmic-utils.configurator.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "app-id": "io.github.cosmic-utils.configurator", - "runtime": "org.freedesktop.Platform", - "runtime-version": "24.08", - "sdk": "org.freedesktop.Sdk", - "sdk-extensions": ["org.freedesktop.Sdk.Extension.rust-stable"], - "command": "configurator", - "finish-args": ["--share=ipc", "--socket=fallback-x11", "--socket=wayland"], - "modules": [ - { - "name": "configurator", - "buildsystem": "simple", - "build-options": { - "env": { - "CARGO_HOME": "/run/build/configurator/cargo" - }, - "append-path": "/usr/lib/sdk/rust-stable/bin" - }, - "build-commands": [ - "just build-release --offline --verbose", - "just prefix=/app install" - ], - "sources": [ - { - "type": "dir", - "path": "./" - }, - "./cargo-sources.json" - ] - } - ] -} diff --git a/io.github.cosmic_utils.configurator.json b/io.github.cosmic_utils.configurator.json new file mode 100644 index 0000000..137a751 --- /dev/null +++ b/io.github.cosmic_utils.configurator.json @@ -0,0 +1,39 @@ +{ + "app-id": "io.github.cosmic_utils.configurator", + "runtime": "org.freedesktop.Platform", + "runtime-version": "24.08", + "sdk": "org.freedesktop.Sdk", + "sdk-extensions": ["org.freedesktop.Sdk.Extension.rust-nightly"], + "base": "com.system76.Cosmic.BaseApp", + "base-version": "stable", + "command": "configurator", + "finish-args": [ + "--share=ipc", + "--socket=fallback-x11", + "--socket=wayland", + "--filesystem=host-os", + "--filesystem=/var/lib/flatpak:ro", + "--filesystem=~/.local/share/configurator:ro", + "--filesystem=~/.var/app:ro" + ], + "modules": [ + { + "name": "configurator", + "buildsystem": "simple", + "build-options": { + "append-path": "/usr/lib/sdk/rust-nightly/extra/sdk/rust-nightly/bin" + }, + "build-commands": [ + "just build-release --offline --verbose", + "just prefix=/app install" + ], + "sources": [ + { + "type": "dir", + "path": "./" + }, + "./cargo-sources.json" + ] + } + ] +} diff --git a/justfile b/justfile index 82dcc61..90bba77 100644 --- a/justfile +++ b/justfile @@ -4,7 +4,7 @@ debug := '0' name := 'configurator' -appid := 'io.github.cosmic-utils.' + name +appid := 'io.github.cosmic_utils.' + name cargo-target-dir := env('CARGO_TARGET_DIR', 'target') bin-src := cargo-target-dir / if debug == '1' { 'debug' / name } else { 'release' / name } @@ -89,16 +89,8 @@ setupf: sources_gen: python3 flatpak-builder-tools/cargo/flatpak-cargo-generator.py ./Cargo.lock -o cargo-sources.json -install_sdk: - flatpak remote-add --if-not-exists --user flathub https://flathub.org/repo/flathub.flatpakrepo - flatpak install --noninteractive --user flathub \ - org.freedesktop.Platform//24.08 \ - org.freedesktop.Sdk//24.08 \ - org.freedesktop.Sdk.Extension.rust-stable//24.08 \ - org.freedesktop.Sdk.Extension.llvm17//24.08 - uninstallf: - flatpak uninstall io.github.cosmic-utils.configurator -y || true + flatpak uninstall io.github.cosmic_utils.configurator -y || true # deps: flatpak-builder git-lfs build_and_install: uninstallf @@ -110,7 +102,7 @@ build_and_install: uninstallf --install-deps-from=flathub \ --repo=repo \ flatpak-out \ - io.github.cosmic-utils.configurator.json + io.github.cosmic_utils.configurator.json runf: - flatpak run io.github.cosmic-utils.configurator + flatpak run io.github.cosmic_utils.configurator diff --git a/res/desktop_entry.desktop b/res/desktop_entry.desktop index efbe5e3..4298cf0 100644 --- a/res/desktop_entry.desktop +++ b/res/desktop_entry.desktop @@ -7,6 +7,6 @@ Keywords=dconf Type=Application Categories=System;Utility; Exec=configurator -Icon=io.github.cosmic-utils.configurator -StartupWMClass=io.github.cosmic-utils.configurator +Icon=io.github.cosmic_utils.configurator +StartupWMClass=io.github.cosmic_utils.configurator Terminal=false diff --git a/res/metainfo.xml b/res/metainfo.xml index 48b4ea3..ed8df53 100644 --- a/res/metainfo.xml +++ b/res/metainfo.xml @@ -3,7 +3,7 @@ - io.github.cosmic-utils.configurator + io.github.cosmic_utils.configurator Configurator Configure your apps with an UI @@ -29,7 +29,7 @@

- io.github.cosmic-utils.configurator.desktop + io.github.cosmic_utils.configurator.desktop configurator screenshot