Skip to content

Commit

Permalink
feat(core): add isTauri (#9539)
Browse files Browse the repository at this point in the history
* feat(core): add `isTauri`

* generate api
  • Loading branch information
amrbashir committed Apr 22, 2024
1 parent 005fe8c commit 70c5137
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changes/api-isTauri.md
@@ -0,0 +1,6 @@
---
"@tauri-apps/api": "patch:feat"
---

Add `isTauri` function in `core` module to check whether running inside tauri or not.

6 changes: 6 additions & 0 deletions .changes/core-isTauri.md
@@ -0,0 +1,6 @@
---
"tauri": "patch:feat"
---

Add `window.isTauri` to check whether running inside tauri or not.

2 changes: 1 addition & 1 deletion core/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions core/tauri/src/manager/webview.rs
Expand Up @@ -165,6 +165,10 @@ impl<R: Runtime> WebviewManager<R> {
webview_attributes = webview_attributes
.initialization_script(
r#"
Object.defineProperty(window, 'isTauri', {
value: true,
});
if (!window.__TAURI_INTERNALS__) {
Object.defineProperty(window, '__TAURI_INTERNALS__', {
value: {
Expand Down
7 changes: 6 additions & 1 deletion tooling/api/src/core.ts
Expand Up @@ -238,6 +238,10 @@ export class Resource {
}
}

function isTauri() {
return 'isTauri' in window && window.isTauri
}

export type { InvokeArgs, InvokeOptions }

export {
Expand All @@ -246,5 +250,6 @@ export {
PluginListener,
addPluginListener,
invoke,
convertFileSrc
convertFileSrc,
isTauri
}

0 comments on commit 70c5137

Please sign in to comment.