Skip to content

Commit 5f35162

Browse files
committed
feat(core): add focus API to the WindowBuilder and WindowOptions, #1737
1 parent bb6992f commit 5f35162

File tree

6 files changed

+39
-11
lines changed

6 files changed

+39
-11
lines changed

.changes/api-focus.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": patch
3+
---
4+
5+
Adds `focus?: boolean` to the WindowOptions interface.

.changes/focus.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri": patch
3+
"tauri-runtime": patch
4+
"tauri-runtime-wry": patch
5+
---
6+
7+
Adds `focus` API to the WindowBuilder.

core/tauri-runtime-wry/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ impl WindowBuilder for WindowBuilderWrapper {
315315
}
316316
}
317317

318+
fn focus(self) -> Self {
319+
Self(self.0.with_focus())
320+
}
321+
318322
fn maximized(self, maximized: bool) -> Self {
319323
Self(self.0.with_maximized(maximized))
320324
}

core/tauri-runtime/src/webview.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ pub trait WindowBuilder: WindowBuilderBase {
124124
/// Whether to start the window in fullscreen or not.
125125
fn fullscreen(self, fullscreen: bool) -> Self;
126126

127+
/// Whether the window will be initially hidden or focused.
128+
fn focus(self) -> Self;
129+
127130
/// Whether the window should be maximized upon creation.
128131
fn maximized(self, maximized: bool) -> Self;
129132

core/tauri-utils/src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ pub struct WindowConfig {
6969
/// Whether the window starts as fullscreen or not.
7070
#[serde(default)]
7171
pub fullscreen: bool,
72+
/// Whether the window will be initially hidden or focused.
73+
#[serde(default)]
74+
pub focus: bool,
7275
/// Whether the window is transparent or not.
7376
#[serde(default)]
7477
pub transparent: bool,
@@ -130,6 +133,7 @@ impl Default for WindowConfig {
130133
resizable: default_resizable(),
131134
title: default_title(),
132135
fullscreen: false,
136+
focus: false,
133137
transparent: false,
134138
maximized: false,
135139
visible: default_visible(),
@@ -630,6 +634,7 @@ mod build {
630634
let resizable = self.resizable;
631635
let title = str_lit(&self.title);
632636
let fullscreen = self.fullscreen;
637+
let focus = self.focus;
633638
let transparent = self.transparent;
634639
let maximized = self.maximized;
635640
let visible = self.visible;
@@ -652,6 +657,7 @@ mod build {
652657
resizable,
653658
title,
654659
fullscreen,
660+
focus,
655661
transparent,
656662
maximized,
657663
visible,
@@ -899,6 +905,7 @@ mod test {
899905
resizable: true,
900906
title: String::from("Tauri App"),
901907
fullscreen: false,
908+
focus: false,
902909
transparent: false,
903910
maximized: false,
904911
visible: true,

tooling/api/src/window.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,12 @@ class WindowManager {
593593
cmd: 'setMinSize',
594594
data: size
595595
? {
596-
type: size.type,
597-
data: {
598-
width: size.width,
599-
height: size.height
596+
type: size.type,
597+
data: {
598+
width: size.width,
599+
height: size.height
600+
}
600601
}
601-
}
602602
: null
603603
}
604604
})
@@ -629,12 +629,12 @@ class WindowManager {
629629
cmd: 'setMaxSize',
630630
data: size
631631
? {
632-
type: size.type,
633-
data: {
634-
width: size.width,
635-
height: size.height
632+
type: size.type,
633+
data: {
634+
width: size.width,
635+
height: size.height
636+
}
636637
}
637-
}
638638
: null
639639
}
640640
})
@@ -695,7 +695,7 @@ class WindowManager {
695695

696696
/**
697697
* Bring the window to front and focus.
698-
*
698+
*
699699
* @returns A promise indicating the success or failure of the operation.
700700
*/
701701
async setFocus(): Promise<void> {
@@ -771,6 +771,8 @@ interface WindowOptions {
771771
title?: string
772772
/** Whether the window is in fullscreen mode or not. */
773773
fullscreen?: boolean
774+
/** Whether the window will be initially hidden or focused. */
775+
focus?: boolean
774776
/** Whether the window is transparent or not. */
775777
transparent?: boolean
776778
/** Whether the window should be maximized upon creation or not. */

0 commit comments

Comments
 (0)