Skip to content

Commit 9cb1059

Browse files
authored
fix(api): do not throw an exception if __TAURI_METADATA__ is not set, fixes #3554 (#3572)
1 parent 0f15589 commit 9cb1059

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

.changes/api-app-window-browser.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": patch
3+
---
4+
5+
Do not crash if `__TAURI_METADATA__` is not set, log an error instead.

core/tauri/scripts/bundle.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/api/src/window.ts

+26-15
Original file line numberDiff line numberDiff line change
@@ -879,12 +879,12 @@ class WindowManager extends WebviewWindowHandle {
879879
type: 'setMinSize',
880880
payload: size
881881
? {
882-
type: size.type,
883-
data: {
884-
width: size.width,
885-
height: size.height
886-
}
882+
type: size.type,
883+
data: {
884+
width: size.width,
885+
height: size.height
887886
}
887+
}
888888
: null
889889
}
890890
}
@@ -921,12 +921,12 @@ class WindowManager extends WebviewWindowHandle {
921921
type: 'setMaxSize',
922922
payload: size
923923
? {
924-
type: size.type,
925-
data: {
926-
width: size.width,
927-
height: size.height
928-
}
924+
type: size.type,
925+
data: {
926+
width: size.width,
927+
height: size.height
929928
}
929+
}
930930
: null
931931
}
932932
}
@@ -1157,13 +1157,24 @@ class WebviewWindow extends WindowManager {
11571157
}
11581158

11591159
/** The WebviewWindow for the current window. */
1160-
const appWindow = new WebviewWindow(
1161-
window.__TAURI_METADATA__.__currentWindow.label,
1162-
{
1160+
let appWindow
1161+
if ('__TAURI_METADATA__' in window) {
1162+
appWindow = new WebviewWindow(
1163+
window.__TAURI_METADATA__.__currentWindow.label,
1164+
{
1165+
// @ts-expect-error
1166+
skip: true
1167+
}
1168+
)
1169+
} else {
1170+
console.warn(
1171+
`Could not find "window.__TAURI_METADATA__". The "appWindow" value will reference the "main" window label.\nNote that this is not an issue if running this frontend on a browser instead of a Tauri window.`
1172+
)
1173+
appWindow = new WebviewWindow('main', {
11631174
// @ts-expect-error
11641175
skip: true
1165-
}
1166-
)
1176+
})
1177+
}
11671178

11681179
/** Configuration for the window to create. */
11691180
interface WindowOptions {

0 commit comments

Comments
 (0)