Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(compositor-view): actually find the addon, unpackaged and packaged
Etienne Lescotafebff161de4
diff --git a/electron/native-bridge/services/compositorViewService.test.ts b/electron/native-bridge/services/compositorViewService.test.tsindex 297d3f5ef..0c04e7bc1 100644--- a/electron/native-bridge/services/compositorViewService.test.ts+++ b/electron/native-bridge/services/compositorViewService.test.ts@@ -4,6 +4,7 @@ import path from "node:path";import { afterEach, beforeEach, describe, expect, it } from "vitest";import { CURSOR_THEMES, DEFAULT_CURSOR_SPRITES } from "../../../src/lib/cursor/cursorThemes";import {+ buildCandidatePaths,CompositorViewService,ffmpegSharedBinCandidates,resolveSceneAssetPaths,@@ -100,6 +101,75 @@ describe("ffmpegSharedBinCandidates", () => {});});+describe("buildCandidatePaths", () => {+ let tmpRoot: string;++ beforeEach(() => {+ tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openscreen-addon-path-test-"));+ });++ afterEach(() => {+ fs.rmSync(tmpRoot, { recursive: true, force: true });+ });++ const norm = (p: string) => p.replace(/\\/g, "/");++ it("finds the addon from dist-electron, which is what app.getAppPath() returns unpackaged", () => {+ // The regression this exists for: `electron dist-electron/main.js` — the entry+ // `npm run dev` uses — makes app.getAppPath() the dist-electron DIRECTORY, not+ // the checkout root. Every candidate was built by joining "electron/native/..."+ // onto it, so none of them existed and the editor ran with a no-op compositor+ // on a machine that had a perfectly good addon one level up.+ fs.mkdirSync(path.join(tmpRoot, "electron", "native", "bin"), { recursive: true });+ const appRoot = path.join(tmpRoot, "dist-electron");+ fs.mkdirSync(appRoot, { recursive: true });++ const candidates = buildCandidatePaths(appRoot, false, null).map(norm);++ expect(+ candidates.some((c) => c.startsWith(norm(tmpRoot)) && !c.includes("dist-electron")),+ ).toBe(true);+ });++ it("stops walking up when no ancestor holds electron/native", () => {+ const appRoot = path.join(tmpRoot, "nothing", "here");+ fs.mkdirSync(appRoot, { recursive: true });++ const candidates = buildCandidatePaths(appRoot, false, null).map(norm);++ expect(candidates.every((c) => c.startsWith(norm(appRoot)) || c.includes("resources"))).toBe(+ true,+ );+ });++ it("also probes process.resourcesPath, where extraResources actually puts the addon", () => {+ // electron-builder ships electron/native/bin/<tag>/** through extraResources,+ // so in a packaged build the addon is at <resources>/electron/native/bin/<tag>+ // and NEVER inside app.asar — the .asar → .asar.unpacked rewrite cannot reach a+ // file that was never in the archive.+ const original = process.resourcesPath;+ Object.defineProperty(process, "resourcesPath", {+ value: "/fake/resources",+ configurable: true,+ });+ try {+ const candidates = buildCandidatePaths("/fake/resources/app.asar", true, null).map(norm);+ expect(+ candidates.some(+ (c) => c.startsWith("/fake/resources/electron/native/bin/") && c.endsWith(".node"),+ ),+ ).toBe(true);+ } finally {+ Object.defineProperty(process, "resourcesPath", { value: original, configurable: true });+ }+ });++ it("keeps the env override first", () => {+ const candidates = buildCandidatePaths(tmpRoot, false, "/explicit/compositor_view.node");+ expect(norm(candidates[0]!)).toBe("/explicit/compositor_view.node");+ });+});+describe("CompositorViewService ffmpeg PATH prepend", () => {let tmpRoot: string;let originalPath: string | undefined;diff --git a/electron/native-bridge/services/compositorViewService.ts b/electron/native-bridge/services/compositorViewService.tsindex fd30d95d4..7400b4a6d 100644--- a/electron/native-bridge/services/compositorViewService.ts+++ b/electron/native-bridge/services/compositorViewService.ts@@ -185,28 +185,61 @@ function platformArchTag(): string {return process.arch === "arm64" ? `${platformPrefix}-arm64` : `${platformPrefix}-x64`;}-function buildCandidatePaths(+/**+ * Bases that may hold `electron/native/…`, most specific first.+ *+ * `appRoot` alone is not enough, and was not enough on either side of the packaged+ * line:+ *+ * - **Unpackaged.** `app.getAppPath()` resolves to the directory holding the entry+ * script, i.e. `<repo>/dist-electron` — the entry every dev run uses, `npm run dev`+ * included. Joining `electron/native/...` onto that gives+ * `<repo>/dist-electron/electron/native/...`, which no build step ever writes, so+ * the loader fell through to "addon not present; running as no-op" and the editor+ * silently ran without a compositor. Walking up to the first ancestor that actually+ * has an `electron/native` finds the checkout root.+ * - **Packaged.** `electron/native/bin/<tag>/**` ships exclusively through+ * `extraResources` (see electron-builder.json5's mac/win/linux blocks), so it lands+ * at `<resources>/electron/native/bin/<tag>` and is never inside `app.asar` — the+ * `.asar` → `.asar.unpacked` rewrite below cannot reach it either, since the file+ * was never in the archive. `process.resourcesPath` is the base that holds it.+ *+ * Same pair of bases `ffmpegSharedBinCandidates` already walks for the ffmpeg dir; the+ * addon needs it for exactly the same reason.+ */+function nativeAssetBaseDirs(appRoot: string): string[] {+ const bases = [appRoot];+ // Bounded walk: dist-electron → repo root is one level, but a nested layout could+ // be deeper. Stop at the filesystem root rather than looping.+ let dir = appRoot;+ for (let i = 0; i < 4; i += 1) {+ const parent = path.dirname(dir);+ if (parent === dir) {+ break;+ }+ dir = parent;+ if (fs.existsSync(path.join(dir, "electron", "native"))) {+ bases.push(dir);+ break;+ }+ }+ if (typeof process.resourcesPath === "string" && process.resourcesPath.length > 0) {+ bases.push(process.resourcesPath);+ }+ return bases;+}++export function buildCandidatePaths(appRoot: string,isPackaged: boolean,envOverride: string | null | undefined,): string[] {- const builtPath = path.join(- appRoot,- "electron",- "native",- "compositor-view",- "build",- "compositor_view.node",- );- const archBinPath = path.join(- appRoot,- "electron",- "native",- "bin",- platformArchTag(),- "compositor_view.node",- );- const ordered = [envOverride, archBinPath, builtPath].filter(+ const tag = platformArchTag();+ const perBase = nativeAssetBaseDirs(appRoot).flatMap((base) => [+ path.join(base, "electron", "native", "bin", tag, "compositor_view.node"),+ path.join(base, "electron", "native", "compositor-view", "build", "compositor_view.node"),+ ]);+ const ordered = [envOverride, ...perBase].filter((value): value is string => typeof value === "string" && value.length > 0,);if (!isPackaged) {