fix(updates): ensure preferences are loaded from backend after login

initUpdatesStore() set its initialized flag before the async preference
fetch completed. If get_update_preferences failed (backend store not
yet ready), preferences stayed at defaults (both true) and were never
re-fetched. This caused:
- "Show What's New" toggle appearing enabled despite being disabled
- "Check for updates on launch" toggle not persisting
- Changelog modal reappearing on every restart

Changes:
- Split initialized flag into versionLoaded/prefsLoaded so preference
  loading retries until the backend store is ready
- Call refreshUpdatePreferences() in decideLaunchModals() to always
  get fresh data before making modal decisions
- Call refreshUpdatePreferences() in handleLoginSuccess() after
  session activation so SettingsView reflects saved values

cc
This commit is contained in:
vicrodh committed 2026-02-07 11:58:32 -06:00
1 parent 865e25e9b1
commit 28742fa19e
3 files changed
+27 -15

No files matched your search

+20 -15
View File
@@ -30,7 +30,8 @@ let preferences: UpdatePreferences = {
};
let currentVersion = '';
let initialized = false;
let versionLoaded = false;
let prefsLoaded = false;
const listeners = new Set<() => void>();
@@ -55,23 +56,27 @@ export function getCurrentVersion(): string {
}
export async function initUpdatesStore(): Promise<void> {
if (initialized) return;
initialized = true;
// get_current_version never needs a session (compile-time value).
// get_update_preferences needs the SQLite store which is only
// available after login. Fetch them independently so a preference
// failure doesn't lose the version.
try {
currentVersion = await invoke<string>('get_current_version');
} catch (error) {
console.error('[Updates] Failed to get current version:', error);
// Only fetch once.
if (!versionLoaded) {
try {
currentVersion = await invoke<string>('get_current_version');
versionLoaded = true;
} catch (error) {
console.error('[Updates] Failed to get current version:', error);
}
}
try {
preferences = await invoke<UpdatePreferences>('get_update_preferences');
} catch {
// Expected before login — store not initialised yet.
// get_update_preferences needs the SQLite store which is only
// available after login. Retry on each call until it succeeds,
// so a pre-login failure doesn't lock in stale defaults.
if (!prefsLoaded) {
try {
preferences = await invoke<UpdatePreferences>('get_update_preferences');
prefsLoaded = true;
} catch {
// Expected before login — store not initialised yet.
}
}
notify();