feat(core): add focus API to the WindowBuilder and WindowOptions, #1737

This commit is contained in:
Lucas Nogueira 2021-05-30 17:41:28 -03:00
parent bb6992f888
commit 5f351622c7
No known key found for this signature in database
GPG Key ID: 2714B66BCFB01F7F
6 changed files with 39 additions and 11 deletions

5
.changes/api-focus.md Normal file
View File

@ -0,0 +1,5 @@
---
"api": patch
---
Adds `focus?: boolean` to the WindowOptions interface.

7
.changes/focus.md Normal file
View File

@ -0,0 +1,7 @@
---
"tauri": patch
"tauri-runtime": patch
"tauri-runtime-wry": patch
---
Adds `focus` API to the WindowBuilder.

View File

@ -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))
}

View File

@ -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;

View File

@ -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,
@ -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(),
@ -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;
@ -652,6 +657,7 @@ mod build {
resizable,
title,
fullscreen,
focus,
transparent,
maximized,
visible,
@ -899,6 +905,7 @@ mod test {
resizable: true,
title: String::from("Tauri App"),
fullscreen: false,
focus: false,
transparent: false,
maximized: false,
visible: true,

View File

@ -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
}
})
@ -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
}
})
@ -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> {
@ -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. */