fix: persist volume and tray settings across restarts

Volume was saved to per-user localStorage but loaded from unscoped key
before login set the userId. Added resyncPersistedVolume() called after
login to re-read from the correct scoped key.

Close/minimize to tray read settings once at startup from the flat-path
DB, but user changes were saved to per-user DB after login. Changed
close-to-tray to read dynamically from state, and minimize-to-tray to
re-fetch before each action.
This commit is contained in:
vicrodh committed 2026-02-10 06:23:05 -06:00
1 parent 3edfd165cb
commit 07f9f64a08
4 files changed
+35 -2

No files matched your search

+6
View File
@@ -43,6 +43,12 @@
});
async function handleMinimize() {
// Re-read setting to pick up per-user value after login
try {
const settings = await invoke<TraySettings>('get_tray_settings');
minimizeToTray = settings.minimize_to_tray;
} catch {}
if (minimizeToTray) {
await appWindow?.hide();
} else {
+18
View File
@@ -426,6 +426,22 @@ export async function seek(position: number): Promise<void> {
}
}
/**
* Re-read volume from localStorage after user-scoped storage becomes available.
* Called after login sets the userId, so getUserItem reads the correct scoped key.
*/
export async function resyncPersistedVolume(): Promise<void> {
const persistedVolume = loadPersistedVolume();
volume = persistedVolume;
notifyListeners();
try {
await invoke('set_volume', { volume: persistedVolume / 100 });
console.log('[Player] Resynced volume after login:', persistedVolume);
} catch {
console.debug('[Player] Could not resync volume to backend');
}
}
/**
* Set volume (0-100)
* Always persists the volume, even when nothing is playing.
@@ -692,6 +708,8 @@ export async function startPolling(): Promise<void> {
// Sync persisted volume to backend on startup
// This ensures the backend knows the saved volume before any playback starts
// Note: at this point userId may not be set yet, so the volume may come from
// the unscoped key. resyncPersistedVolume() is called after login to fix this.
const persistedVolume = loadPersistedVolume();
try {
await invoke('set_volume', { volume: persistedVolume / 100 });
+4
View File
@@ -149,6 +149,7 @@
reset as resetPlayer,
getPlayerState,
getVolume,
resyncPersistedVolume,
type PlayingTrack,
type PlayerState
} from '$lib/stores/playerStore';
@@ -2267,6 +2268,9 @@
migrateLocalStorage(info.userId);
}
// Re-sync volume from the now-correct user-scoped localStorage key
await resyncPersistedVolume();
// Activate per-user backend state (LoginView already did this for auto-login,
// but we call again to ensure it's active for manual login too — it's idempotent)
if (info.userId) {