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): resolve scene assets outside the asar, so themes and wallpapers load
Etienne Lescotf2439829d6e5
diff --git a/electron/native-bridge/services/compositorViewService.test.ts b/electron/native-bridge/services/compositorViewService.test.tsindex 4e2f5bbde..c0b05038e 100644--- a/electron/native-bridge/services/compositorViewService.test.ts+++ b/electron/native-bridge/services/compositorViewService.test.ts@@ -2,7 +2,12 @@ import fs from "node:fs";import os from "node:os";import path from "node:path";import { afterEach, beforeEach, describe, expect, it } from "vitest";-import { CompositorViewService, ffmpegSharedBinCandidates } from "./compositorViewService";+import { CURSOR_THEMES } from "../../../src/lib/cursor/cursorThemes";+import {+ CompositorViewService,+ ffmpegSharedBinCandidates,+ resolveSceneAssetPaths,+} from "./compositorViewService";/** A source checkout's `poc-d3d/.cargo/config.toml`, with `FFMPEG_DIR` written as `body`. */function writeCargoConfig(root: string, body: string): void {@@ -172,3 +177,79 @@ describe("CompositorViewService ffmpeg PATH prepend", () => {expect(occurrences?.length).toBe(1);});});++describe("resolveSceneAssetPaths", () => {+ // A packaged install: `wallpapers/` and `cursors/` exist as real files under+ // resourcesPath (extraResources), while VITE_PUBLIC points into the asar, where+ // nothing is readable by the Rust addon — the exact layout that broke both features.+ let resources: string;+ let originalResourcesPath: PropertyDescriptor | undefined;+ let originalVitePublic: string | undefined;+ const themed = CURSOR_THEMES.find((t) => t.assets.arrow);++ beforeEach(() => {+ resources = fs.mkdtempSync(path.join(os.tmpdir(), "openscreen-scene-assets-"));+ fs.mkdirSync(path.join(resources, "wallpapers"), { recursive: true });+ fs.writeFileSync(path.join(resources, "wallpapers", "wallpaper1.jpg"), "jpg");+ if (themed?.assets.arrow) {+ const arrow = path.join(resources, themed.assets.arrow.assetPath);+ fs.mkdirSync(path.dirname(arrow), { recursive: true });+ fs.writeFileSync(arrow, "png");+ }+ originalResourcesPath = Object.getOwnPropertyDescriptor(process, "resourcesPath");+ Object.defineProperty(process, "resourcesPath", { value: resources, configurable: true });+ originalVitePublic = process.env.VITE_PUBLIC;+ // vite copies public/ into dist, so the names exist inside the archive — but the+ // archive is a file, so no candidate under it can ever pass an existence check.+ process.env.VITE_PUBLIC = path.join(resources, "app.asar", "dist");+ });++ afterEach(() => {+ if (originalResourcesPath) {+ Object.defineProperty(process, "resourcesPath", originalResourcesPath);+ }+ if (originalVitePublic === undefined) {+ delete process.env.VITE_PUBLIC;+ } else {+ process.env.VITE_PUBLIC = originalVitePublic;+ }+ fs.rmSync(resources, { recursive: true, force: true });+ });++ function resolved(scene: Record<string, unknown>) {+ return JSON.parse(resolveSceneAssetPaths(JSON.stringify(scene)));+ }++ it("resolves a bundled wallpaper to the extraResources copy, not the unreadable asar path", () => {+ const out = resolved({ background: { kind: "image", path: "/wallpapers/wallpaper1.jpg" } });++ expect(out.background.path).toBe(path.join(resources, "wallpapers", "wallpaper1.jpg"));+ expect(out.background.path).not.toContain("app.asar");+ expect(fs.existsSync(out.background.path)).toBe(true);+ });++ it("resolves a cursor theme's arrow sprite to a path that exists on disk", () => {+ if (!themed) return; // no bundled theme ships an arrow override+ const out = resolved({ cursor: { theme: themed.id } });++ expect(out.cursor.cursorSpritePath).toBe(path.join(resources, themed.assets.arrow!.assetPath));+ expect(fs.existsSync(out.cursor.cursorSpritePath)).toBe(true);+ });++ it("leaves a custom upload's data: URL untouched — the addon decodes it in memory", () => {+ const dataUrl = "data:image/png;base64,SGkh";+ const out = resolved({ background: { kind: "image", path: dataUrl } });++ expect(out.background.path).toBe(dataUrl);+ });++ it("nulls the sprite for the default theme so the built-in art is used", () => {+ expect(resolved({ cursor: { theme: "default" } }).cursor.cursorSpritePath).toBeNull();+ });++ it("leaves the scene alone when no base dir holds the asset", () => {+ const out = resolved({ background: { kind: "image", path: "/wallpapers/absent.jpg" } });++ expect(out.background.path).toBe("/wallpapers/absent.jpg");+ });+});diff --git a/electron/native-bridge/services/compositorViewService.ts b/electron/native-bridge/services/compositorViewService.tsindex 396207506..e9189db81 100644--- a/electron/native-bridge/services/compositorViewService.ts+++ b/electron/native-bridge/services/compositorViewService.ts@@ -33,25 +33,55 @@ const localRequire: NodeRequire = createRequire(import.meta.url) as unknown as N* schemes (data:, http:) are left as-is; the native side falls back to a flat* colour when it can't load them. Malformed JSON passes through untouched.*/-/** Absolute path of a theme's "arrow" sprite under `publicDir`, or null (unknown theme /- * default / theme ships no arrow override — same fallback the web renderer applies). */-function resolveCursorThemeArrowPath(themeId: string, publicDir: string): string | null {- if (!themeId || themeId === DEFAULT_CURSOR_THEME_ID) {- return null;+/**+ * Bases holding the `wallpapers/` and `cursors/` trees, most specific first.+ *+ * `VITE_PUBLIC` is right in dev (`<root>/public`) and WRONG when packaged, where it points at+ * `<resources>/app.asar/dist`: vite copies `public/` into `dist`, so the files are there — but+ * inside the asar archive. Only Electron's patched `fs` can read through an asar, and the+ * compositor is a Rust addon calling `image::open` on a raw OS path, so every themed cursor+ * sprite and every bundled wallpaper silently failed to load in an installed build. The cursor+ * fell back to its default art (a theme pick looked like it did nothing) and the background fell+ * back to a flat colour. A CUSTOM uploaded image kept working throughout, because it travels as a+ * `data:` URL the addon decodes in memory rather than a path — which is exactly the asymmetry that+ * pinned this down.+ *+ * `extraResources` copies both trees to `<resources>/{wallpapers,cursors}` as real files (see+ * electron-builder.json5, whose own "Asset layout contract" comment names this), so+ * `process.resourcesPath` is the packaged answer. Probing for existence rather than branching on+ * `app.isPackaged` keeps `--dir` staging builds and tests working too, and mirrors the+ * candidate-list idiom `ffmpegSharedBinCandidates` already uses below. Same base dir as+ * `ASSET_BASE_DIR` in electron/windows.ts, which resolves these two trees for the renderer.+ */+function sceneAssetBaseDirs(): string[] {+ return [process.env.VITE_PUBLIC, process.resourcesPath].filter(+ (dir): dir is string => typeof dir === "string" && dir.length > 0,+ );+}++/** First base under which `relativePath` actually exists, joined; null when none does (leave the+ * scene's own value alone rather than hand the addon a path we know is not there). */+export function resolveSceneAssetPath(relativePath: string): string | null {+ for (const base of sceneAssetBaseDirs()) {+ const candidate = path.join(base, relativePath);+ if (fs.existsSync(candidate)) {+ return candidate;+ }}- const theme = CURSOR_THEMES.find((t) => t.id === themeId);- const arrow = theme?.assets.arrow;- if (!arrow) {+ return null;+}++/** Absolute path of a theme's "arrow" sprite, or null (unknown theme / default / theme ships no+ * arrow override / asset missing — same fallback to built-in art the web renderer applies). */+function resolveCursorThemeArrowPath(themeId: string): string | null {+ if (!themeId || themeId === DEFAULT_CURSOR_THEME_ID) {return null;}- return path.join(publicDir, arrow.assetPath);+ const arrow = CURSOR_THEMES.find((t) => t.id === themeId)?.assets.arrow;+ return arrow ? resolveSceneAssetPath(arrow.assetPath) : null;}-function resolveSceneAssetPaths(sceneJson: string): string {- const publicDir = process.env.VITE_PUBLIC;- if (!publicDir) {- return sceneJson;- }+export function resolveSceneAssetPaths(sceneJson: string): string {try {const scene = JSON.parse(sceneJson) as {background?: { kind?: string; path?: string };@@ -60,12 +90,15 @@ function resolveSceneAssetPaths(sceneJson: string): string {let changed = false;const bg = scene.background;if (bg?.kind === "image" && typeof bg.path === "string" && bg.path.startsWith("/")) {- // strip the leading slash so path.join keeps it under publicDir- bg.path = path.join(publicDir, bg.path.replace(/^\/+/, ""));- changed = true;+ // strip the leading slash so path.join keeps it under the base dir+ const resolved = resolveSceneAssetPath(bg.path.replace(/^\/+/, ""));+ if (resolved) {+ bg.path = resolved;+ changed = true;+ }}if (scene.cursor && typeof scene.cursor.theme === "string") {- scene.cursor.cursorSpritePath = resolveCursorThemeArrowPath(scene.cursor.theme, publicDir);+ scene.cursor.cursorSpritePath = resolveCursorThemeArrowPath(scene.cursor.theme);changed = true;}return changed ? JSON.stringify(scene) : sceneJson;