feat: show window instantly with cached theme background#26
Merged
Conversation
Speed up perceived cold-start by showing the BrowserWindow as soon as it is
created instead of waiting for the renderer's first paint, and seed it with
the correct theme background so dark-theme users don't see a white flash.
- main.js: add startupBackground() helper that reads the cached bg from
userData/startup.json (validated against /^#[0-9a-fA-F]{3,8}$/), falling
back to the default theme bg (#f4f4f4). Window now uses explicit show: true
and backgroundColor: startupBackground().
- ipc.js: add app:setStartupBg handler that validates a hex color and writes
{ "bg": <color> } to userData/startup.json (try/catch, returns bool). Import
app from electron.
- preload.js: expose setStartupBg(color) on the m2scout bridge.
- themes.js: cache the current theme --bg via m2scout.setStartupBg on every
theme apply/init.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Speeds up the perceived cold-start of the app by showing the
BrowserWindowthe moment it is created — instead of waiting for the renderer to finish its
first paint — and seeds it with the correct theme background so dark-theme
users no longer see a white flash before the UI appears.
The window background color is read from a small cache (
startup.json) that therenderer writes every time a theme is applied, so the next cold start paints with
the right color immediately.
Changes
src/main/main.jsstartupBackground()helper readsuserData/startup.json→bg, validates against/^#[0-9a-fA-F]{3,8}$/, falls back to default theme bg#f4f4f4. Window now uses explicitshow: true+backgroundColor: startupBackground(). Wrapped intry/catchso first launch (no cache) never throws.src/main/ipc.jsapp:setStartupBghandler: validates hex color (same regex), writes{ "bg": <color> }touserData/startup.jsonviafs.writeFileSync, returnstrue/false. Fulltry/catch. Addedappto the electron import.src/preload/preload.jssetStartupBg: (color) => ipcRenderer.invoke('app:setStartupBg', color)on the existingm2scoutcontextBridge API.contextIsolation: true/nodeIntegration: falseunchanged.src/renderer/js/themes.jsapply(), after setting CSS variables, caches the currentvars['--bg']viawindow.m2scout.setStartupBg(...)(existence-checked +try/catch). Runs on every theme switch and oninit().How it works
--bgtouserData/startup.json.correct color immediately, then shows content as the renderer loads.
What this does NOT fix (by design / out of scope)
earlier; content fills in right after.
of
electron.execannot be removed by app code.npm start(electron .) is slower than runningnode_modules/electron/dist/electron.exedirectly (extra npm/node layer);a packaged asar build is typically fastest.
app.getPath('userData')may point to an app-name folder in dev mode; set andget use the same path, so it stays consistent.
Testing
node --checkon all four modified files → OK.npm test→ 5 pass / 0 fail.