fix(view-once): hold-to-view pattern + content-protection during reveal
This commit is contained in:
@@ -107,6 +107,11 @@ export const CHANNELS = {
|
||||
// OS fullscreen so the Windows taskbar / macOS menubar gets covered.
|
||||
WINDOW_SET_FULLSCREEN: 'window:set-fullscreen',
|
||||
|
||||
// Content-protection toggle. Enables/disables OS-level screenshot/screen-
|
||||
// recording block (WDA_MONITOR on Windows, NSWindowSharingNone on macOS)
|
||||
// while a view-once image is being revealed. No-op on Linux X11.
|
||||
WINDOW_SET_CONTENT_PROTECTION: 'window:set-content-protection',
|
||||
|
||||
// Wipe-on-close — main process pushes this to the renderer right before
|
||||
// exiting if the user has enabled the Settings → Sicherheit toggle. The
|
||||
// renderer clears its sensitive caches (memoryWipe.ts) and acks via
|
||||
@@ -271,6 +276,12 @@ export interface UpdateProgress {
|
||||
total: number;
|
||||
}
|
||||
|
||||
// ---- Window content protection -------------------------------------------
|
||||
|
||||
export interface WindowSetContentProtectionArgs {
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
// ---- Runtime marker ------------------------------------------------------
|
||||
|
||||
/** Value exposed on `window.electronAPI.platform`. Used by the renderer
|
||||
|
||||
@@ -26,6 +26,7 @@ import { register as registerShortcuts } from './modules/shortcuts';
|
||||
import { register as registerSql } from './modules/sql';
|
||||
import { register as registerTray } from './modules/tray';
|
||||
import { register as registerUpdater } from './modules/updater';
|
||||
import { register as registerWindowContentProtection } from './modules/window-content-protection';
|
||||
import { register as registerWindowFullscreen } from './modules/window-fullscreen';
|
||||
import { attach as attachWindowState, loadState } from './window-state';
|
||||
|
||||
@@ -274,6 +275,7 @@ if (!gotLock) {
|
||||
registerTray(mainWindow);
|
||||
registerUpdater(mainWindow);
|
||||
registerWindowFullscreen(mainWindow);
|
||||
registerWindowContentProtection(mainWindow);
|
||||
registerAudioLoopback(mainWindow);
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// 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);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
+6
@@ -96,6 +96,12 @@ export interface ElectronAPI {
|
||||
|
||||
setFullscreen: (enabled: boolean) => Promise<void>;
|
||||
|
||||
/** Block OS-level screen capture (Win+PrtScr, OBS, etc.) while a
|
||||
* view-once image is being revealed. Covers Windows (WDA_MONITOR) and
|
||||
* macOS (NSWindowSharingNone). No-op on Linux X11. Optional: always
|
||||
* feature-check because the web build has no preload bridge. */
|
||||
setContentProtection?: (enabled: boolean) => Promise<void>;
|
||||
|
||||
/** Subscribe to the main-process pre-quit notification. Used by the
|
||||
* "Cache beim Schließen leeren" Settings toggle. */
|
||||
onWipeBeforeQuit: (cb: () => Promise<void>) => () => void;
|
||||
|
||||
@@ -160,6 +160,10 @@ const api = {
|
||||
setFullscreen: (enabled: boolean): Promise<void> =>
|
||||
ipcRenderer.invoke(CHANNELS.WINDOW_SET_FULLSCREEN, enabled),
|
||||
|
||||
// Window content protection ----------------------------------------------
|
||||
setContentProtection: (enabled: boolean): Promise<void> =>
|
||||
ipcRenderer.invoke(CHANNELS.WINDOW_SET_CONTENT_PROTECTION, { enabled }),
|
||||
|
||||
// OS hostname ------------------------------------------------------------
|
||||
getHostname: (): Promise<string | null> => ipcRenderer.invoke(CHANNELS.APP_HOSTNAME),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user