diff --git a/Cargo.lock b/Cargo.lock index f8aa441c61f5..dd32ccd47bd7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9363,6 +9363,7 @@ dependencies = [ "kuchikiki", "log", "memchr", + "once_cell", "phf 0.11.2", "proc-macro2", "quote", diff --git a/crates/tauri-cli/config.schema.json b/crates/tauri-cli/config.schema.json index 0de52f8c641a..ecf58a1b7a42 100644 --- a/crates/tauri-cli/config.schema.json +++ b/crates/tauri-cli/config.schema.json @@ -843,7 +843,7 @@ "InnerColor": { "anyOf": [ { - "description": "A tuple of RGB colors. Each value has minimum of 0 and maximum of 255.", + "description": "Array of RGB colors. Each value has minimum of 0 and maximum of 255.", "type": "array", "items": [ { @@ -866,7 +866,7 @@ "minItems": 3 }, { - "description": "A tuple of RGBA colors. Each value has minimum of 0 and maximum of 255.", + "description": "Array of RGBA colors. Each value has minimum of 0 and maximum of 255.", "type": "array", "items": [ { @@ -894,7 +894,7 @@ "minItems": 4 }, { - "description": "An object of red, green, blue, alpha color values. Each value has minimum of 0 and maximum of 255.", + "description": "Object of red, green, blue, alpha color values. Each value has minimum of 0 and maximum of 255.", "type": "object", "required": [ "blue", @@ -926,7 +926,7 @@ } }, { - "description": "A color hex string, for example: #fff, #ffffff, or #ffffffff.", + "description": "Color hex string, for example: #fff, #ffffff, or #ffffffff.", "type": "string" } ] diff --git a/crates/tauri-runtime-wry/src/window/windows.rs b/crates/tauri-runtime-wry/src/window/windows.rs index a0d921991cb4..6c032beabda8 100644 --- a/crates/tauri-runtime-wry/src/window/windows.rs +++ b/crates/tauri-runtime-wry/src/window/windows.rs @@ -59,7 +59,7 @@ impl super::WindowExt for tao::window::Window { surface.resize(width, height).unwrap(); let mut buffer = surface.buffer_mut().unwrap(); let color = background_color - .map(|(r, g, b, _)| ((b as u32) << 0) | ((g as u32) << 8) | ((r as u32) << 16)) + .map(|(r, g, b, _)| (b as u32) | ((g as u32) << 8) | ((r as u32) << 16)) .unwrap_or(0); buffer.fill(color); let _ = buffer.present(); diff --git a/crates/tauri-schema-generator/schemas/config.schema.json b/crates/tauri-schema-generator/schemas/config.schema.json index 0de52f8c641a..ecf58a1b7a42 100644 --- a/crates/tauri-schema-generator/schemas/config.schema.json +++ b/crates/tauri-schema-generator/schemas/config.schema.json @@ -843,7 +843,7 @@ "InnerColor": { "anyOf": [ { - "description": "A tuple of RGB colors. Each value has minimum of 0 and maximum of 255.", + "description": "Array of RGB colors. Each value has minimum of 0 and maximum of 255.", "type": "array", "items": [ { @@ -866,7 +866,7 @@ "minItems": 3 }, { - "description": "A tuple of RGBA colors. Each value has minimum of 0 and maximum of 255.", + "description": "Array of RGBA colors. Each value has minimum of 0 and maximum of 255.", "type": "array", "items": [ { @@ -894,7 +894,7 @@ "minItems": 4 }, { - "description": "An object of red, green, blue, alpha color values. Each value has minimum of 0 and maximum of 255.", + "description": "Object of red, green, blue, alpha color values. Each value has minimum of 0 and maximum of 255.", "type": "object", "required": [ "blue", @@ -926,7 +926,7 @@ } }, { - "description": "A color hex string, for example: #fff, #ffffff, or #ffffffff.", + "description": "Color hex string, for example: #fff, #ffffff, or #ffffffff.", "type": "string" } ] diff --git a/crates/tauri-utils/Cargo.toml b/crates/tauri-utils/Cargo.toml index cd36d6ce217c..31354a9fe643 100644 --- a/crates/tauri-utils/Cargo.toml +++ b/crates/tauri-utils/Cargo.toml @@ -46,6 +46,7 @@ log = "0.4.21" cargo_metadata = { version = "0.18", optional = true } serde-untagged = "0.1" uuid = { version = "1", features = ["serde"] } +once_cell = { version = "1", optional = true } [target."cfg(target_os = \"macos\")".dependencies] swift-rs = { version = "1.0.7", optional = true, features = ["build"] } @@ -57,7 +58,7 @@ serial_test = "3.1" [features] build = ["proc-macro2", "quote", "cargo_metadata", "schema", "swift-rs"] compression = ["brotli"] -schema = ["schemars"] +schema = ["schemars", "once_cell"] isolation = ["aes-gcm", "getrandom", "serialize-to-javascript"] process-relaunch-dangerous-allow-symlink-macos = [] config-json5 = ["json5"] diff --git a/crates/tauri-utils/src/config.rs b/crates/tauri-utils/src/config.rs index 6d916a06b63d..f96650575ccc 100644 --- a/crates/tauri-utils/src/config.rs +++ b/crates/tauri-utils/src/config.rs @@ -1323,15 +1323,20 @@ fn default_alpha() -> u8 { 255 } +#[cfg(feature = "schema")] +static HEX_COLOR_RE: once_cell::sync::Lazy = once_cell::sync::Lazy::new(|| { + regex::Regex::new(r"^#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$").unwrap() +}); + #[derive(Deserialize)] #[cfg_attr(feature = "schema", derive(JsonSchema))] #[serde(untagged)] enum InnerColor { - /// A tuple of RGB colors. Each value has minimum of 0 and maximum of 255. + /// Array of RGB colors. Each value has minimum of 0 and maximum of 255. Rgb((u8, u8, u8)), - /// A tuple of RGBA colors. Each value has minimum of 0 and maximum of 255. + /// Array of RGBA colors. Each value has minimum of 0 and maximum of 255. Rgba((u8, u8, u8, u8)), - /// An object of red, green, blue, alpha color values. Each value has minimum of 0 and maximum of 255. + /// Object of red, green, blue, alpha color values. Each value has minimum of 0 and maximum of 255. RgbaObject { red: u8, green: u8, @@ -1339,7 +1344,8 @@ enum InnerColor { #[serde(default = "default_alpha")] alpha: u8, }, - /// A color hex string, for example: #fff, #ffffff, or #ffffffff. + /// Color hex string, for example: #fff, #ffffff, or #ffffffff. + #[cfg_attr(feature = "schema", validate(regex(path = *HEX_COLOR_RE)))] String(String), }