fix(desktop): guard destroyed recovery windows (#37406)
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
export const destroyedWindowURL = "<destroyed>"
|
||||
|
||||
type WebContentsURLState = {
|
||||
isDestroyed(): boolean
|
||||
getURL(): string
|
||||
}
|
||||
|
||||
type WindowURLState = {
|
||||
isDestroyed(): boolean
|
||||
readonly webContents: WebContentsURLState
|
||||
}
|
||||
|
||||
export function safeWebContentsURL(webContents: WebContentsURLState) {
|
||||
try {
|
||||
if (webContents.isDestroyed()) return destroyedWindowURL
|
||||
return webContents.getURL()
|
||||
} catch {
|
||||
return destroyedWindowURL
|
||||
}
|
||||
}
|
||||
|
||||
export function safeWindowURL(win: WindowURLState) {
|
||||
try {
|
||||
if (win.isDestroyed()) return destroyedWindowURL
|
||||
return safeWebContentsURL(win.webContents)
|
||||
} catch {
|
||||
return destroyedWindowURL
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user