From 0e4ae922451af967c78616057ed26b85ba5d4b5c Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 20 Feb 2024 10:12:27 -0500 Subject: Popup preview frame API map (#712) * Add API map type safety * Add API map types * Simplify names * Remove unused type --- ext/js/app/popup.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'ext/js/app') diff --git a/ext/js/app/popup.js b/ext/js/app/popup.js index 7a8b3f8c..4caf8241 100644 --- a/ext/js/app/popup.js +++ b/ext/js/app/popup.js @@ -722,22 +722,25 @@ export class Popup extends EventDispatcher { } /** - * @param {string} action - * @param {import('core').SerializableObject} params + * @template {import('display').WindowApiNames} TName + * @param {TName} action + * @param {import('display').WindowApiParams} params */ - _invokeWindow(action, params = {}) { + _invokeWindow(action, params) { const contentWindow = this._frame.contentWindow; if (this._frameClient === null || !this._frameClient.isConnected() || contentWindow === null) { return; } - const message = this._frameClient.createMessage({action, params}); - contentWindow.postMessage(message, this._targetOrigin); + /** @type {import('display').WindowApiMessage} */ + const message = {action, params}; + const messageWrapper = this._frameClient.createMessage(message); + contentWindow.postMessage(messageWrapper, this._targetOrigin); } /** * @returns {void} */ _onExtensionUnloaded() { - this._invokeWindow('displayExtensionUnloaded'); + this._invokeWindow('displayExtensionUnloaded', void 0); } /** -- cgit v1.2.3