Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(desktop): 20s delta-encoded splash so the reveal plays effectively once
Elian Doran03bc0bcf1e38
diff --git a/apps/desktop/electron-forge/setup-icon/generate/README.md b/apps/desktop/electron-forge/setup-icon/generate/README.mdindex c097db7e92..827f3cf545 100644--- a/apps/desktop/electron-forge/setup-icon/generate/README.md+++ b/apps/desktop/electron-forge/setup-icon/generate/README.md@@ -16,21 +16,41 @@ Run it on **Windows** so the wordmark renders in Segoe UI (the font is rasterize## How it works-- `splash.html` is a deterministic frame source: `window.renderFrame(i)` computes every element's- opacity/transform for frame `i` (no CSS animations), so output is reproducible. `?variant=nightly`- switches to the purple palette and shows the NIGHTLY badge.-- `generate.mts` steps through the timeline in headless Chromium (via the repo's `@playwright/test`),+- `splash.html` is a deterministic frame source: `window.renderFrame(t)` computes every element's+ opacity/transform at absolute time `t` seconds (no CSS animations), so output is reproducible.+ `window.SPLASH_TIMELINE` is the `[{ t, delay }]` frame schedule. `?variant=nightly` switches to the+ purple palette and shows the NIGHTLY badge.+- `generate.mts` walks the timeline in headless Chromium (via the repo's `@playwright/test`),screenshots each frame, and encodes an animated GIF with `gifenc` — no external binaries needed.+## Timeline++- The reveal plays once (0–1.5 s at 10 fps), then a steady tail pulses the dots out to 20 s at 5 fps.+ The GIF loops, so the reveal replays every ~20 s — long enough that a normal install finishes during+ the first pass and effectively sees it once. Adjust `REVEAL_DURATION` / `LOOP_DURATION` /+ `STEADY_FPS` in `splash.html`.+- **Keep the frame count modest.** Squirrel's `Update.exe` renders the GIF with `WpfAnimatedGif`,+ which pre-decodes *every* frame to a full-size (640×480) bitmap held in memory, in a **32-bit**+ process (verified: `electron-winstaller`'s vendored `Squirrel.exe` is x86). Memory scales with+ frame count, not file size — ~1.2 MiB per frame. The current 108 frames ≈ 127 MiB; a 100 s / 1000-+ frame GIF would be ~1.2 GiB and risks an OutOfMemoryException. The low-fps steady tail exists to+ hold the count down.++## Encoding++- Frames are **delta-encoded**: one global palette, and pixels unchanged from the previous frame are+ written as a transparent index over the kept canvas (`dispose: 1`). This shrinks the mostly-static+ steady tail to almost nothing (~140 KiB total). It saves file size only — not `Update.exe` memory,+ which re-expands every frame to full size regardless.+## Output contract-- 640 × 480, opaque white background (GIF transparency is 1-bit and would leave ragged edges over- the desktop), 36 frames at 100 ms (3.6 s loop), infinite loop, ≤ 128 colors per frame, ~250 KiB.+- 640 × 480, opaque white background (GIF transparency is used for delta frames, but frame 0 is a+ full opaque frame so the loop resets cleanly and there is no reliance on desktop show-through),+ 108 frames, ~20 s loop, infinite loop, 255-color global palette, ~140 KiB.- The mark and wordmark are drawn larger than strictly needed: Squirrel's `Update.exe` is notDPI-aware, so on a HiDPI display the window is bilinear-stretched by the display scale factor(e.g. 1.5×) and there is no way to signal density through a GIF. Bolder artwork survives thatstretch better — it cannot be made pixel-sharp from our side.- The leaf geometry and the nine stable fill colors are taken verbatim from the app icon(`icon-color.svg`); the nightly variant remaps each leaf to a purple ramp.-- The dot pulse cycle (1.2 s) divides the loop length evenly so the pulse is continuous across the- GIF loop point — keep that invariant if you change the timing.diff --git a/apps/desktop/electron-forge/setup-icon/generate/generate.mts b/apps/desktop/electron-forge/setup-icon/generate/generate.mtsindex 8a5150b87d..cafd7c9c05 100644--- a/apps/desktop/electron-forge/setup-icon/generate/generate.mts+++ b/apps/desktop/electron-forge/setup-icon/generate/generate.mts@@ -4,9 +4,14 @@** Run with: pnpm --filter desktop generate-setup-banners*- * Renders each frame deterministically via window.renderFrame(i) in headless+ * Renders each frame deterministically via window.renderFrame(t) in headless* Chromium, then encodes an animated GIF with gifenc. Run on Windows so the* wordmark renders in Segoe UI, which is what the installer audience sees.+ *+ * Frames are delta-encoded: a single global palette, and pixels unchanged from+ * the previous frame are written as a transparent index over the kept canvas+ * (dispose = 1). The static reveal costs full frames; the steady tail (only the+ * pulsing dots change) costs almost nothing, so the file stays small even at 20s.*/import { chromium, type Page } from "@playwright/test";import { writeFileSync } from "fs";@@ -23,7 +28,8 @@ const SPLASH_PAGE = pathToFileURL(path.join(SETUP_ICON_DIR, "generate", "splash.const WIDTH = 640;const HEIGHT = 480;-const MAX_COLORS = 128;+// One color slot is reserved for transparency, so quantize to 255 (not 256).+const PALETTE_COLORS = 255;const VARIANTS = [{ variant: "stable", fileName: "setup-banner.gif" },@@ -34,25 +40,66 @@ async function renderVariant(page: Page, variant: string): Promise<Buffer> {await page.goto(`${SPLASH_PAGE}?variant=${variant}`);const timeline = await page.evaluate(() => window.SPLASH_TIMELINE);- const gif = GIFEncoder();- for (let frame = 0; frame < timeline.totalFrames; frame++) {- await page.evaluate((f) => window.renderFrame(f), frame);- const screenshot = PNG.sync.read(await page.screenshot({ clip: { x: 0, y: 0, width: WIDTH, height: HEIGHT } }));- const rgba = new Uint8Array(screenshot.data.buffer, screenshot.data.byteOffset, screenshot.data.length);+ // Capture every frame's raw pixels up front; delta encoding needs to diff+ // consecutive frames and to build one palette covering all of them.+ const frames: Uint8Array[] = [];+ for (const { t } of timeline) {+ await page.evaluate((time) => window.renderFrame(time), t);+ const png = PNG.sync.read(await page.screenshot({ clip: { x: 0, y: 0, width: WIDTH, height: HEIGHT } }));+ frames.push(new Uint8Array(png.data.buffer, png.data.byteOffset, png.data.length).slice());+ }- const palette = quantize(rgba, MAX_COLORS);+ const palette = buildGlobalPalette(frames);+ const transparentIndex = palette.length; // 255: unused by applyPalette (0..254)++ const gif = GIFEncoder();+ let previous: Uint8Array | null = null;+ for (const [i, { delay }] of timeline.entries()) {+ const rgba = frames[i];const index = applyPalette(rgba, palette);+ if (previous) {+ for (let p = 0; p < index.length; p++) {+ const b = p * 4;+ if (rgba[b] === previous[b] && rgba[b + 1] === previous[b + 1] && rgba[b + 2] === previous[b + 2]) {+ index[p] = transparentIndex;+ }+ }+ }gif.writeFrame(index, WIDTH, HEIGHT, {- palette,- delay: 1000 / timeline.fps,+ palette: i === 0 ? palette : undefined, // global color table, written once+ first: i === 0,+ transparent: true,+ transparentIndex,+ dispose: 1, // keep the previous canvas so transparent pixels persist+ delay,repeat: 0 // loop forever});+ previous = rgba;}gif.finish();return Buffer.from(gif.bytes());}+// Builds one palette shared by every frame (required for cross-frame transparency).+// Sampling a handful of frames across the timeline captures the reveal's partial+// leaves plus the steady tail's dot-pulse tints without quantizing all ~110 frames.+function buildGlobalPalette(frames: Uint8Array[]): number[][] {+ const count = Math.min(frames.length, 6);+ const step = Math.max(1, Math.floor(frames.length / count));+ const sampled: Uint8Array[] = [];+ for (let i = 0; i < frames.length; i += step) {+ sampled.push(frames[i]);+ }+ const merged = new Uint8Array(sampled.reduce((n, f) => n + f.length, 0));+ let offset = 0;+ for (const frame of sampled) {+ merged.set(frame, offset);+ offset += frame.length;+ }+ return quantize(merged, PALETTE_COLORS);+}+const browser = await chromium.launch();try {const page = await browser.newPage({@@ -72,7 +119,7 @@ try {declare global {interface Window {- SPLASH_TIMELINE: { fps: number; totalFrames: number };- renderFrame: (frame: number) => void;+ SPLASH_TIMELINE: { t: number; delay: number }[];+ renderFrame: (t: number) => void;}}diff --git a/apps/desktop/electron-forge/setup-icon/generate/splash.html b/apps/desktop/electron-forge/setup-icon/generate/splash.htmlindex 06a0d5eadd..32781af05e 100644--- a/apps/desktop/electron-forge/setup-icon/generate/splash.html+++ b/apps/desktop/electron-forge/setup-icon/generate/splash.html@@ -106,10 +106,15 @@const params = new URLSearchParams(location.search);stage.classList.add(params.get("variant") === "nightly" ? "variant-nightly" : "variant-stable");- // Timeline (seconds). The loop is TOTAL_FRAMES / FPS long; DOT_CYCLE must divide- // it evenly so the pulse is continuous across the GIF loop point.- const FPS = 10;- const TOTAL_FRAMES = 36;+ // Timeline (all times in seconds). The reveal plays once at 10 fps, then a long+ // steady tail pulses at 5 fps out to LOOP_DURATION. The low-fps tail keeps the+ // frame COUNT down, which is what matters: Squirrel's Update.exe renders the GIF+ // with WpfAnimatedGif, which pre-decodes every frame to a full-size bitmap in a+ // 32-bit process — so memory scales with frame count, not file size.+ const REVEAL_DURATION = 1.5; // reveal phase, rendered at REVEAL_FPS+ const LOOP_DURATION = 20; // total GIF length before it loops+ const REVEAL_FPS = 10;+ const STEADY_FPS = 5;const LEAF_STARTS = { green: 0, orange: 0.25, red: 0.5 };const LEAF_DURATION = 0.4;const TEXT_START = 0.7;@@ -141,9 +146,8 @@leaf.style.transform = `scale(${scale}) rotate(${rotation}deg)`;}- function renderFrame(frame) {- const t = frame / FPS;-+ // Renders the whole composition at absolute time `t` (seconds).+ function renderFrame(t) {setLeaf(".leaf-green", t, LEAF_STARTS.green);setLeaf(".leaf-orange", t, LEAF_STARTS.orange);setLeaf(".leaf-red", t, LEAF_STARTS.red);@@ -164,11 +168,28 @@}}- window.SPLASH_TIMELINE = { fps: FPS, totalFrames: TOTAL_FRAMES };+ // Frame schedule: [{ t, delay }] where delay is the ms this frame is shown.+ function buildTimeline() {+ const frames = [];+ const revealStep = 1 / REVEAL_FPS;+ const steadyStep = 1 / STEADY_FPS;+ let t = 0;+ while (t < REVEAL_DURATION) {+ frames.push({ t, delay: revealStep * 1000 });+ t += revealStep;+ }+ while (t < LOOP_DURATION) {+ frames.push({ t, delay: steadyStep * 1000 });+ t += steadyStep;+ }+ return frames;+ }++ window.SPLASH_TIMELINE = buildTimeline();window.renderFrame = renderFrame;// When opened directly in a browser, show the settled state.- renderFrame(TOTAL_FRAMES - 1);+ renderFrame(LOOP_DURATION / 2);</script></body></html>diff --git a/apps/desktop/electron-forge/setup-icon/setup-banner-dev.gif b/apps/desktop/electron-forge/setup-icon/setup-banner-dev.gifindex 15cf270cfc..6846ae258a 100644Binary files a/apps/desktop/electron-forge/setup-icon/setup-banner-dev.gif and b/apps/desktop/electron-forge/setup-icon/setup-banner-dev.gif differdiff --git a/apps/desktop/electron-forge/setup-icon/setup-banner.gif b/apps/desktop/electron-forge/setup-icon/setup-banner.gifindex d41770ff42..a70fe312c0 100644Binary files a/apps/desktop/electron-forge/setup-icon/setup-banner.gif and b/apps/desktop/electron-forge/setup-icon/setup-banner.gif differ