Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions electron/electron-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ interface RendererNativeExportCapabilities {
interface Window {
electronAPI: {
hudOverlaySetIgnoreMouse: (ignore: boolean) => void;
hudOverlaySetSourceSelectionActive: (active: boolean) => void;
hudOverlayDrag: (phase: "start" | "move" | "end", screenX: number, screenY: number) => void;
hudOverlayHide: () => void;
hudOverlayClose: () => void;
Expand Down
4 changes: 4 additions & 0 deletions electron/hudOverlayBounds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ describe("shouldResizeHudOverlayFallback", () => {
it("keeps the recording HUD compact in non-passthrough mode", () => {
expect(shouldResizeHudOverlayFallback(false, true)).toBe(false);
});

it("keeps the fallback stable while source selection is active", () => {
expect(shouldResizeHudOverlayFallback(false, false, true)).toBe(false);
});
});

describe("shouldExpandHudOverlayFallback", () => {
Expand Down
3 changes: 2 additions & 1 deletion electron/hudOverlayBounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ export function getHudOverlayWindowBounds(
export function shouldResizeHudOverlayFallback(
mousePassthroughSupported: boolean,
recordingActive: boolean,
interactionLocked = false,
): boolean {
return !mousePassthroughSupported && !recordingActive;
return !mousePassthroughSupported && !recordingActive && !interactionLocked;
}

export function shouldExpandHudOverlayFallback({
Expand Down
11 changes: 8 additions & 3 deletions electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ contextBridge.exposeInMainWorld("electronAPI", {
hudOverlaySetIgnoreMouse: (ignore: boolean) => {
ipcRenderer.send("hud-overlay-set-ignore-mouse", ignore);
},
hudOverlaySetSourceSelectionActive: (active: boolean) => {
ipcRenderer.send("hud-overlay-set-source-selection-active", active);
},
hudOverlayDrag: (phase: "start" | "move" | "end", screenX: number, screenY: number) => {
ipcRenderer.send("hud-overlay-drag", phase, screenX, screenY);
},
Expand Down Expand Up @@ -708,8 +711,10 @@ contextBridge.exposeInMainWorld("electronAPI", {
return ipcRenderer.invoke("set-current-recording-session", session, options);
},
onRecordingSessionChanged: (callback: (session: RecordingSessionData | null) => void) => {
const listener = (_event: Electron.IpcRendererEvent, payload: RecordingSessionData | null) =>
callback(payload);
const listener = (
_event: Electron.IpcRendererEvent,
payload: RecordingSessionData | null,
) => callback(payload);
ipcRenderer.on("recording-session-changed", listener);
return () => ipcRenderer.removeListener("recording-session-changed", listener);
},
Expand Down Expand Up @@ -896,7 +901,7 @@ contextBridge.exposeInMainWorld("electronAPI", {
success?: boolean;
value?: unknown;
};
return result?.success ? result.value ?? null : null;
return result?.success ? (result.value ?? null) : null;
},
setAppSetting: (key: string, value: unknown) => {
const result = ipcRenderer.sendSync("app-settings:set", key, value) as {
Expand Down
33 changes: 31 additions & 2 deletions electron/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ let hudOverlayHiddenFromCapture = true;
let hudOverlayCaptureProtectionLoaded = false;
let hudOverlayFallbackExpanded = false;
let hudOverlayIgnoringMouse = true;
let hudOverlaySourceSelectionActive = false;
let hudOverlayMouseReassertTimer: NodeJS.Timeout | null = null;
let hudOverlayRecordingActive = false;
let hudOverlayWebcamPreviewVisible = false;
Expand Down Expand Up @@ -287,7 +288,12 @@ function setHudOverlayFallbackExpanded(expanded: boolean) {
}

function setHudOverlayMousePassthrough(ignore: boolean) {
hudOverlayIgnoringMouse = hudOverlayRecordingActive ? false : ignore;
hudOverlayIgnoringMouse =
hudOverlaySourceSelectionActive && !hudOverlayRecordingActive
? true
: hudOverlayRecordingActive
? false
: ignore;

if (hudOverlayMouseReassertTimer) {
clearTimeout(hudOverlayMouseReassertTimer);
Expand All @@ -305,9 +311,21 @@ function setHudOverlayMousePassthrough(ignore: boolean) {
return;
}

if (hudOverlaySourceSelectionActive) {
hudOverlayFallbackExpanded = false;
hudOverlayWindow.setIgnoreMouseEvents(false);
return;
}

const mousePassthroughSupported = isHudOverlayMousePassthroughSupported();
if (!mousePassthroughSupported) {
if (shouldResizeHudOverlayFallback(mousePassthroughSupported, hudOverlayRecordingActive)) {
if (
shouldResizeHudOverlayFallback(
mousePassthroughSupported,
hudOverlayRecordingActive,
hudOverlaySourceSelectionActive,
)
) {
setHudOverlayFallbackExpanded(!ignore);
}
hudOverlayWindow.setIgnoreMouseEvents(false);
Expand All @@ -326,6 +344,17 @@ ipcMain.on("hud-overlay-set-ignore-mouse", (_event, ignore: boolean) => {
setHudOverlayMousePassthrough(Boolean(ignore));
});

ipcMain.on("hud-overlay-set-source-selection-active", (_event, active: boolean) => {
hudOverlaySourceSelectionActive = Boolean(active);
if (hudOverlaySourceSelectionActive) {
hudOverlayFallbackExpanded = false;
applyHudOverlayBounds();
return;
}

setHudOverlayMousePassthrough(hudOverlayIgnoringMouse);
});

// Keep compatibility with existing drag IPC/state.
let hudUserPosition: { x: number; y: number } | null = null;
let hudDragOffset: { x: number; y: number } | null = null;
Expand Down
27 changes: 27 additions & 0 deletions src/hooks/useScreenRecorder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
normalizeBrowserMicrophoneProfile,
resolveBrowserCaptureCursorPolicy,
resolveLinuxPortalCursorPresentation,
shouldLockHudDuringDisplaySelection,
shouldUseLinuxPortalCapture,
shouldUseNativeWindowsCaptureForSource,
} from "./useScreenRecorder";
Expand Down Expand Up @@ -246,6 +247,32 @@ describe("shouldUseLinuxPortalCapture", () => {
});
});

describe("shouldLockHudDuringDisplaySelection", () => {
it("locks HUD fallback resizing while Linux portal selection is active", () => {
expect(
shouldLockHudDuringDisplaySelection({
platform: "linux",
useLinuxPortal: true,
}),
).toBe(true);
});

it("keeps non-portal capture flows interactive", () => {
expect(
shouldLockHudDuringDisplaySelection({
platform: "linux",
useLinuxPortal: false,
}),
).toBe(false);
expect(
shouldLockHudDuringDisplaySelection({
platform: "win32",
useLinuxPortal: true,
}),
).toBe(false);
});
});

describe("getScreenCaptureCursorSetting", () => {
it("normalizes only supported screen-capture cursor settings", () => {
expect(getScreenCaptureCursorSetting({ cursor: "motion" } as MediaTrackSettings)).toBe(
Expand Down
39 changes: 37 additions & 2 deletions src/hooks/useScreenRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ export function shouldUseLinuxPortalCapture({
);
}

export function shouldLockHudDuringDisplaySelection({
platform,
useLinuxPortal,
}: {
platform?: string;
useLinuxPortal: boolean;
}) {
return platform === "linux" && useLinuxPortal;
}

type UseScreenRecorderReturn = {
recording: boolean;
paused: boolean;
Expand Down Expand Up @@ -1429,6 +1439,16 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
return;
}

let hudSourceSelectionActive = false;
const setHudSourceSelectionActive = (active: boolean) => {
if (hudSourceSelectionActive === active) {
return;
}

hudSourceSelectionActive = active;
window.electronAPI?.hudOverlaySetSourceSelectionActive?.(active);
};

hasPromptedForReselect.current = false;
startInFlight.current = true;
setStarting(true);
Expand Down Expand Up @@ -1628,7 +1648,14 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
}

setRecording(true);
window.electronAPI?.setRecordingState(true);
try {
await window.electronAPI?.setRecordingState(true);
} catch (stateError) {
console.warn(
"Failed to notify main process that native recording started:",
stateError,
);
}

return;
}
Expand Down Expand Up @@ -1676,6 +1703,9 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
browserCaptureSourceId: browserCaptureSource.id,
selectedSourceId: selectedSource.id,
});
if (shouldLockHudDuringDisplaySelection({ platform, useLinuxPortal })) {
setHudSourceSelectionActive(true);
}
const browserScreenVideoConstraints = {
mandatory: {
chromeMediaSource: CHROME_MEDIA_SOURCE,
Expand Down Expand Up @@ -1990,7 +2020,11 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
webcamStartTime.current === null ? 0 : webcamStartTime.current - mainStartedAt;
recorder.start(RECORDER_TIMESLICE_MS);
setRecording(true);
window.electronAPI?.setRecordingState(true);
try {
await window.electronAPI?.setRecordingState(true);
} catch (stateError) {
console.warn("Failed to notify main process that recording started:", stateError);
}
} catch (error) {
console.error("Failed to start recording:", error);
alert(
Expand All @@ -2008,6 +2042,7 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
await stopWebcamRecorder();
}
} finally {
setHudSourceSelectionActive(false);
startInFlight.current = false;
setStarting(false);
}
Expand Down