mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-22 21:30:44 +02:00
feat(window): add is_focused API (#407)
This commit is contained in:
@@ -563,6 +563,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
|
||||
@@ -1779,6 +1797,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. */
|
||||
|
||||
Reference in New Issue
Block a user