// Window content-protection adapter. Enables / disables OS-level // screenshot and screen-recording blocking on the host BrowserWindow. // // Windows: WDA_MONITOR (SetWindowDisplayAffinity) — the window surface // appears black in any screen capture tool (OBS, Snipping Tool, // Win+PrtScr, etc.) while protection is enabled. // macOS: NSWindowSharingNone — equivalent coverage for QuickTime, // Cmd+Shift+3/4, and external recorders. // Linux: No-op. Electron exposes the API on all platforms but the // X11/Wayland compositors don't honour it in Electron 33. // // Called by the renderer during view-once image reveals so the image // cannot be captured by an OS-level screenshot while it is on screen. import { BrowserWindow, ipcMain } from 'electron'; import { CHANNELS, type WindowSetContentProtectionArgs } from '../ipc-types'; export function register(mainWindow: BrowserWindow): void { ipcMain.handle( CHANNELS.WINDOW_SET_CONTENT_PROTECTION, (_evt, args: WindowSetContentProtectionArgs) => { // Electron's setContentProtection covers Windows (WDA_MONITOR) and // macOS (NSWindowSharingNone) in one call. No-op on Linux X11. // Wrapped in try/catch because the window can already be destroyed // by the time this fires during a teardown. try { const win = BrowserWindow.fromWebContents(_evt.sender) ?? mainWindow; if (!win || win.isDestroyed()) return; win.setContentProtection(args.enabled); } catch (err) { console.warn('setContentProtection failed', err); } }, ); }