Add full-screen display capture alongside the region picker for desktop chat.

This commit is contained in:
CREDO23 2026-04-27 18:49:20 +02:00
parent 62b9e328b4
commit d212422bf5

View file

@ -6,11 +6,13 @@ import { IPC_CHANNELS } from '../ipc/channels';
let pickInProgress = false; let pickInProgress = false;
async function captureDisplayDataUrl(display: Electron.Display): Promise<{ type DisplayCaptureSnapshot = {
dataUrl: string; dataUrl: string;
width: number; width: number;
height: number; height: number;
} | null> { };
async function captureDisplaySnapshot(display: Electron.Display): Promise<DisplayCaptureSnapshot | null> {
try { try {
const sf = display.scaleFactor || 1; const sf = display.scaleFactor || 1;
const tw = Math.max(1, Math.round(display.size.width * sf)); const tw = Math.max(1, Math.round(display.size.width * sf));
@ -37,6 +39,12 @@ async function captureDisplayDataUrl(display: Electron.Display): Promise<{
} }
} }
export async function captureCurrentDisplayDataUrl(): Promise<string | null> {
const display = screen.getDisplayNearestPoint(screen.getCursorScreenPoint());
const snapshot = await captureDisplaySnapshot(display);
return snapshot?.dataUrl ?? null;
}
function buildInjectScript(dataUrl: string, iw: number, ih: number): string { function buildInjectScript(dataUrl: string, iw: number, ih: number): string {
return `(() => { return `(() => {
const api = window.surfsenseScreenRegion; const api = window.surfsenseScreenRegion;
@ -166,7 +174,7 @@ export function pickScreenRegion(): Promise<string | null> {
resolve(result); resolve(result);
}; };
let snapshot: { dataUrl: string; width: number; height: number } | null = null; let snapshot: DisplayCaptureSnapshot | null = null;
const onSubmit = ( const onSubmit = (
_event: Electron.IpcMainEvent, _event: Electron.IpcMainEvent,
@ -206,7 +214,7 @@ export function pickScreenRegion(): Promise<string | null> {
} }
}; };
void captureDisplayDataUrl(display) void captureDisplaySnapshot(display)
.then((cap) => { .then((cap) => {
if (!cap) { if (!cap) {
finish(null); finish(null);