From 49012353a6868ca555a56ec0556450d48af24f5a Mon Sep 17 00:00:00 2001 From: Stefan Wehrmeyer Date: Tue, 26 Dec 2023 20:47:25 +0000 Subject: [PATCH] Improve message typing --- src/reader.ts | 8 ++++---- src/sitebot.ts | 2 +- src/sourcebot.ts | 4 ++-- src/types.ts | 6 ++++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/reader.ts b/src/reader.ts index b23a169..a3dd378 100644 --- a/src/reader.ts +++ b/src/reader.ts @@ -69,7 +69,7 @@ class Reader { this.cleanUp() } - postMessage (message) { + postMessage (message: Message) { try { this.port.postMessage(message) } catch (e) { @@ -92,7 +92,7 @@ class Reader { this.sourceBot.run() } - botCallback (event) { + botCallback (event: Message) { if (event.type === STATUS_MESSAGE) { this.sendStatusMessage(event) } else if (event.type === FAILED_MESSAGE) { @@ -115,7 +115,7 @@ class Reader { } this.postMessage({ type: SUCCESS_MESSAGE, - content: event.message, + content: event.content, saveArticle: storageItems.saveArticle }) } @@ -123,7 +123,7 @@ class Reader { fail (event) { this.postMessage({ type: FAILED_MESSAGE, - content: event.message + message: event.message }) this.cleanUp() } diff --git a/src/sitebot.ts b/src/sitebot.ts index 0ca6fbc..86482cf 100644 --- a/src/sitebot.ts +++ b/src/sitebot.ts @@ -150,7 +150,7 @@ class SiteBot implements SiteBotInterface { this.port.onDisconnect.removeListener(this.onDisconnect) } - onMessage (event) { + onMessage (event: Message) { console.log(LOG_NAME, event) if (event.type === ABORT_MESSAGE) { this.showPaywall() diff --git a/src/sourcebot.ts b/src/sourcebot.ts index 0564ebe..b185130 100644 --- a/src/sourcebot.ts +++ b/src/sourcebot.ts @@ -193,12 +193,12 @@ class SourceBot { } } - finalize (result) { + finalize (result: string) { this.done = true if (result.length > 0) { this.callback({ type: SUCCESS_MESSAGE, - message: result + content: result }) browser.tabs.remove(this.tabId) diff --git a/src/types.ts b/src/types.ts index 5ad3174..495472b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -124,11 +124,13 @@ export type GoToTabMessage = { export type StatusMessage = { type: 'status' message: string + action?: 'interaction_required' } export type SuccessMessage = { type: 'success' - message: string + content: string + saveArticle?: string | null } export type FailedMessage = { @@ -136,7 +138,7 @@ export type FailedMessage = { message: string } -export type Message = InitMessage | GoToTabMessage | StatusMessage | SuccessMessage | FailedMessage +export type Message = InitMessage | GoToTabMessage | StatusMessage | SuccessMessage | FailedMessage | AbortMessage export type FillAction = { fill: {