Skip to content

Commit 4036e15

Browse files
authored
feat(core): reimplement window initial focus flag, closes #5120 (#5338)
1 parent 8357ce5 commit 4036e15

File tree

8 files changed

+29
-12
lines changed

8 files changed

+29
-12
lines changed

Diff for: .changes/focused.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri": minor
3+
"tauri-runtime": minor
4+
"tauri-runtime-wry": minor
5+
---
6+
7+
Readd the option to create an unfocused window via the `focused` method. The `focus` function has been deprecated.

Diff for: core/tauri-runtime-wry/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ unsafe impl Send for WindowBuilderWrapper {}
690690
impl WindowBuilderBase for WindowBuilderWrapper {}
691691
impl WindowBuilder for WindowBuilderWrapper {
692692
fn new() -> Self {
693-
Default::default()
693+
Self::default().focused(true)
694694
}
695695

696696
fn with_config(config: WindowConfig) -> Self {
@@ -803,9 +803,8 @@ impl WindowBuilder for WindowBuilderWrapper {
803803
self
804804
}
805805

806-
/// Deprecated since 0.1.4 (noop)
807-
/// Windows is automatically focused when created.
808-
fn focus(self) -> Self {
806+
fn focused(mut self, focused: bool) -> Self {
807+
self.inner = self.inner.with_focused(focused);
809808
self
810809
}
811810

Diff for: core/tauri-runtime/src/webview.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ pub trait WindowBuilder: WindowBuilderBase {
133133
#[must_use]
134134
fn fullscreen(self, fullscreen: bool) -> Self;
135135

136-
/// Whether the window will be initially hidden or focused.
136+
/// Whether the window will be initially focused or not.
137137
#[must_use]
138-
fn focus(self) -> Self;
138+
fn focused(self, focused: bool) -> Self;
139139

140140
/// Whether the window should be maximized upon creation.
141141
#[must_use]

Diff for: core/tauri-utils/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ pub struct WindowConfig {
838838
/// Whether the window starts as fullscreen or not.
839839
#[serde(default)]
840840
pub fullscreen: bool,
841-
/// Whether the window will be initially hidden or focused.
841+
/// Whether the window will be initially focused or not.
842842
#[serde(default = "default_focus")]
843843
pub focus: bool,
844844
/// Whether the window is transparent or not.

Diff for: core/tauri/src/test/mock_runtime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl WindowBuilder for MockWindowBuilder {
221221
self
222222
}
223223

224-
fn focus(self) -> Self {
224+
fn focused(self, focused: bool) -> Self {
225225
self
226226
}
227227

Diff for: core/tauri/src/window.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,21 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
328328
self
329329
}
330330

331-
/// Whether the window will be initially hidden or focused.
331+
/// Sets the window to be initially focused.
332332
#[must_use]
333+
#[deprecated(
334+
since = "1.2.0",
335+
note = "The window is automatically focused by default. This function Will be removed in 2.0.0. Use `focused` instead."
336+
)]
333337
pub fn focus(mut self) -> Self {
334-
self.window_builder = self.window_builder.focus();
338+
self.window_builder = self.window_builder.focused(true);
339+
self
340+
}
341+
342+
/// Whether the window will be initially focused or not.
343+
#[must_use]
344+
pub fn focused(mut self, focused: bool) -> Self {
345+
self.window_builder = self.window_builder.focused(focused);
335346
self
336347
}
337348

Diff for: tooling/api/src/window.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,7 @@ interface WindowOptions {
20042004
title?: string
20052005
/** Whether the window is in fullscreen mode or not. */
20062006
fullscreen?: boolean
2007-
/** Whether the window will be initially hidden or focused. */
2007+
/** Whether the window will be initially focused or not. */
20082008
focus?: boolean
20092009
/**
20102010
* Whether the window is transparent or not.

Diff for: tooling/cli/schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@
612612
"type": "boolean"
613613
},
614614
"focus": {
615-
"description": "Whether the window will be initially hidden or focused.",
615+
"description": "Whether the window will be initially focused or not.",
616616
"default": true,
617617
"type": "boolean"
618618
},

0 commit comments

Comments
 (0)