fix(api): do not throw an exception if __TAURI_METADATA__ is not set, fixes #3554 (#3572)

This commit is contained in:
Lucas Fernandes Nogueira 2022-03-03 10:40:31 -03:00 committed by GitHub
parent 0f1558980a
commit 9cb1059aa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 16 deletions

View File

@ -0,0 +1,5 @@
---
"api": patch
---
Do not crash if `__TAURI_METADATA__` is not set, log an error instead.

File diff suppressed because one or more lines are too long

View File

@ -879,12 +879,12 @@ class WindowManager extends WebviewWindowHandle {
type: 'setMinSize',
payload: size
? {
type: size.type,
data: {
width: size.width,
height: size.height
}
type: size.type,
data: {
width: size.width,
height: size.height
}
}
: null
}
}
@ -921,12 +921,12 @@ class WindowManager extends WebviewWindowHandle {
type: 'setMaxSize',
payload: size
? {
type: size.type,
data: {
width: size.width,
height: size.height
}
type: size.type,
data: {
width: size.width,
height: size.height
}
}
: null
}
}
@ -1157,13 +1157,24 @@ class WebviewWindow extends WindowManager {
}
/** The WebviewWindow for the current window. */
const appWindow = new WebviewWindow(
window.__TAURI_METADATA__.__currentWindow.label,
{
let appWindow
if ('__TAURI_METADATA__' in window) {
appWindow = new WebviewWindow(
window.__TAURI_METADATA__.__currentWindow.label,
{
// @ts-expect-error
skip: true
}
)
} else {
console.warn(
`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.`
)
appWindow = new WebviewWindow('main', {
// @ts-expect-error
skip: true
}
)
})
}
/** Configuration for the window to create. */
interface WindowOptions {