You've already forked bilibili-subtitle
fix
This commit is contained in:
@@ -71,7 +71,7 @@ class ExtensionMessage {
|
||||
const id = crypto.randomUUID()
|
||||
const name = port.name
|
||||
const portMessageHandler = new Layer1Protocol<MessageData, MessageResult>(async (value: MessageData) => {
|
||||
// 初始化
|
||||
// 初始化消息
|
||||
if (value.method === '_init') {
|
||||
const type = value.params.type
|
||||
let tabId = value.params.tabId
|
||||
@@ -95,6 +95,7 @@ class ExtensionMessage {
|
||||
} as MessageResult
|
||||
}
|
||||
|
||||
// 处理消息
|
||||
return handler(value, portContext)
|
||||
}, port)
|
||||
const portContext: PortContext = {id, name, port, portMessageHandler, ready: false}
|
||||
|
@@ -8,15 +8,11 @@ class InjectMessage {
|
||||
methods?: {
|
||||
[key: string]: (params: any, context: MethodContext) => Promise<any>
|
||||
}
|
||||
// postMessageToApp?: (method: string, payload: PostMessagePayload) => Promise<PostMessageResponse>
|
||||
|
||||
debug = (...args: any[]) => {
|
||||
console.debug('[Inject Messaging]', ...args)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sendResponse No matter what is returned, this method will definitely be called.
|
||||
*/
|
||||
messageHandler = async (event: MessageData): Promise<MessageResult> => {
|
||||
this.debug(`${event.from} => `, JSON.stringify(event))
|
||||
|
||||
|
@@ -30,13 +30,6 @@ class Layer1Protocol<L1Req = any, L1Res = any> {
|
||||
this.handler = handler
|
||||
}
|
||||
|
||||
// init(type: 'inject' | 'app', tabId?: number) {
|
||||
// this.port.postMessage({
|
||||
// type,
|
||||
// tabId,
|
||||
// })
|
||||
// }
|
||||
|
||||
startListen() {
|
||||
// 持久监听 port.onMessage
|
||||
this.port.onMessage.addListener((msg: ReqMsg<L1Req, L1Res>) => {
|
||||
|
Reference in New Issue
Block a user