Skip to content

Commit

Permalink
feat(api): add WebviewWindow.isValid, closes #5380
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Oct 21, 2022
1 parent 161d5be commit d0d9778
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changes/api-webviewwindow-isvalid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"api": "patch"
---

Add `WebviewWindow.isValid` to check if it is valid against the app core cache. Useful when creating a `WebviewWindow` through `WebviewWindow.getByLabelUnchecked`.
10 changes: 5 additions & 5 deletions core/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions core/tauri/src/endpoints/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub enum WindowManagerCmd {
PrimaryMonitor,
AvailableMonitors,
Theme,
IsValid,
// Setters
#[cfg(window_center)]
Center,
Expand Down Expand Up @@ -261,6 +262,10 @@ impl Cmd {
WindowManagerCmd::PrimaryMonitor => return Ok(window.primary_monitor()?.into()),
WindowManagerCmd::AvailableMonitors => return Ok(window.available_monitors()?.into()),
WindowManagerCmd::Theme => return Ok(window.theme()?.into()),
WindowManagerCmd::IsValid => {
// this is unreachable unless the window is valid and exists in the cache.
return Ok(true.into());
}
// Setters
#[cfg(window_center)]
WindowManagerCmd::Center => window.center()?,
Expand Down
2 changes: 1 addition & 1 deletion examples/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This example demonstrates Tauri's API capabilities using the `@tauri-apps/api` package. It's used as the main validation app, serving as the testbed of our development process.
In the future, this app will be used on Tauri's integration tests.

![App screenshot](./screenshot.png?raw=true)
![App screenshot (Windows version)](./screenshot.png?raw=true)

## Running the example

Expand Down
56 changes: 28 additions & 28 deletions examples/api/dist/assets/index.js

Large diffs are not rendered by default.

Binary file modified examples/api/screenshot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions tooling/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,27 @@ class WindowManager extends WebviewWindowHandle {
})
}

/**
* Checks if this WebviewWindow is valid against the app core cache.
* Useful for checking if a WebviewWindow created through {@link WebviewWindow.getByLabelUnchecked} is valid.
*
* @since 1.2.0
*/
async isValid(): Promise<boolean> {
return invokeTauriCommand<boolean>({
__tauriModule: 'Window',
message: {
cmd: 'manage',
data: {
label: this.label,
cmd: {
type: 'isValid'
}
}
}
}).catch((_) => false)
}

// Setters

/**
Expand Down

0 comments on commit d0d9778

Please sign in to comment.