From 02aaba6a836d75c7d311411bddd5c4c2c02e739c Mon Sep 17 00:00:00 2001 From: IndieKKY Date: Sun, 6 Oct 2024 18:41:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chrome/background.ts | 2 +- src/messaging/layer2/ExtensionMessaging.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/chrome/background.ts b/src/chrome/background.ts index 5cc3ca4..d074070 100644 --- a/src/chrome/background.ts +++ b/src/chrome/background.ts @@ -115,7 +115,7 @@ chrome.action.onClicked.addListener(async (tab) => { }) } else { closeSidePanel() - extensionMessaging.broadcastMessageExact([tab.id!], [TAG_TARGET_INJECT], MESSAGE_TO_INJECT_TOGGLE_DISPLAY).catch(console.error) + extensionMessaging.broadcastMessageExact([tab.id!], [TAG_TARGET_INJECT], 'TOGGLE_DISPLAY').catch(console.error) } }) }) diff --git a/src/messaging/layer2/ExtensionMessaging.ts b/src/messaging/layer2/ExtensionMessaging.ts index 34c1667..693ec4f 100644 --- a/src/messaging/layer2/ExtensionMessaging.ts +++ b/src/messaging/layer2/ExtensionMessaging.ts @@ -45,7 +45,7 @@ class ExtensionMessaging { portContext.ready = true }, ROUTE: async (params, context: MethodContext) => { - return this.broadcastMessageExact([context.tabId!], params.tags, params.method, params.params) + return this.broadcastMessageExact([context.tabId!], params.tags, params.method as any, params.params) }, } @@ -98,7 +98,7 @@ class ExtensionMessaging { //tags 如果为null,则不检查tags,如果为空数组,则不会发送消息 //返回:最后一个响应(因此如果只发送给一个tab,则返回的是该tab的响应) - broadcastMessageExact = async (tabIds: number[], tags: string[] | null, method: string, params?: any) => { + broadcastMessageExact = async (tabIds: number[], tags: string[] | null, method: K, params?: Extract['params']): Promise['return']> => { // 如果tags为空数组,则不会发送消息 if (tags != null && tags.length === 0) { return @@ -121,13 +121,13 @@ class ExtensionMessaging { return res?.data } - broadcastMessage = async (ignoreTabIds: number[] | undefined | null, tags: string[], method: string, params?: any) => { + broadcastMessage = async (ignoreTabIds: number[] | undefined | null, tags: string[], method: K, params?: Extract['params']): Promise['return']> => { const tabs = await chrome.tabs.query({ discarded: false, }) const tabIds: number[] = tabs.map(tab => tab.id).filter(tabId => tabId != null) as number[] const filteredTabIds: number[] = tabIds.filter(tabId => !ignoreTabIds?.includes(tabId)) - await this.broadcastMessageExact(filteredTabIds, tags, method, params) + return await this.broadcastMessageExact(filteredTabIds, tags, method, params) } }