Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #11

Merged
merged 17 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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"
67 changes: 42 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ log = "0.4"
# knuffel = "3.2.0"
indexmap = "2"
bon = "2"
pretty_assertions = "1"
2 changes: 1 addition & 1 deletion SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions configurator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ features = [
[dev-dependencies]
configurator_schema = { workspace = true }
serial_test = "3"
pretty_assertions.workspace = true
2 changes: 1 addition & 1 deletion configurator/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion configurator/src/manual_testing/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{fs, path::Path};

use configurator_utils::ConfigFormat;
use figment::{providers, Figment, Profile};
use schemars::JsonSchema;
use serde::Serialize;
Expand All @@ -8,10 +9,11 @@ mod testing1;
mod testing2;

fn get_schema<C: JsonSchema>(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::<C>()
.source_home_path(&config_path)
.format(ConfigFormat::CosmicRon)
.call()
.unwrap()
}
Expand Down
79 changes: 76 additions & 3 deletions configurator/src/manual_testing/testing1.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -16,7 +20,7 @@ enum ConfigEnum {
#[serde(default)]
#[derive(Default)]
struct Config {
opt: Option<ConfigEnum>,
x: ConfigEnum,
}

#[derive(Clone, Debug, JsonSchema, Serialize, Deserialize, Default)]
Expand Down Expand Up @@ -56,3 +60,72 @@ fn print_ron() {
fn print_schema() {
super::print_schema::<Config>(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<D>(deserializer: D) -> Result<Self, D::Error>
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<A>(self, map: A) -> Result<Self::Value, A::Error>
where
A: de::MapAccess<'de>,
{
todo!()
}
}

deserializer.deserialize_struct("Config", &["x"], VisitorStruct {})
}
}
Loading