Browse Source

fix: center and focus not being allowed in config (#2199)

FabianLars 4 years ago
parent
commit
bc2c331dec

+ 7 - 0
.changes/fix-window-config-center-focus.md

@@ -0,0 +1,7 @@
+
+---
+ "cli.rs": patch
+ "tauri-runtime-wry": patch
+---
+
+Fixes `center` and `focus` not being allowed in `tauri.conf.json > tauri > windows` and ignored in `WindowBuilderWrapper`.

+ 4 - 0
core/tauri-runtime-wry/src/lib.rs

@@ -442,6 +442,10 @@ impl WindowBuilder for WindowBuilderWrapper {
       window = window.position(x, y);
     }
 
+    if config.center {
+      window = window.center();
+    }
+
     if config.focus {
       window = window.focus();
     }

+ 10 - 0
tooling/cli.rs/config_definition.rs

@@ -268,6 +268,9 @@ pub struct WindowConfig {
   /// Disabling it is required to use drag and drop on the frontend on Windows.
   #[serde(default = "default_file_drop_enabled")]
   pub file_drop_enabled: bool,
+  /// Whether or not the window starts centered or not.
+  #[serde(default)]
+  pub center: bool,
   /// The horizontal position of the window's top left corner
   pub x: Option<f64>,
   /// The vertical position of the window's top left corner
@@ -292,6 +295,9 @@ pub struct WindowConfig {
   /// Whether the window starts as fullscreen or not.
   #[serde(default)]
   pub fullscreen: bool,
+  /// Whether the window will be initially hidden or focused.
+  #[serde(default = "default_focus")]
+  pub focus: bool,
   /// Whether the window is transparent or not.
   #[serde(default)]
   pub transparent: bool,
@@ -312,6 +318,10 @@ pub struct WindowConfig {
   pub skip_taskbar: bool,
 }
 
+fn default_focus() -> bool {
+  true
+}
+
 fn default_visible() -> bool {
   true
 }

+ 10 - 0
tooling/cli.rs/schema.json

@@ -1099,6 +1099,11 @@
           "default": false,
           "type": "boolean"
         },
+        "center": {
+          "description": "Whether or not the window starts centered or not.",
+          "default": false,
+          "type": "boolean"
+        },
         "decorations": {
           "description": "Whether the window should have borders and bars.",
           "default": true,
@@ -1109,6 +1114,11 @@
           "default": true,
           "type": "boolean"
         },
+        "focus": {
+          "description": "Whether the window will be initially hidden or focused.",
+          "default": true,
+          "type": "boolean"
+        },
         "fullscreen": {
           "description": "Whether the window starts as fullscreen or not.",
           "default": false,