Appearance setting ("Light") reverts to "Automatic" on macOS after quitting via Cmd+Q — localStorage write lost, likely missing flushStorageData() before quit
Environment: macOS, draw.io Desktop v31.4.5, system appearance set to Dark
Steps to reproduce:
- Set system (macOS) appearance to Dark
- Launch draw.io Desktop,
Extras > Appearance > Light - Confirm the change took:
Extras > Configuration > Preferencesshows"darkMode": false - Quit the app with Cmd+Q
- Relaunch
Expected: app opens in Light mode, "darkMode": false persists.
Actual: app opens in Dark mode; Preferences now shows "darkMode": "auto" again, which resolves to Dark since the OS is in Dark mode.
Suspected root cause: mxSettings.save() (drawio's Settings.js) persists via localStorage.setItem(), which drawio Desktop backs with Electron's LevelDB-based Local Storage (app.getPath('userData')/Local Storage/leveldb, referenced in src/main/electron.js). That write is asynchronous. I checked src/main/electron.js in this repo and found no call to session.flushStorageData() anywhere — including in the before-quit handler (app.on('before-quit', ...) around line 1967, which on macOS just sets cmdQPressed before app.quit() fires via window-all-closed). Electron's own guidance (and prior reports elsewhere, e.g. asticode/go-astilectron#229) is that localStorage writes can be lost if the process exits before LevelDB flushes, unless flushStorageData() is called first. That matches this repro exactly: the setting is written correctly (confirmed via the in-app Preferences viewer) but doesn't survive a quit shortly after.
Suggested fix: call session.flushStorageData() (or the modern equivalent) in the before-quit/window-all-closed path before app.quit() completes.
Related but distinct existing issues (none mention the flush mechanism, so filing separately): #1362, #1540, #630, #1940
Source: jgraph/drawio-desktop