Skip to content
Open
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
6 changes: 5 additions & 1 deletion electron/electron-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ interface Window {
switchToEditor: () => Promise<void>;
openSourceSelector: () => Promise<void>;
selectSource: (source: ProcessedDesktopSource) => Promise<ProcessedDesktopSource>;
showSourceHighlight: (source: ProcessedDesktopSource) => Promise<{ success: boolean }>;
showSourceHighlight: (
source: ProcessedDesktopSource,
options?: { activateWindow?: boolean },
) => Promise<{ success: boolean }>;
clearSourceHighlight: () => Promise<{ success: boolean }>;
getSelectedSource: () => Promise<ProcessedDesktopSource | null>;
onSelectedSourceChanged: (
callback: (source: ProcessedDesktopSource | null) => void,
Expand Down
50 changes: 50 additions & 0 deletions electron/ipc/cursor/bounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,39 @@ export function getWindowBoundsFromNativeSource(
return { x, y, width, height };
}

export function getVisibleWindowBoundsFromNativeSource(
source?: NativeMacWindowSource | null,
): WindowBounds | null {
if (!source || source.visible === false) {
return null;
}

const {
visibleX: x,
visibleY: y,
visibleWidth: width,
visibleHeight: height,
} = source;
if (
typeof x !== "number" ||
!Number.isFinite(x) ||
typeof y !== "number" ||
!Number.isFinite(y) ||
typeof width !== "number" ||
!Number.isFinite(width) ||
typeof height !== "number" ||
!Number.isFinite(height)
) {
return getWindowBoundsFromNativeSource(source);
}

if (width <= 0 || height <= 0) {
return null;
}

return { x, y, width, height };
}

export async function resolveMacWindowBounds(source: SelectedSource): Promise<WindowBounds | null> {
const windowId = parseWindowId(source.id);
if (!windowId) {
Expand All @@ -101,6 +134,23 @@ export async function resolveMacWindowBounds(source: SelectedSource): Promise<Wi
}
}

export async function resolveMacWindowVisibleBounds(
source: SelectedSource,
): Promise<WindowBounds | null> {
const windowId = parseWindowId(source.id);
if (!windowId) {
return null;
}

try {
const nativeSources = await getNativeMacWindowSources({ maxAgeMs: 0 });
const matchedSource = nativeSources.find((entry) => parseWindowId(entry.id) === windowId);
return getVisibleWindowBoundsFromNativeSource(matchedSource);
} catch {
return null;
}
}

export function parseXwininfoBounds(stdout: string): WindowBounds | null {
const absX = stdout.match(/Absolute upper-left X:\s+(-?\d+)/);
const absY = stdout.match(/Absolute upper-left Y:\s+(-?\d+)/);
Expand Down
27 changes: 21 additions & 6 deletions electron/ipc/paths/binaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import fs from "node:fs/promises";
import path from "node:path";
import { promisify } from "node:util";
import { app } from "electron";
import {
nativeHelperMigrationPromise,
setNativeHelperMigrationPromise,
} from "../state";
import { nativeHelperMigrationPromise, setNativeHelperMigrationPromise } from "../state";

const execFileAsync = promisify(execFile);

Expand Down Expand Up @@ -49,6 +46,20 @@ export function getPrebundledNativeHelperPath(binaryName: string): string {
return resolveUnpackedAppPath("electron", "native", "bin", getNativeArchTag(), binaryName);
}

function getWindowsNativeArchTag(): string {
return process.arch === "arm64" ? "win32-arm64" : "win32-x64";
}

function getPrebundledWindowsNativeHelperPath(binaryName: string): string {
return resolveUnpackedAppPath(
"electron",
"native",
"bin",
getWindowsNativeArchTag(),
binaryName,
);
}

export function resolvePreferredWindowsNativeHelperPath(
helperDirectory: string,
binaryName: string,
Expand All @@ -61,7 +72,7 @@ export function resolvePreferredWindowsNativeHelperPath(
"Release",
binaryName,
);
const prebundledPath = getPrebundledNativeHelperPath(binaryName);
const prebundledPath = getPrebundledWindowsNativeHelperPath(binaryName);

if (app.isPackaged && existsSync(prebundledPath)) {
return prebundledPath;
Expand Down Expand Up @@ -128,7 +139,11 @@ export function getCursorMonitorExePath(): string {
async function migrateLegacyNativeHelperBinaries(): Promise<void> {
const legacyToCurrentPaths: Array<[string, string]> = [
[
path.join(app.getPath("userData"), "native-tools", "openscreen-screencapturekit-helper"),
path.join(
app.getPath("userData"),
"native-tools",
"openscreen-screencapturekit-helper",
),
getNativeCaptureHelperBinaryPath(),
],
[
Expand Down
2 changes: 2 additions & 0 deletions electron/ipc/register/recording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
systemPreferences,
} from "electron";
import { showCursor } from "../../cursorHider";
import { clearSourceHighlightWindow } from "../../sourceHighlight";
import { getMonitorHandles } from "../monitorResolver";
import { ALLOW_RECORDLY_WINDOW_CAPTURE } from "../constants";
import { startWindowBoundsCapture, stopWindowBoundsCapture } from "../cursor/bounds";
Expand Down Expand Up @@ -1827,6 +1828,7 @@ export function registerRecordingHandlers(
startCursorSampling();
void startInteractionCapture();
} else {
clearSourceHighlightWindow();
setIsCursorCaptureActive(false);
stopCursorCapture();
stopInteractionCapture();
Expand Down
Loading