mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-04 04:42:37 +02:00
Merge b979bddf48 into 50df9ed178
This commit is contained in:
commit
db4b3b3fea
1 changed files with 14 additions and 9 deletions
|
|
@ -116,21 +116,26 @@ protocol.registerSchemesAsPrivileged([
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const ALLOWED_SESSION_PERMISSIONS = new Set(["media", "display-capture", "clipboard-read", "clipboard-sanitized-write"]);
|
const APP_SESSION_PERMISSIONS = new Set(["media", "display-capture", "clipboard-read", "clipboard-sanitized-write"]);
|
||||||
|
const BROWSER_SESSION_PERMISSIONS = new Set(["clipboard-read", "clipboard-sanitized-write"]);
|
||||||
|
|
||||||
function configureSessionPermissions(targetSession: Session): void {
|
function configureSessionPermissions(targetSession: Session, allowedPermissions: Set<string>): void {
|
||||||
targetSession.setPermissionCheckHandler((_webContents, permission) => {
|
targetSession.setPermissionCheckHandler((_webContents, permission) => {
|
||||||
return ALLOWED_SESSION_PERMISSIONS.has(permission);
|
return allowedPermissions.has(permission);
|
||||||
});
|
});
|
||||||
|
|
||||||
targetSession.setPermissionRequestHandler((_webContents, permission, callback) => {
|
targetSession.setPermissionRequestHandler((_webContents, permission, callback) => {
|
||||||
callback(ALLOWED_SESSION_PERMISSIONS.has(permission));
|
callback(allowedPermissions.has(permission));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Auto-approve display media requests and route system audio as loopback.
|
// Only sessions that explicitly allow display-capture should receive an
|
||||||
// Electron requires a video source in the callback even if we only want audio.
|
// auto-approved source. Embedded browser tabs use a separate session with a
|
||||||
// We pass the first available screen source; the renderer discards the video track.
|
// narrower permission set.
|
||||||
targetSession.setDisplayMediaRequestHandler(async (_request, callback) => {
|
targetSession.setDisplayMediaRequestHandler(async (_request, callback) => {
|
||||||
|
if (!allowedPermissions.has("display-capture")) {
|
||||||
|
callback({});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const sources = await desktopCapturer.getSources({ types: ['screen'] });
|
const sources = await desktopCapturer.getSources({ types: ['screen'] });
|
||||||
if (sources.length === 0) {
|
if (sources.length === 0) {
|
||||||
callback({});
|
callback({});
|
||||||
|
|
@ -159,8 +164,8 @@ function createWindow() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
configureSessionPermissions(session.defaultSession);
|
configureSessionPermissions(session.defaultSession, APP_SESSION_PERMISSIONS);
|
||||||
configureSessionPermissions(session.fromPartition(BROWSER_PARTITION));
|
configureSessionPermissions(session.fromPartition(BROWSER_PARTITION), BROWSER_SESSION_PERMISSIONS);
|
||||||
|
|
||||||
// Show window when content is ready to prevent blank screen
|
// Show window when content is ready to prevent blank screen
|
||||||
win.once("ready-to-show", () => {
|
win.once("ready-to-show", () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue