feat(core): add isTauri (#9539)

* feat(core): add `isTauri`

* generate api
This commit is contained in:
Amr Bashir 2024-04-22 15:07:11 +02:00 committed by GitHub
parent 005fe8ce1e
commit 70c51371e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 23 additions and 2 deletions

6
.changes/api-isTauri.md Normal file
View File

@ -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/core-isTauri.md Normal file
View File

@ -0,0 +1,6 @@
---
"tauri": "patch:feat"
---
Add `window.isTauri` to check whether running inside tauri or not.

File diff suppressed because one or more lines are too long

View File

@ -165,6 +165,10 @@ impl<R: Runtime> WebviewManager<R> {
webview_attributes = webview_attributes webview_attributes = webview_attributes
.initialization_script( .initialization_script(
r#" r#"
Object.defineProperty(window, 'isTauri', {
value: true,
});
if (!window.__TAURI_INTERNALS__) { if (!window.__TAURI_INTERNALS__) {
Object.defineProperty(window, '__TAURI_INTERNALS__', { Object.defineProperty(window, '__TAURI_INTERNALS__', {
value: { value: {

View File

@ -238,6 +238,10 @@ export class Resource {
} }
} }
function isTauri() {
return 'isTauri' in window && window.isTauri
}
export type { InvokeArgs, InvokeOptions } export type { InvokeArgs, InvokeOptions }
export { export {
@ -246,5 +250,6 @@ export {
PluginListener, PluginListener,
addPluginListener, addPluginListener,
invoke, invoke,
convertFileSrc convertFileSrc,
isTauri
} }