feat(window): add is_focused API

Ref https://github.com/tauri-apps/tauri/pull/6530
Needs tauri 2.0.0-alpha.10
pull/407/head
Lucas Nogueira 2 years ago
parent 0f480d0985
commit 2fcadf283b
No known key found for this signature in database
GPG Key ID: FFEA6C72E73482F1

@ -0,0 +1,6 @@
---
"window": "minor:feat"
"window-js": "minor:feat"
---
Add `WebviewWindow.is_focused` and `WebviewWindow.getFocusedWindow` getters.

737
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -5,8 +5,8 @@ resolver = "2"
[workspace.dependencies]
serde = { version = "1", features = ["derive"] }
log = "0.4"
tauri = "2.0.0-alpha.9"
tauri-build = "2.0.0-alpha.5"
tauri = { git = "https://github.com/tauri-apps/tauri", branch = "chore/merge-from-dev" }
tauri-build = { git = "https://github.com/tauri-apps/tauri", branch = "chore/merge-from-dev" }
serde_json = "1"
thiserror = "1"

@ -565,6 +565,24 @@ class WindowManager extends WebviewWindowHandle {
});
}
/**
* Gets the window's current focus state.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/plugin-window';
* const focused = await appWindow.isFocused();
* ```
*
* @returns Whether the window is focused or not.
*
* @since 2.0.0
* */
async isFocused(): Promise<boolean> {
return window.__TAURI_INVOKE__("plugin:window|is_focused", {
label: this.label,
});
}
/**
* Gets the window's current decorated state.
* @example
@ -1757,6 +1775,27 @@ class WebviewWindow extends WindowManager {
}
return null;
}
/**
* Gets the focused window.
* @example
* ```typescript
* import { WebviewWindow } from '@tauri-apps/plugin-window';
* const focusedWindow = WebviewWindow.getFocusedWindow();
* ```
*
* @returns The WebviewWindow instance to communicate with the webview or `undefined` if there is not any focused window.
*
* @since 1.4
*/
static async getFocusedWindow(): Promise<WebviewWindow | null> {
for (const w of getAll()) {
if (await w.isFocused()) {
return w;
}
}
return null;
}
}
/** The WebviewWindow for the current window. */

File diff suppressed because one or more lines are too long

@ -111,6 +111,7 @@ getter!(outer_size, PhysicalSize<u32>);
getter!(is_fullscreen, bool);
getter!(is_minimized, bool);
getter!(is_maximized, bool);
getter!(is_focused, bool);
getter!(is_decorated, bool);
getter!(is_resizable, bool);
getter!(is_visible, bool);

@ -40,6 +40,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
desktop_commands::is_fullscreen,
desktop_commands::is_minimized,
desktop_commands::is_maximized,
desktop_commands::is_focused,
desktop_commands::is_decorated,
desktop_commands::is_resizable,
desktop_commands::is_visible,

Loading…
Cancel
Save