From bc2c331dec3dec44c79e659b082b5fb6b65cc5ea Mon Sep 17 00:00:00 2001 From: FabianLars Date: Mon, 12 Jul 2021 16:59:32 +0200 Subject: [PATCH] fix: center and focus not being allowed in config (#2199) --- .changes/fix-window-config-center-focus.md | 7 +++++++ core/tauri-runtime-wry/src/lib.rs | 4 ++++ tooling/cli.rs/config_definition.rs | 10 ++++++++++ tooling/cli.rs/schema.json | 10 ++++++++++ 4 files changed, 31 insertions(+) create mode 100644 .changes/fix-window-config-center-focus.md diff --git a/.changes/fix-window-config-center-focus.md b/.changes/fix-window-config-center-focus.md new file mode 100644 index 000000000..33c43c96c --- /dev/null +++ b/.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`. \ No newline at end of file diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index 65100a8ea..ab32e707d 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/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(); } diff --git a/tooling/cli.rs/config_definition.rs b/tooling/cli.rs/config_definition.rs index 058c6491a..56a4ce5bf 100644 --- a/tooling/cli.rs/config_definition.rs +++ b/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, /// 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 } diff --git a/tooling/cli.rs/schema.json b/tooling/cli.rs/schema.json index 4a55d16b9..0d78f0cb7 100644 --- a/tooling/cli.rs/schema.json +++ b/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,