mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-18 15:02:31 +00:00
feat(desktop): add notification permission for renderer (#28119)
This commit is contained in:
parent
4312e5df05
commit
418c0ea04a
1 changed files with 7 additions and 5 deletions
|
|
@ -9,6 +9,8 @@ const rendererRoot = join(root, "../renderer")
|
|||
const rendererProtocol = "oc"
|
||||
const rendererHost = "renderer"
|
||||
const clipboardWritePermission = "clipboard-sanitized-write"
|
||||
const notificationPermission = "notifications"
|
||||
const rendererPermissions = new Set([clipboardWritePermission, notificationPermission])
|
||||
|
||||
protocol.registerSchemesAsPrivileged([
|
||||
{
|
||||
|
|
@ -109,7 +111,7 @@ export function createMainWindow() {
|
|||
},
|
||||
})
|
||||
|
||||
allowClipboardWrite(win)
|
||||
allowRendererPermissions(win)
|
||||
|
||||
win.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => {
|
||||
const { requestHeaders } = details
|
||||
|
|
@ -162,7 +164,7 @@ export function createLoadingWindow() {
|
|||
},
|
||||
})
|
||||
|
||||
allowClipboardWrite(win)
|
||||
allowRendererPermissions(win)
|
||||
|
||||
loadWindow(win, "loading.html")
|
||||
|
||||
|
|
@ -199,16 +201,16 @@ function loadWindow(win: BrowserWindow, html: string) {
|
|||
void win.loadURL(`${rendererProtocol}://${rendererHost}/${html}`)
|
||||
}
|
||||
|
||||
function allowClipboardWrite(win: BrowserWindow) {
|
||||
function allowRendererPermissions(win: BrowserWindow) {
|
||||
win.webContents.session.setPermissionRequestHandler((webContents, permission, callback, details) => {
|
||||
callback(
|
||||
permission === clipboardWritePermission &&
|
||||
rendererPermissions.has(permission) &&
|
||||
isTrustedRendererUrl(details.requestingUrl) &&
|
||||
webContents.id === win.webContents.id,
|
||||
)
|
||||
})
|
||||
win.webContents.session.setPermissionCheckHandler((webContents, permission, requestingOrigin, details) => {
|
||||
if (permission !== clipboardWritePermission) return false
|
||||
if (!rendererPermissions.has(permission)) return false
|
||||
if (webContents && webContents.id !== win.webContents.id) return false
|
||||
return isTrustedRendererUrl(details.requestingUrl) || isTrustedRendererUrl(requestingOrigin)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue