Repository navigation
fix(desktop): keep the sign-in, settings and history through restarts, updates and version switches (1.2.3) - #27
Merged
Merged
Conversation
An update writes the new Statsify.exe at the old one's path, and Tauri's NSIS template never tells the shell, so Explorer keeps what it cached for that path and the desktop and Start menu shortcuts show a blank icon until clicked. Installer hooks (src-tauri/windows/installer-hooks.nsh) call SHChangeNotify(SHCNE_ASSOCCHANGED) at the end of the install section and again once the finish page has made the desktop shortcut. Checked by compiling Tauri 2.13's installer.nsi with the hooks in makensis, and in scripts/tauri-config.test.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
Settings, the Client ID, the sign-in, folders and pins lived only in the WebView's localStorage, which the WebView writes to disk a while after each change. Windows ends the app at once when it shuts down and when the installer updates it (tao answers WM_ENDSESSION with process::exit), so the next start could miss the latest writes (a refresh token Spotify had already replaced: signed out) or find the storage gone (no settings, no Client ID, no sign-in) while the history sat untouched in SQLite. Every write to a kept ss.* key now also goes to the shell, which writes app-state.json beside the history database atomically (new file, flushed, renamed; 0600 on macOS and Linux). On start-up, before the first render, the app puts back whatever the WebView lost; removals are kept too, so a lost sign-out can't sign anyone back in. A file it can't read is neither trusted nor overwritten. The developer log records only which keys were saved. Persisted stores and the other keys write through appStorage. Tests: Rust unit and IPC tests, keptState unit tests, and e2e/restart.spec.ts, which wipes the WebView's storage, rolls back a rotated refresh token and undoes a sign-out on the fake desktop (each fails without the fix). A refresh that can't reach Spotify, or that Spotify fails, keeps the sign-in (now tested). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
History and folders are kept per account, and the app only knew the account once Spotify answered /me. A PC that starts before its network does showed "can't reach Spotify" where the history on disk could have been. The sign-in now remembers its account (from /me answered in the same session, kept through refreshes), and the history, folders and import page use it until Spotify answers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
…save before the copy is read Switching to an older Statsify (which keeps no copy) and back could put the copy's older settings, or a refresh token Spotify had since replaced, back over what the older version saved. The copy now counts a generation with every write, and the app notes it in localStorage after each save: storage behind the copy lost writes and gets the copy back; storage level with it was changed by an older version, and the copy takes its values. A WebView holding none of Statsify's keys never gets to erase the copy. Nothing is saved until the copy has been read: a copy slow to answer at start-up no longer gets an emptied WebView's defaults written over it. The app shows after 3 s without it, keeps trying, and takes what it puts back when it answers. The fake desktop gets a generation and fault injection (slow, failing or hanging commands, across reloads) for the tests that follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
…sktop's faults Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
… copy - A copy that answers late (a slow disk at boot) no longer loses to what the app did on the stale storage meanwhile. Where the copy is ahead it wins over those changes too. A token refresh waits for the copy (up to 20 s), and retries with a newer refresh token of the same sign-in before signing out. A spent token can no longer sign the user out and erase the good one from the copy. - Save timing uses performance.now(): a clock set back at boot no longer holds saves (the sign-in's included) back by hours. - A restore before the first render takes the session without starting a new one, so "where songs stopped" isn't cleared and saved empty. A late restore puts restored values back after stores clear themselves. - Keys the shell would refuse, and values over 1 MB, stay in localStorage instead of failing every save. The marker is written only when the whole restore landed. A save the shell never answers times out after 15 s. main.tsx renders even if restoring throws. - The copy lives in the local data folder: on Windows the roaming one could carry one sign-in's tokens to another PC. A copy from a newer format is refused and left untouched. - The developer log lists the copy's keys, not its field names. The installer notifies Explorer without waiting for it (SHCNF_FLUSHNOWAIT). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
…t each release Updating from v1.0.0..v1.2.2, and switching to an older release and back (round-tripped with the real v1.2.2 build), keeps every setting, folder and the sign-in: - fix(storage): keep every persisted store whatever version saved it - fix(storage): a "__proto__" key in stored playlists or timings is just dropped - fix(storage): read back what localStorage refused, and never note it level with the copy - test(e2e): updating from v1.0.0 and v1.2.2, and switching to an older release and back - a restore that brings back another sign-in than the one the app started on starts a new session (per-account state reset), then puts the restored values back Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
Start-up awaited each read of app-state.json without a limit, so one read the shell never answered (an answer lost, a share or disk stuck for a while) left the copy unread for the whole session: nothing the user changed was saved to it, and a refresh had to wait out its limit. A read unanswered after 10 s is now asked again beside it, at most two at once, and whichever answers first counts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
When the saved copy answered after the app was on screen and turned out to be ahead of the WebView, it replaced every change made meanwhile. That keeps a sign-out forced by a spent refresh token from winning, but it also undid what the user did while waiting: a sign-out signed them back in, the demo they tried was left again, and a setting chosen on an emptied WebView was lost. A change now remembers what storage held under it. Where the copy still holds that value, the change was made on what the copy has, and it stands. Where the copy holds something newer, the copy wins as before, keeping the fields the change touched in a persisted store's value (with the store's defaults standing in for nothing). A WebView that kept its note but none of its keys is no longer taken as level with the copy because the app wrote something meanwhile, which erased the copy's keys. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
…rt comes up TanStack Query takes itself to be online when it starts and follows only the online and offline events after that. An app started without a network (a PC still connecting after it boots, Statsify starting with Windows) never heard the network come back, so every view that failed meanwhile waited for a click on Try again. The query layer now starts offline when the WebView says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
…aited After a restart that cost the WebView its sign-in, the landing page offers Connect Spotify. If the saved copy answered late while the browser was open, it put the sign-in back into storage, but a sign-in in progress doesn't follow the stored session; cancelling it then returned to "signed out", although storage (and the next start) had the sign-in. A desktop sign-in that is cancelled or fails now takes whatever session storage holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
…nd races The saved copy slow by 1, 5 and 30 s, failing then answering, never answering (once and for good); saving failing (disk full), slow and never answering; Spotify slow, offline at start, flapping; token refreshes that hang, are slow or fail with 5xx, 429, a revoked token or no network; /me failing while the remembered account opens the history; the recently-played sync failing; restart storms during slow saves; signing out, trying the demo and signing in while the copy is slow; an account switch while the history loads; double sign-ins; hiding the window and pagehide flushing; quick changes and an immediate restart. Each checks that nobody is signed out wrongly, nothing is reset or lost, and the page has no errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
…ocs for the fault and version work Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
…hone The demo history follows today's date, and on some dates a longer name with a longer "last played" date was cut off at 375 px (stats.spec.ts failed on main too). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
… and old files - fix(desktop): keep the history database whole through crashes, moves and odd files - fix(desktop): save a whole history in staged parts that land together - fix(history): say when the saved history can't be opened, is slow, or wasn't saved - test(desktop): kill the app mid-save and check what is left on disk - test(desktop): open history files exactly as every shipped version made them - fix(desktop): leave no half-written copies or oversized logs on a full disk - test(desktop): a damaged file put right opens without a restart; steadier kill and restart tests - fix(desktop): answer a staged rewrite's own outcome, whatever clearing up does A whole history over 50k plays now lands in one transaction (history_stage parts, then history_apply with staged), a save carries the history it was made from and is refused (history_changed) if the file holds something else, a -wal beside a missing database or from a newer version is left untouched, and the UI says when the history can't be opened instead of suggesting an import. Kill tests (tests/process_kill.rs) and files from every shipped schema. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
…clippy Rust 1.100's clippy refuses `for n in from..` (for_unbounded_range). The writers run until the test kills them; the bound only gives the loop an end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
CodeQL took a fictional fixture id in an assertion message for sensitive data
("cleartext logging"), going by the word "account" in its names.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TCk6t7edJdscNtTSeFmyQN
Kkkermit
force-pushed
the
feature/fix-lost-data
branch
from
December 5, 2026 02:21
d412ebc to
26f14a4
Compare
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.
What and why
On Windows, restarting the PC or updating Statsify could sign you out, reset your settings and Client ID, and make your history look gone. The history itself was never deleted (it lives in its own database), but with no sign-in and no Client ID it couldn't be shown.
The cause. Everything except the history lived only in the WebView's own storage, which writes to disk a while after each change. Windows ends the app abruptly when it shuts down, and the installer does the same when it updates (tao answers
WM_ENDSESSIONwithprocess::exit). So the WebView could lose:The fix. The desktop app now keeps a copy of its saved state (settings, Client ID, sign-in, folders and pins, lyrics timing, where songs stopped) in
app-state.json.The history database was attacked too, and these are fixed:
-walbeside a missing database is refused instead of deleted, along with the plays only it held.Also in this PR:
stats.spec.tsfailed onmainon some dates because of it.How it was tested
Four separate passes tried to break it: an independent code review, the history database, version switching, and faults and races. Every bug they found has a test that fails without its fix.
npm run checkpasses: typecheck, lint, 708 Vitest tests, build.npm run e2epasses on the desktop project, 514 passed and 0 failed. New specs:restart.spec.ts: the WebView losing everything, losing its latest writes, a lost sign-out, starting offline, a late copy, an older version and back.versions.spec.ts: updating from v1.0.0 and v1.2.2, and switching back and forth.storage-faults.spec.ts: a slow, failing or hung saved copy; slow or flaky networks; token endpoint errors; restart storms and sign-out races.database.spec.ts: a slow, failing, hung or corrupt database; failed saves and imports; reloads mid-import.cargo fmt --check,cargo clippy --all-targets -- -D warningsandcargo testpass. New:app_state.rsunit tests, plustests/app_state_ipc.rs;tests/process_kill.rs, which kills the app mid-save 40 times per scenario and checks the files hold exactly one finished save;-wal;Not tested on real Windows (this was all Linux, with a stand-in for the desktop app and real process kills): the WebView2 behaviour itself, NTFS file locking and the installer. Before merging, please:
Checklist
feature/<name>and the commits follow the commit style.npm run checkpasses (typecheck, lint, unit tests, build).npm run e2epasses, or the change can't affect the UI.cargo fmt --check,cargo clippy --all-targets -- -D warningsandcargo testpass insrc-tauri/.docs/,AGENTS.md) where behaviour, commands or architecture changed.Generated by Claude Code