amrbashir 9 ماه پیش
والد
کامیت
eb82252786

+ 1 - 0
Cargo.lock

@@ -9363,6 +9363,7 @@ dependencies = [
  "kuchikiki",
  "log",
  "memchr",
+ "once_cell",
  "phf 0.11.2",
  "proc-macro2",
  "quote",

+ 4 - 4
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"
         }
       ]

+ 1 - 1
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();

+ 4 - 4
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"
         }
       ]

+ 2 - 1
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"]

+ 10 - 4
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<regex::Regex> = 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),
 }