Skip to content

Commit 70c5137

Browse files
authored
feat(core): add isTauri (#9539)
* feat(core): add `isTauri` * generate api
1 parent 005fe8c commit 70c5137

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

.changes/api-isTauri.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@tauri-apps/api": "patch:feat"
3+
---
4+
5+
Add `isTauri` function in `core` module to check whether running inside tauri or not.
6+

.changes/core-isTauri.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": "patch:feat"
3+
---
4+
5+
Add `window.isTauri` to check whether running inside tauri or not.
6+

core/tauri/scripts/bundle.global.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/tauri/src/manager/webview.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ impl<R: Runtime> WebviewManager<R> {
165165
webview_attributes = webview_attributes
166166
.initialization_script(
167167
r#"
168+
Object.defineProperty(window, 'isTauri', {
169+
value: true,
170+
});
171+
168172
if (!window.__TAURI_INTERNALS__) {
169173
Object.defineProperty(window, '__TAURI_INTERNALS__', {
170174
value: {

tooling/api/src/core.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ export class Resource {
238238
}
239239
}
240240

241+
function isTauri() {
242+
return 'isTauri' in window && window.isTauri
243+
}
244+
241245
export type { InvokeArgs, InvokeOptions }
242246

243247
export {
@@ -246,5 +250,6 @@ export {
246250
PluginListener,
247251
addPluginListener,
248252
invoke,
249-
convertFileSrc
253+
convertFileSrc,
254+
isTauri
250255
}

0 commit comments

Comments
 (0)