DioxusLabs / dioxus

Fullstack GUI library for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
19.46k stars 750 forks source link

Document configuration values #1474

Open tigerros opened 10 months ago

tigerros commented 10 months ago

Specific Demand

There's some values in the Dioxus.toml which aren't documented on the website or even the source code itself. I looked in the 0.3.0 book as well, and they don't seem to be there either. It seems strange to me that these would be undocumented, but I guess that's the case.

Additionally, it would be great if there was a way to generate an example Dioxus.toml that would contain all possible values. This would allow us to replace the dioxuslabs.com configuring page with a link to the docs.rs, thus reducing the amount of documentation we need to maintain.

Implement Suggestion

Initially, I wanted to document them myself, but realized it's difficult seeing as I didn't write it, and I only have experience with the web configuration (which is documented). However, I've got some suggestions.

The config structs are in cli/src/config.rs. The documentation for some of them is on the dioxuslabs.com configuring page, so that can be copied. Other documentation needs to be added though.

As for generating the example, we could use something like this:

// [dependencies]
// serde = { version = "1.0.0", features = ["derive"] }
// toml = "0.8.0"

use serde::{Serialize, Deserialize};

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct BundleConfig {
    // other fields...
    pub identifier: Option<String>,
    // Why is "icon" a vector? Shouldn't it be "icons"?
    pub icon: Option<Vec<String>>,
    pub resources: Option<Vec<String>>,
    // other fields...
}

// Maybe in a post-build cargo-make?
fn main() {
    // I don't really know what these fields refer to, so these example values might be wrong
    let example_bundle = BundleConfig {
        identifier: Some("GitHub".to_string()),
        icon: Some(vec!["assets/favicon.ico".to_string()]),
        resources: Some(vec!["assets/*".to_string(), "octocat_images/*".to_string()]),
    };

    match toml::to_string_pretty(&example_bundle) {
        Ok(toml_str) => println!("{toml_str}"),
        Err(_) => println!("Failed to generate example"), // Or panic
    }
}

Output:

identifier = "GitHub"        
icon = ["assets/favicon.ico"]
resources = [
    "assets/*",
    "octocat_images/*",
]
ealmloff commented 10 months ago

Bundler settings are copied from tauri-bundle (more docs here). (The only reason we don't use tauri's structs directly is because tauri's structs don't implement serialize and deserialize which we need to convert them to and from toml)

tigerros commented 10 months ago

Bundler settings are copied from tauri-bundle (more docs here)

That explains it. I suppose linking the tauri docs would be sufficient then. Also, does the TUI use the tauri bundler, or only desktop and mobile? For the docsite.

ealmloff commented 10 months ago

Bundler settings are copied from tauri-bundle (more docs here)

That explains it. I suppose linking the tauri docs would be sufficient then. Also, does the TUI use the tauri bundler, or only desktop and mobile? For the docsite.

I think it should work for TUI, but I haven't tested it. Mobile cannot use dx bundle yet