diff --git a/audio.ts b/audio.ts index cb4425c..aa64b6e 100644 --- a/audio.ts +++ b/audio.ts @@ -195,7 +195,12 @@ function dataUriToArrayBuffer(dataUri: string): ArrayBuffer | null { } export async function getAllAudio(): Promise> { - return (await get(KEY)) ?? {}; + try { + return (await get(KEY)) ?? {}; + } catch (e) { + console.error("[CustomSounds] Failed to read audio store:", e); + return {}; + } } export async function getAudioMeta(): Promise> { diff --git a/index.tsx b/index.tsx index d1788e0..41eee3c 100644 --- a/index.tsx +++ b/index.tsx @@ -120,11 +120,27 @@ function SettingsUI() { const fileInputRef = React.useRef(null); const loadFiles = React.useCallback(async () => { - try { setFiles(await getAudioMeta()); } catch (e) { console.error("[CustomSounds]", e); } + try { + const meta = await getAudioMeta(); + setFiles(meta); + let healed = false; + for (const t of soundTypes) { + const o = getOverride(t.id); + if (o.selectedSound === "custom" && o.selectedFileId && !meta[o.selectedFileId]) { + o.selectedFileId = undefined; + o.selectedSound = "default"; + setOverride(t.id, o); + healed = true; + } + } + if (healed) setResetTrigger(t => t + 1); + } catch (e) { console.error("[CustomSounds]", e); } }, []); React.useEffect(() => { - soundTypes.forEach(t => { if (!settings.store[t.id]) setOverride(t.id, makeEmptyOverride()); }); + try { + soundTypes.forEach(t => { if (!settings.store[t.id]) setOverride(t.id, makeEmptyOverride()); }); + } catch (e) { console.error("[CustomSounds]", e); } loadFiles(); }, []);