From a70a9f5ac84af662e1127ce1f18415490b51ea3c Mon Sep 17 00:00:00 2001 From: Hauke D Date: Fri, 11 Oct 2024 20:33:11 +0000 Subject: [PATCH] Report to user if background dict update fails --- src/js/common.ts | 2 +- src/js/main.ts | 2 ++ src/workers/dict-load.ts | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/js/common.ts b/src/js/common.ts index 4d3ac81..fec30e5 100644 --- a/src/js/common.ts +++ b/src/js/common.ts @@ -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[] } diff --git a/src/js/main.ts b/src/js/main.ts index c123ea8..e538b78 100644 --- a/src/js/main.ts +++ b/src/js/main.ts @@ -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') { diff --git a/src/workers/dict-load.ts b/src/workers/dict-load.ts index a361bcc..dd1525d 100644 --- a/src/workers/dict-load.ts +++ b/src/workers/dict-load.ts @@ -186,7 +186,11 @@ export async function loadDict(target :string[]): Promise { 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)