mirror of
https://github.com/purocean/yn.git
synced 2026-09-24 15:46:02 +08:00
refactor: update setWindowOpenHandler in app.ts to handle additional features
This commit is contained in:
+25
-2
@@ -634,7 +634,7 @@ if (!gotTheLock) {
|
||||
})
|
||||
})
|
||||
|
||||
webContents.setWindowOpenHandler(({ url }) => {
|
||||
webContents.setWindowOpenHandler(({ url, features }) => {
|
||||
if (url.includes('__allow-open-window__')) {
|
||||
return { action: 'allow' }
|
||||
}
|
||||
@@ -652,7 +652,30 @@ if (!gotTheLock) {
|
||||
return { action: 'deny' }
|
||||
}
|
||||
|
||||
return { action: 'allow' }
|
||||
const webPreferences: Record<string, boolean | string> = {}
|
||||
|
||||
// electron not auto parse features below. https://www.electronjs.org/docs/latest/api/window-open
|
||||
const extraFeatureKeys = [
|
||||
'experimentalFeatures',
|
||||
'nodeIntegrationInSubFrames',
|
||||
'webSecurity',
|
||||
]
|
||||
|
||||
extraFeatureKeys.forEach(key => {
|
||||
const match = features.match(new RegExp(`${key}=([^,]+)`))
|
||||
if (match) {
|
||||
webPreferences[key] = match[1] === 'true' ? true : match[1] === 'false' ? false : match[1]
|
||||
}
|
||||
})
|
||||
|
||||
debugger
|
||||
|
||||
return {
|
||||
action: 'allow',
|
||||
overrideBrowserWindowOptions: {
|
||||
webPreferences: Object.keys(webPreferences).length > 0 ? webPreferences : undefined,
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user