Skip to content

Commit b4008f5

Browse files
authored
Merge pull request #611 from webadderallorg/fix/webcam-hud-preview-bounds
fix(recording): preserve webcam preview HUD bounds
2 parents 7f7d51c + 46810c5 commit b4008f5

6 files changed

Lines changed: 84 additions & 2 deletions

File tree

‎electron/electron-env.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ interface Window {
208208
hudOverlayHide: () => void;
209209
hudOverlayClose: () => void;
210210
hudOverlayRendererReady: () => void;
211+
hudOverlaySetWebcamPreviewVisible: (visible: boolean) => void;
211212
getHudOverlayCaptureProtection: () => Promise<{ success: boolean; enabled: boolean }>;
212213
getHudOverlayMousePassthroughSupported: () => Promise<{
213214
success: boolean;

‎electron/hudOverlayBounds.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vitest";
33
import {
44
getHudOverlayWindowBounds,
55
resizeHudOverlayFallbackBounds,
6+
shouldExpandHudOverlayFallback,
67
} from "./hudOverlayBounds";
78

89
describe("getHudOverlayWindowBounds", () => {
@@ -143,3 +144,35 @@ describe("resizeHudOverlayFallbackBounds", () => {
143144
});
144145
});
145146
});
147+
148+
describe("shouldExpandHudOverlayFallback", () => {
149+
it("expands while recording only when the floating webcam preview is visible", () => {
150+
expect(
151+
shouldExpandHudOverlayFallback({
152+
fallbackExpanded: false,
153+
recordingActive: true,
154+
webcamPreviewVisible: true,
155+
}),
156+
).toBe(true);
157+
});
158+
159+
it("keeps the compact recording fallback when there is no webcam preview", () => {
160+
expect(
161+
shouldExpandHudOverlayFallback({
162+
fallbackExpanded: false,
163+
recordingActive: true,
164+
webcamPreviewVisible: false,
165+
}),
166+
).toBe(false);
167+
});
168+
169+
it("preserves manual fallback expansion outside recording", () => {
170+
expect(
171+
shouldExpandHudOverlayFallback({
172+
fallbackExpanded: true,
173+
recordingActive: false,
174+
webcamPreviewVisible: false,
175+
}),
176+
).toBe(true);
177+
});
178+
});

‎electron/hudOverlayBounds.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ export function getHudOverlayWindowBounds(
3838
};
3939
}
4040

41+
export function shouldExpandHudOverlayFallback({
42+
fallbackExpanded,
43+
recordingActive,
44+
webcamPreviewVisible,
45+
}: {
46+
fallbackExpanded: boolean;
47+
recordingActive: boolean;
48+
webcamPreviewVisible: boolean;
49+
}): boolean {
50+
return fallbackExpanded || (recordingActive && webcamPreviewVisible);
51+
}
52+
4153
export function resizeHudOverlayFallbackBounds(
4254
workArea: HudOverlayWorkArea,
4355
currentBounds: HudOverlayWorkArea,

‎electron/preload.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ contextBridge.exposeInMainWorld("electronAPI", {
179179
hudOverlayRendererReady: () => {
180180
ipcRenderer.send("hud-overlay-renderer-ready");
181181
},
182+
hudOverlaySetWebcamPreviewVisible: (visible: boolean) => {
183+
ipcRenderer.send("hud-overlay-set-webcam-preview-visible", visible);
184+
},
182185
getHudOverlayCaptureProtection: () => {
183186
return ipcRenderer.invoke("get-hud-overlay-capture-protection");
184187
},

‎electron/windows.ts‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import path from "node:path";
55
import { fileURLToPath } from "node:url";
66
import { app, BrowserWindow, ipcMain } from "electron";
77
import { USER_DATA_PATH } from "./appPaths";
8-
import { getHudOverlayWindowBounds, resizeHudOverlayFallbackBounds } from "./hudOverlayBounds";
8+
import {
9+
getHudOverlayWindowBounds,
10+
resizeHudOverlayFallbackBounds,
11+
shouldExpandHudOverlayFallback,
12+
} from "./hudOverlayBounds";
913
import { getPackagedRendererBaseUrl } from "./rendererServer";
1014

1115
const electronWindowsDir = path.dirname(fileURLToPath(import.meta.url));
@@ -29,6 +33,7 @@ let hudOverlayFallbackExpanded = false;
2933
let hudOverlayIgnoringMouse = true;
3034
let hudOverlayMouseReassertTimer: NodeJS.Timeout | null = null;
3135
let hudOverlayRecordingActive = false;
36+
let hudOverlayWebcamPreviewVisible = false;
3237
let countdownWindow: BrowserWindow | null = null;
3338
let updateToastWindow: BrowserWindow | null = null;
3439

@@ -189,10 +194,15 @@ function getHudOverlayDisplay() {
189194

190195
function getHudOverlayBounds() {
191196
const { workArea } = getHudOverlayDisplay();
197+
const fallbackExpanded = shouldExpandHudOverlayFallback({
198+
fallbackExpanded: hudOverlayFallbackExpanded,
199+
recordingActive: hudOverlayRecordingActive,
200+
webcamPreviewVisible: hudOverlayWebcamPreviewVisible,
201+
});
192202
return getHudOverlayWindowBounds(
193203
workArea,
194204
isHudOverlayMousePassthroughSupported() && !hudOverlayRecordingActive,
195-
hudOverlayFallbackExpanded,
205+
fallbackExpanded,
196206
);
197207
}
198208

@@ -393,6 +403,18 @@ ipcMain.handle("get-hud-overlay-mouse-passthrough-supported", () => {
393403
};
394404
});
395405

406+
ipcMain.on("hud-overlay-set-webcam-preview-visible", (_event, visible: boolean) => {
407+
const nextVisible = Boolean(visible);
408+
if (hudOverlayWebcamPreviewVisible === nextVisible) {
409+
return;
410+
}
411+
412+
hudOverlayWebcamPreviewVisible = nextVisible;
413+
if (hudOverlayRecordingActive) {
414+
applyHudOverlayBounds();
415+
}
416+
});
417+
396418
ipcMain.handle("set-hud-overlay-capture-protection", (_event, enabled: boolean) => {
397419
loadHudOverlayCaptureProtectionSetting();
398420
hudOverlayHiddenFromCapture = Boolean(enabled);
@@ -415,6 +437,7 @@ ipcMain.handle("set-hud-overlay-capture-protection", (_event, enabled: boolean)
415437
export function createHudOverlayWindow(): BrowserWindow {
416438
loadHudOverlayCaptureProtectionSetting();
417439
hudOverlayFallbackExpanded = false;
440+
hudOverlayWebcamPreviewVisible = false;
418441
const initialBounds = getHudOverlayBounds();
419442
let hasShownHudWindow = false;
420443

‎src/components/launch/LaunchWindow.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ function LaunchWindowContent() {
152152
hudOverlayMousePassthroughSupported,
153153
});
154154

155+
useEffect(() => {
156+
window.electronAPI?.hudOverlaySetWebcamPreviewVisible?.(showRecordingWebcamPreview);
157+
}, [showRecordingWebcamPreview]);
158+
159+
useEffect(() => {
160+
return () => {
161+
window.electronAPI?.hudOverlaySetWebcamPreviewVisible?.(false);
162+
};
163+
}, []);
164+
155165
const {
156166
recordingHudOffset,
157167
isHudDragging,

0 commit comments

Comments
 (0)