Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ function dataUriToArrayBuffer(dataUri: string): ArrayBuffer | null {
}

export async function getAllAudio(): Promise<Record<string, StoredAudioFile>> {
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<Record<string, string>> {
Expand Down
20 changes: 18 additions & 2 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,27 @@ function SettingsUI() {
const fileInputRef = React.useRef<HTMLInputElement>(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();
}, []);

Expand Down