diff options
Diffstat (limited to 'ext/js/comm')
-rw-r--r-- | ext/js/comm/api.js | 14 | ||||
-rw-r--r-- | ext/js/comm/frame-client.js | 8 | ||||
-rw-r--r-- | ext/js/comm/frame-endpoint.js | 4 |
3 files changed, 12 insertions, 14 deletions
diff --git a/ext/js/comm/api.js b/ext/js/comm/api.js index c2351538..423115f1 100644 --- a/ext/js/comm/api.js +++ b/ext/js/comm/api.js @@ -156,21 +156,19 @@ export class API { /** * @param {import('api').ApiParam<'sendMessageToFrame', 'frameId'>} frameId - * @param {import('api').ApiParam<'sendMessageToFrame', 'action'>} action - * @param {import('api').ApiParam<'sendMessageToFrame', 'params'>} [params] + * @param {import('api').ApiParam<'sendMessageToFrame', 'message'>} message * @returns {Promise<import('api').ApiReturn<'sendMessageToFrame'>>} */ - sendMessageToFrame(frameId, action, params) { - return this._invoke('sendMessageToFrame', {frameId, action, params}); + sendMessageToFrame(frameId, message) { + return this._invoke('sendMessageToFrame', {frameId, message}); } /** - * @param {import('api').ApiParam<'broadcastTab', 'action'>} action - * @param {import('api').ApiParam<'broadcastTab', 'params'>} params + * @param {import('api').ApiParam<'broadcastTab', 'message'>} message * @returns {Promise<import('api').ApiReturn<'broadcastTab'>>} */ - broadcastTab(action, params) { - return this._invoke('broadcastTab', {action, params}); + broadcastTab(message) { + return this._invoke('broadcastTab', {message}); } /** diff --git a/ext/js/comm/frame-client.js b/ext/js/comm/frame-client.js index 5e997622..cb591ca9 100644 --- a/ext/js/comm/frame-client.js +++ b/ext/js/comm/frame-client.js @@ -110,14 +110,14 @@ export class FrameClient { contentWindow.postMessage({action, params}, targetOrigin); }; - /** @type {import('extension').ChromeRuntimeOnMessageCallback<import('extension').ChromeRuntimeMessageWithFrameId>} */ + /** @type {import('extension').ChromeRuntimeOnMessageCallback<import('application').ApiMessageAny>} */ const onMessage = (message) => { onMessageInner(message); return false; }; /** - * @param {import('extension').ChromeRuntimeMessageWithFrameId} message + * @param {import('application').ApiMessageAny} message */ const onMessageInner = async (message) => { try { @@ -130,7 +130,7 @@ export class FrameClient { switch (action) { case 'frameEndpointReady': { - const {secret} = /** @type {import('frame-client').FrameEndpointReadyDetails} */ (params); + const {secret} = params; const token = generateId(16); tokenMap.set(secret, token); postMessage('frameEndpointConnect', {secret, token, hostFrameId}); @@ -138,7 +138,7 @@ export class FrameClient { break; case 'frameEndpointConnected': { - const {secret, token} = /** @type {import('frame-client').FrameEndpointConnectedDetails} */ (params); + const {secret, token} = params; const frameId = message.frameId; const token2 = tokenMap.get(secret); if (typeof token2 !== 'undefined' && token === token2 && typeof frameId === 'number') { diff --git a/ext/js/comm/frame-endpoint.js b/ext/js/comm/frame-endpoint.js index c338e143..4c5f58c1 100644 --- a/ext/js/comm/frame-endpoint.js +++ b/ext/js/comm/frame-endpoint.js @@ -41,7 +41,7 @@ export class FrameEndpoint { } /** @type {import('frame-client').FrameEndpointReadyDetails} */ const details = {secret: this._secret}; - yomitan.api.broadcastTab('frameEndpointReady', details); + yomitan.api.broadcastTab({action: 'frameEndpointReady', params: details}); } /** @@ -83,6 +83,6 @@ export class FrameEndpoint { this._eventListeners.removeAllEventListeners(); /** @type {import('frame-client').FrameEndpointConnectedDetails} */ const details = {secret, token}; - yomitan.api.sendMessageToFrame(hostFrameId, 'frameEndpointConnected', details); + yomitan.api.sendMessageToFrame(hostFrameId, {action: 'frameEndpointConnected', params: details}); } } |