Skip to content

Commit 418c0ea

Browse files
authored
feat(desktop): add notification permission for renderer (anomalyco#28119)
1 parent 4312e5d commit 418c0ea

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

packages/desktop/src/main/windows.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const rendererRoot = join(root, "../renderer")
99
const rendererProtocol = "oc"
1010
const rendererHost = "renderer"
1111
const clipboardWritePermission = "clipboard-sanitized-write"
12+
const notificationPermission = "notifications"
13+
const rendererPermissions = new Set([clipboardWritePermission, notificationPermission])
1214

1315
protocol.registerSchemesAsPrivileged([
1416
{
@@ -109,7 +111,7 @@ export function createMainWindow() {
109111
},
110112
})
111113

112-
allowClipboardWrite(win)
114+
allowRendererPermissions(win)
113115

114116
win.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => {
115117
const { requestHeaders } = details
@@ -162,7 +164,7 @@ export function createLoadingWindow() {
162164
},
163165
})
164166

165-
allowClipboardWrite(win)
167+
allowRendererPermissions(win)
166168

167169
loadWindow(win, "loading.html")
168170

@@ -199,16 +201,16 @@ function loadWindow(win: BrowserWindow, html: string) {
199201
void win.loadURL(`${rendererProtocol}://${rendererHost}/${html}`)
200202
}
201203

202-
function allowClipboardWrite(win: BrowserWindow) {
204+
function allowRendererPermissions(win: BrowserWindow) {
203205
win.webContents.session.setPermissionRequestHandler((webContents, permission, callback, details) => {
204206
callback(
205-
permission === clipboardWritePermission &&
207+
rendererPermissions.has(permission) &&
206208
isTrustedRendererUrl(details.requestingUrl) &&
207209
webContents.id === win.webContents.id,
208210
)
209211
})
210212
win.webContents.session.setPermissionCheckHandler((webContents, permission, requestingOrigin, details) => {
211-
if (permission !== clipboardWritePermission) return false
213+
if (!rendererPermissions.has(permission)) return false
212214
if (webContents && webContents.id !== win.webContents.id) return false
213215
return isTrustedRendererUrl(details.requestingUrl) || isTrustedRendererUrl(requestingOrigin)
214216
})

0 commit comments

Comments
 (0)