|
43 | 43 | else longBreakAlert = val; |
44 | 44 | } |
45 | 45 |
|
| 46 | + let workAlertError = $state<string | null>(null); |
| 47 | + let shortBreakAlertError = $state<string | null>(null); |
| 48 | + let longBreakAlertError = $state<string | null>(null); |
| 49 | +
|
| 50 | + function getError(id: CueKey): string | null { |
| 51 | + if (id === 'work_alert') return workAlertError; |
| 52 | + if (id === 'short_break_alert') return shortBreakAlertError; |
| 53 | + return longBreakAlertError; |
| 54 | + } |
| 55 | +
|
| 56 | + function setError(id: CueKey, val: string | null) { |
| 57 | + if (id === 'work_alert') workAlertError = val; |
| 58 | + else if (id === 'short_break_alert') shortBreakAlertError = val; |
| 59 | + else longBreakAlertError = val; |
| 60 | + } |
| 61 | +
|
46 | 62 | async function refreshAudioInfo() { |
47 | 63 | try { |
48 | 64 | const info: CustomAudioInfo = await getCustomAudioInfo(); |
|
76 | 92 | } |
77 | 93 |
|
78 | 94 | async function pickAudio(id: CueKey) { |
| 95 | + setError(id, null); |
79 | 96 | let path: string | null = null; |
80 | 97 | try { |
81 | 98 | path = await openAudioFilePicker(); |
|
87 | 104 | try { |
88 | 105 | const displayName = await setCustomAudio(id, path); |
89 | 106 | setFileName(id, displayName); |
| 107 | + setError(id, null); |
90 | 108 | } catch (err) { |
91 | 109 | await logError(`[audio] setCustomAudio failed: ${err}`); |
| 110 | + setError(id, String(err)); |
92 | 111 | } |
93 | 112 | } |
94 | 113 |
|
95 | 114 | async function restoreAudio(id: CueKey) { |
96 | 115 | try { |
97 | 116 | await clearCustomAudio(id); |
98 | 117 | setFileName(id, null); |
| 118 | + setError(id, null); |
99 | 119 | } catch (err) { |
100 | 120 | await logError(`[audio] clearCustomAudio failed: ${err}`); |
101 | 121 | } |
|
122 | 142 | <button class="btn-choose" onclick={() => pickAudio(id)}>{m.notif_btn_choose()}</button> |
123 | 143 | </div> |
124 | 144 | </div> |
| 145 | + {#if getError(id)} |
| 146 | + <p class="audio-error">{getError(id)}</p> |
| 147 | + {/if} |
125 | 148 | {/each} |
126 | 149 |
|
127 | 150 | <div class="group-heading">{m.notif_group_desktop()}</div> |
|
324 | 347 | background: color-mix(in oklch, var(--color-foreground) 14%, transparent); |
325 | 348 | color: var(--color-foreground); |
326 | 349 | } |
| 350 | +
|
| 351 | + .audio-error { |
| 352 | + margin: 0; |
| 353 | + padding: 2px 20px 8px; |
| 354 | + font-size: 0.72rem; |
| 355 | + color: var(--color-danger, #e05252); |
| 356 | + font-family: monospace; |
| 357 | + } |
327 | 358 | </style> |
0 commit comments