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:
1 parent
3edfd165cb
commit
07f9f64a08
4 files changed
+35
-2
No files matched your search
@@ -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 });
|
||||
|
||||
Reference in new issue
Block a user