From 5ba2b9fd6de99df56b4931da1ab83a74c717f4b3 Mon Sep 17 00:00:00 2001 From: IndieKKY Date: Sun, 6 Oct 2024 19:22:01 +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/messaging/const.ts | 3 --- src/messaging/layer2/ExtensionMessaging.ts | 4 ++-- src/messaging/layer2/InjectMessaging.ts | 6 +++--- src/messaging/layer2/useMessaging.ts | 2 +- src/messaging/layer2/useMessagingService.ts | 2 +- src/messaging/messaging-typings.d.ts | 4 ++-- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/messaging/const.ts b/src/messaging/const.ts index 1389366..e4c24f0 100644 --- a/src/messaging/const.ts +++ b/src/messaging/const.ts @@ -12,8 +12,5 @@ export type L2ResMsg = { data?: L2Res } -export const MESSAGE_TO_EXTENSION_HANDSHAKE = '_handshake' -export const MESSAGE_TO_EXTENSION_ROUTE = '_route' - export const TAG_TARGET_INJECT = 'target:inject' export const TAG_TARGET_APP = 'target:app' diff --git a/src/messaging/layer2/ExtensionMessaging.ts b/src/messaging/layer2/ExtensionMessaging.ts index a4748db..3c0414a 100644 --- a/src/messaging/layer2/ExtensionMessaging.ts +++ b/src/messaging/layer2/ExtensionMessaging.ts @@ -27,7 +27,7 @@ class ExtensionMessaging) => { const innerMethods: L2MethodHandlers = { - HANDSHAKE: async (params, context: MethodContext, portContext: PortContext) => { + _HANDSHAKE: async (params, context: MethodContext, portContext: PortContext) => { const tags = params.tags let tabId = params.tabId @@ -44,7 +44,7 @@ class ExtensionMessaging { + _ROUTE: async (params, context: MethodContext) => { return this.broadcastMessageExact([context.tabId!], params.tags, params.method as any, params.params) }, } diff --git a/src/messaging/layer2/InjectMessaging.ts b/src/messaging/layer2/InjectMessaging.ts index 3408dd6..29e7cd7 100644 --- a/src/messaging/layer2/InjectMessaging.ts +++ b/src/messaging/layer2/InjectMessaging.ts @@ -1,5 +1,5 @@ import Layer1Protocol from '../layer1/Layer1Protocol' -import { L2ReqMsg, L2ResMsg, MESSAGE_TO_EXTENSION_HANDSHAKE, MESSAGE_TO_EXTENSION_ROUTE, TAG_TARGET_APP, TAG_TARGET_INJECT } from '../const' +import { L2ReqMsg, L2ResMsg, TAG_TARGET_APP, TAG_TARGET_INJECT } from '../const' class InjectMessaging { port?: chrome.runtime.Port @@ -69,7 +69,7 @@ class InjectMessaging(method: K, params?: Extract['params']): Promise['return']> => { - return this.sendExtension('ROUTE' as any, { + return this.sendExtension('_ROUTE' as any, { tags: [TAG_TARGET_APP], method, params, diff --git a/src/messaging/layer2/useMessaging.ts b/src/messaging/layer2/useMessaging.ts index eff66cb..0739b75 100644 --- a/src/messaging/layer2/useMessaging.ts +++ b/src/messaging/layer2/useMessaging.ts @@ -21,7 +21,7 @@ const useMessaging = (method: K, params?: Extract['params']): Promise['return']> => { - return await sendExtension('ROUTE' as any, { + return await sendExtension('_ROUTE' as any, { tags: [TAG_TARGET_INJECT], method, params: params ?? {}, diff --git a/src/messaging/layer2/useMessagingService.ts b/src/messaging/layer2/useMessagingService.ts index d5e2ec9..9fa3379 100644 --- a/src/messaging/layer2/useMessagingService.ts +++ b/src/messaging/layer2/useMessagingService.ts @@ -77,7 +77,7 @@ const useMessagingService = (methods?: { // 初始化 pmh.sendMessage({ from: 'app', - method: 'HANDSHAKE', + method: '_HANDSHAKE', params: { tabId, tags: [TAG_TARGET_APP], diff --git a/src/messaging/messaging-typings.d.ts b/src/messaging/messaging-typings.d.ts index b0da6fe..1e9683a 100644 --- a/src/messaging/messaging-typings.d.ts +++ b/src/messaging/messaging-typings.d.ts @@ -18,11 +18,11 @@ interface AppMessage extends Message { interface ExtensionHandshakeMessage extends ExtensionMessage<{ tabId?: number, tags: string[] }> { - method: 'HANDSHAKE'; + method: '_HANDSHAKE'; } interface ExtensionRouteMessage extends ExtensionMessage<{ tags: string[], method: string, params: any }> { - method: 'ROUTE'; + method: '_ROUTE'; } type MessagingExtensionMessages = ExtensionHandshakeMessage | ExtensionRouteMessage