Skip to content

Commit

Permalink
feat(core): add focus API to the WindowBuilder and WindowOptions, #1737
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed May 30, 2021
1 parent bb6992f commit 5f35162
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changes/api-focus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"api": patch
---

Adds `focus?: boolean` to the WindowOptions interface.
7 changes: 7 additions & 0 deletions .changes/focus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": patch
"tauri-runtime": patch
"tauri-runtime-wry": patch
---

Adds `focus` API to the WindowBuilder.
4 changes: 4 additions & 0 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ impl WindowBuilder for WindowBuilderWrapper {
}
}

fn focus(self) -> Self {
Self(self.0.with_focus())
}

fn maximized(self, maximized: bool) -> Self {
Self(self.0.with_maximized(maximized))
}
Expand Down
3 changes: 3 additions & 0 deletions core/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ pub trait WindowBuilder: WindowBuilderBase {
/// Whether to start the window in fullscreen or not.
fn fullscreen(self, fullscreen: bool) -> Self;

/// Whether the window will be initially hidden or focused.
fn focus(self) -> Self;

/// Whether the window should be maximized upon creation.
fn maximized(self, maximized: bool) -> Self;

Expand Down
7 changes: 7 additions & 0 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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)]
pub focus: bool,
/// Whether the window is transparent or not.
#[serde(default)]
pub transparent: bool,
Expand Down Expand Up @@ -130,6 +133,7 @@ impl Default for WindowConfig {
resizable: default_resizable(),
title: default_title(),
fullscreen: false,
focus: false,
transparent: false,
maximized: false,
visible: default_visible(),
Expand Down Expand Up @@ -630,6 +634,7 @@ mod build {
let resizable = self.resizable;
let title = str_lit(&self.title);
let fullscreen = self.fullscreen;
let focus = self.focus;
let transparent = self.transparent;
let maximized = self.maximized;
let visible = self.visible;
Expand All @@ -652,6 +657,7 @@ mod build {
resizable,
title,
fullscreen,
focus,
transparent,
maximized,
visible,
Expand Down Expand Up @@ -899,6 +905,7 @@ mod test {
resizable: true,
title: String::from("Tauri App"),
fullscreen: false,
focus: false,
transparent: false,
maximized: false,
visible: true,
Expand Down
24 changes: 13 additions & 11 deletions tooling/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,12 @@ class WindowManager {
cmd: 'setMinSize',
data: size
? {
type: size.type,
data: {
width: size.width,
height: size.height
type: size.type,
data: {
width: size.width,
height: size.height
}
}
}
: null
}
})
Expand Down Expand Up @@ -629,12 +629,12 @@ class WindowManager {
cmd: 'setMaxSize',
data: size
? {
type: size.type,
data: {
width: size.width,
height: size.height
type: size.type,
data: {
width: size.width,
height: size.height
}
}
}
: null
}
})
Expand Down Expand Up @@ -695,7 +695,7 @@ class WindowManager {

/**
* Bring the window to front and focus.
*
*
* @returns A promise indicating the success or failure of the operation.
*/
async setFocus(): Promise<void> {
Expand Down Expand Up @@ -771,6 +771,8 @@ interface WindowOptions {
title?: string
/** Whether the window is in fullscreen mode or not. */
fullscreen?: boolean
/** Whether the window will be initially hidden or focused. */
focus?: boolean
/** Whether the window is transparent or not. */
transparent?: boolean
/** Whether the window should be maximized upon creation or not. */
Expand Down

0 comments on commit 5f35162

Please sign in to comment.