Persist desktop settings to settings.json across releases#1191
Persist desktop settings to settings.json across releases#1191jamesx0416 wants to merge 1 commit intopingdotgg:mainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| appSettings: input.appSettings, | ||
| }; | ||
| const settingsPath = getSettingsPath(); | ||
| const tempPath = `${settingsPath}.tmp`; |
There was a problem hiding this comment.
🟢 Low src/main.ts:151
Using a fixed temp file name ${settingsPath}.tmp creates a race condition when concurrent calls to writeSettingsFile occur. If two IPC SET_SETTINGS_CHANNEL calls overlap, the second write can overwrite the temp file before the first rename, causing incorrect data to be persisted. The second call's rename may also fail with ENOENT if the first call already moved the file. Consider using a unique temp file name per call (e.g., with crypto.randomUUID() or Date.now()) to ensure atomic writes.
- const tempPath = `${settingsPath}.tmp`;
+ const tempPath = `${settingsPath}.tmp-${Date.now()}-${Crypto.randomBytes(4).toString('hex')}`;🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file apps/desktop/src/main.ts around line 151:
Using a fixed temp file name `${settingsPath}.tmp` creates a race condition when concurrent calls to `writeSettingsFile` occur. If two IPC `SET_SETTINGS_CHANNEL` calls overlap, the second write can overwrite the temp file before the first rename, causing incorrect data to be persisted. The second call's rename may also fail with ENOENT if the first call already moved the file. Consider using a unique temp file name per call (e.g., with `crypto.randomUUID()` or `Date.now()`) to ensure atomic writes.
Evidence trail:
apps/desktop/src/main.ts lines 141-156 at REVIEWED_COMMIT:
- Line 151: `const tempPath = `${settingsPath}.tmp`;` confirms fixed temp file name
- Line 153: `await FS.promises.writeFile(tempPath, ...)` writes to temp
- Line 154: `await FS.promises.rename(tempPath, settingsPath);` renames temp to final
- No locking mechanism present in the async function
What Changed
settings.jsonin the desktop state directoryinitialSettingssnapshot from preload so the renderer can read desktop settings before routes and hooks initializesettings.jsonfirst on desktopsettings.jsonsettings.jsonWhy
Packaged desktop builds were still effectively depending on Chromium localStorage in the Electron profile, which made preferences unreliable across release builds and caused startup-order issues where settings were only reflected after more of the app mounted.
This change gives desktop a stable, versioned
settings.jsonsource of truth and makes startup deterministic:settings.jsonfirstThat fixes the desktop persistence bug without changing browser-only behavior.
UI Changes
None.
Checklist
Note
Persist desktop settings to settings.json across app releases
settings.jsonfile to store desktop settings (theme and app settings) across releases, using atomic writes with a temp file and rename.hydrateDesktopSettingsbefore rendering, loading persisted settings from disk and mirroring them to localStorage with storage change events.window.desktopBridge.setSettings.DesktopSettings,DesktopSettingsInput,AppSettings) are defined in a new packages/contracts/src/settings.ts module using Effect Schema, andDesktopBridgeis extended withinitialSettingsandsetSettings.📊 Macroscope summarized 4eae069. 10 files reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted
🗂️ Filtered Issues