fix: persist auto-play setting
This commit is contained in:
@@ -3,6 +3,24 @@ import type { Particle } from "@/api/types";
|
||||
|
||||
type MediaParticle = Extract<Particle, { type: "media" }>;
|
||||
|
||||
const STORAGE_KEY = "llink:autoplay-muted";
|
||||
|
||||
function loadMuted(): boolean {
|
||||
try {
|
||||
return localStorage.getItem(STORAGE_KEY) === "true";
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function saveMuted(muted: boolean) {
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, String(muted));
|
||||
} catch {
|
||||
// Storage unavailable
|
||||
}
|
||||
}
|
||||
|
||||
interface AutoplayState {
|
||||
/** The media particle currently being autoplayed, null when idle */
|
||||
activeParticle: MediaParticle | null;
|
||||
@@ -21,7 +39,7 @@ interface AutoplayState {
|
||||
export const useAutoplayStore = create<AutoplayState>((set, get) => ({
|
||||
activeParticle: null,
|
||||
streamId: null,
|
||||
muted: false,
|
||||
muted: loadMuted(),
|
||||
play: (particle, streamId) => {
|
||||
if (get().muted) return;
|
||||
set({ activeParticle: particle, streamId });
|
||||
@@ -32,8 +50,10 @@ export const useAutoplayStore = create<AutoplayState>((set, get) => ({
|
||||
// If muting, also stop any current playback
|
||||
if (!wasMuted) {
|
||||
set({ muted: true, activeParticle: null, streamId: null });
|
||||
saveMuted(true);
|
||||
} else {
|
||||
set({ muted: false });
|
||||
saveMuted(false);
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user