Skip to content

Commit

Permalink
Report to user if background dict update fails
Browse files Browse the repository at this point in the history
  • Loading branch information
haukex committed Oct 11, 2024
1 parent 6467ab4 commit a70a9f5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/js/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export enum WorkerState {
/// Messages from the worker
export type WorkerMessageType =
{ type: 'dict-prog', percent :number }
| { type: 'dict-upd', status :'loading'|'done', dictLinesLen :number }
| { type: 'dict-upd', status :'loading'|'done'|'error', dictLinesLen :number }
| { type: 'worker-status', state :WorkerState, dictLinesLen :number, error ?:Error|unknown }
| { type: 'search-prog', percent :number }
| { type: 'results', what :string, whatPat :string, matches :string[] }
Expand Down
2 changes: 2 additions & 0 deletions src/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ window.addEventListener('DOMContentLoaded', async () => {
dictLinesLen = event.data.dictLinesLen
if (event.data.status === 'loading')
dict_upd_status.innerText = '(Updating in background...)'
else if (event.data.status === 'error')
dict_upd_status.innerText = '(Background dictionary update failed. Try reloading?)'
else {
dict_upd_status.innerText = ''
if (event.data.status === 'done') {
Expand Down
6 changes: 5 additions & 1 deletion src/workers/dict-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ export async function loadDict(target :string[]): Promise<void> {
postMessage(m)
commit()
}
catch (error) { console.warn('Failed to get dictionary update.', error) }
catch (error) {
console.warn('Failed to get dictionary update.', error)
const m :WorkerMessageType = { type: 'dict-upd', status: 'error', dictLinesLen: target.length }
postMessage(m)
}
}
else console.debug('Dictionary doesn\'t appear to need an update.')
}, 500)
Expand Down

0 comments on commit a70a9f5

Please sign in to comment.