From 56f819d2effd6a3ca23557565efb490eac2a29c0 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Mon, 13 Jul 2020 18:18:06 -0300 Subject: [PATCH] feat(tauri) allow plugin config on tauri.conf.json (#824) --- cli/tauri.js/src/types/config.schema.json | 12 ++++++++++++ cli/tauri.js/src/types/config.ts | 5 +++++ cli/tauri.js/src/types/config.validator.ts | 12 ++++++++++++ tauri-api/src/config.rs | 14 ++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/cli/tauri.js/src/types/config.schema.json b/cli/tauri.js/src/types/config.schema.json index 1e10dc788..e4d452fad 100644 --- a/cli/tauri.js/src/types/config.schema.json +++ b/cli/tauri.js/src/types/config.schema.json @@ -259,6 +259,18 @@ }, "type": "object" }, + "plugins": { + "additionalProperties": { + "additionalProperties": { + }, + "defaultProperties": [ + ], + "type": "object" + }, + "defaultProperties": [ + ], + "type": "object" + }, "tauri": { "additionalProperties": false, "defaultProperties": [ diff --git a/cli/tauri.js/src/types/config.ts b/cli/tauri.js/src/types/config.ts index 98ac01062..68ae3ac5d 100644 --- a/cli/tauri.js/src/types/config.ts +++ b/cli/tauri.js/src/types/config.ts @@ -292,6 +292,11 @@ export interface TauriConfig { active?: boolean } } + plugins?: { + [name: string]: { + [key: string]: any + } + } } export default TauriConfig diff --git a/cli/tauri.js/src/types/config.validator.ts b/cli/tauri.js/src/types/config.validator.ts index 3b8b781bc..bd2e443df 100644 --- a/cli/tauri.js/src/types/config.validator.ts +++ b/cli/tauri.js/src/types/config.validator.ts @@ -269,6 +269,18 @@ export const TauriConfigSchema = { }, "type": "object" }, + "plugins": { + "additionalProperties": { + "additionalProperties": { + }, + "defaultProperties": [ + ], + "type": "object" + }, + "defaultProperties": [ + ], + "type": "object" + }, "tauri": { "additionalProperties": false, "defaultProperties": [ diff --git a/tauri-api/src/config.rs b/tauri-api/src/config.rs index fb2bf38d8..b9e548b1d 100644 --- a/tauri-api/src/config.rs +++ b/tauri-api/src/config.rs @@ -1,5 +1,6 @@ use serde::de::{Deserializer, Error as DeError, Visitor}; use serde::Deserialize; +use serde_json::Value as JsonValue; use once_cell::sync::OnceCell; use std::collections::HashMap; @@ -306,6 +307,8 @@ fn default_dev_path() -> String { "".to_string() } +type JsonObject = HashMap; + /// The tauri.conf.json mapper. #[derive(PartialEq, Deserialize, Debug)] #[serde(rename_all = "camelCase")] @@ -316,6 +319,16 @@ pub struct Config { /// The build configuration. #[serde(default = "default_build")] pub build: BuildConfig, + /// The plugins config. + #[serde(default)] + plugins: HashMap, +} + +impl Config { + /// Gets a plugin configuration. + pub fn plugin_config>(&self, plugin_name: S) -> Option<&JsonObject> { + self.plugins.get(plugin_name.as_ref()) + } } fn default_tauri() -> TauriConfig { @@ -431,6 +444,7 @@ mod test { build: BuildConfig { dev_path: String::from("../dist"), }, + plugins: Default::default(), } }