fix: purchases and verbose log toggles not persisting across restart
Both stores read getUserItem() at module load time when the userId is
still null, so they hit the unscoped localStorage key. After login,
writes go to the user-scoped key (qbz.{userId}.key) which is never
read back on the next restart.
Add rehydrate functions that re-read from localStorage after
setStorageUserId() + migrateLocalStorage() have run, matching the
existing resyncPersistedVolume() pattern.
Closes #113
This commit is contained in:
3 files changed
+27
-2
No files matched your search
@@ -116,6 +116,14 @@ export function isVerboseCaptureEnabled(): boolean {
|
||||
return verboseCapture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-read verbose capture preference from localStorage after setStorageUserId().
|
||||
* At module load time the userId is null, so getUserItem reads the wrong key.
|
||||
*/
|
||||
export function rehydrateVerboseCapture(): void {
|
||||
verboseCapture = getUserItem(VERBOSE_CAPTURE_KEY) === 'true';
|
||||
}
|
||||
|
||||
export function getConsoleLogs(): ConsoleEntry[] {
|
||||
return [...entries];
|
||||
}
|
||||
|
||||
@@ -4,6 +4,17 @@ import { getUserItem, setUserItem } from '$lib/utils/userStorage';
|
||||
const KEY_SHOW = 'qbz-show-purchases';
|
||||
let showPurchases = getUserItem(KEY_SHOW) === 'true';
|
||||
|
||||
/**
|
||||
* Re-read all values from localStorage after setStorageUserId() has been called.
|
||||
* At module load time the userId is null, so getUserItem reads the wrong (unscoped) key.
|
||||
* This must be called after login to pick up the correct user-scoped values.
|
||||
*/
|
||||
export function rehydratePurchasesStore(): void {
|
||||
showPurchases = getUserItem(KEY_SHOW) === 'true';
|
||||
hideUnavailable = getUserItem(KEY_HIDE_UNAVAILABLE) === 'true';
|
||||
hideDownloaded = getUserItem(KEY_HIDE_DOWNLOADED) === 'true';
|
||||
}
|
||||
|
||||
export function getShowPurchases(): boolean {
|
||||
return showPurchases;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
|
||||
|
||||
// Console log capture (must be early, before other imports log)
|
||||
import { initConsoleCapture } from '$lib/stores/consoleLogStore';
|
||||
import { initConsoleCapture, rehydrateVerboseCapture } from '$lib/stores/consoleLogStore';
|
||||
initConsoleCapture();
|
||||
|
||||
// Offline cache state management
|
||||
@@ -357,7 +357,7 @@
|
||||
import LinkResolverModal from '$lib/components/LinkResolverModal.svelte';
|
||||
import type { ReleaseInfo } from '$lib/stores/updatesStore';
|
||||
import { refreshUpdatePreferences, resetUpdatesStore } from '$lib/stores/updatesStore';
|
||||
import { getShowPurchases, setShowPurchases } from '$lib/stores/purchasesStore';
|
||||
import { getShowPurchases, setShowPurchases, rehydratePurchasesStore } from '$lib/stores/purchasesStore';
|
||||
import {
|
||||
decideLaunchModals,
|
||||
disableUpdateChecks,
|
||||
@@ -2564,6 +2564,12 @@
|
||||
// Set up per-user localStorage scoping and migrate old keys
|
||||
setStorageUserId(info.userId);
|
||||
migrateLocalStorage(info.userId);
|
||||
|
||||
// Re-read stores that were initialised at module-load (before userId was set)
|
||||
rehydratePurchasesStore();
|
||||
rehydrateVerboseCapture();
|
||||
showPurchases = getShowPurchases();
|
||||
|
||||
loadSystemNotificationsPreference();
|
||||
|
||||
// Re-sync volume from the now-correct user-scoped localStorage key
|
||||
|
||||
Reference in new issue
Block a user