diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2023-12-29 19:17:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-30 00:17:46 +0000 |
commit | 7303da3991814a0ce220bf2fff3e51b968913b86 (patch) | |
tree | 809c289d824ec2a08c5ff54579766b7f5c5e09e1 /ext/js/app/popup.js | |
parent | 1b0e0c551d1505ed4242c04ebac224e5fff81f04 (diff) |
Cross frame API safety (#491)
* Require error type
* Add TODOs
* Fix init
* Updates
* More type safety
* Fix incorrect API map
* Update type safety
* Updates
* Add API
* Update types
* Update types
* Updates
* Remove unused
* Restore types
* Update frame ancestry handler
* Simplify names
* Fix
* Remove old message handlers
Diffstat (limited to 'ext/js/app/popup.js')
-rw-r--r-- | ext/js/app/popup.js | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/ext/js/app/popup.js b/ext/js/app/popup.js index a8cdf1a6..0f7fbd87 100644 --- a/ext/js/app/popup.js +++ b/ext/js/app/popup.js @@ -316,7 +316,7 @@ export class Popup extends EventDispatcher { */ async clearAutoPlayTimer() { if (this._frameConnected) { - await this._invokeSafe('displayAudioClearAutoPlayTimer', {}); + await this._invokeSafe('displayAudioClearAutoPlayTimer', void 0); } } @@ -679,13 +679,11 @@ export class Popup extends EventDispatcher { } } - // TODO : Type safety /** - * @template {import('core').SerializableObject} TParams - * @template [TReturn=unknown] - * @param {string} action - * @param {TParams} params - * @returns {Promise<TReturn>} + * @template {import('display').DirectApiNames} TName + * @param {TName} action + * @param {import('display').DirectApiParams<TName>} params + * @returns {Promise<import('display').DirectApiReturn<TName>>} */ async _invoke(action, params) { const contentWindow = this._frame.contentWindow; @@ -693,17 +691,21 @@ export class Popup extends EventDispatcher { throw new Error(`Failed to invoke action ${action}: frame state invalid`); } - const message = this._frameClient.createMessage({action, params}); - return await yomitan.crossFrame.invoke(this._frameClient.frameId, 'popupMessage', message); + /** @type {import('display').DirectApiMessage<TName>} */ + const message = {action, params}; + const wrappedMessage = this._frameClient.createMessage(message); + return /** @type {import('display').DirectApiReturn<TName>} */ (await yomitan.crossFrame.invoke( + this._frameClient.frameId, + 'displayPopupMessage1', + /** @type {import('display').DirectApiFrameClientMessageAny} */ (wrappedMessage) + )); } - // TODO : Type safety /** - * @template {import('core').SerializableObject} TParams - * @template [TReturn=unknown] - * @param {string} action - * @param {TParams} params - * @returns {Promise<TReturn|undefined>} + * @template {import('display').DirectApiNames} TName + * @param {TName} action + * @param {import('display').DirectApiParams<TName>} params + * @returns {Promise<import('display').DirectApiReturn<TName>|undefined>} */ async _invokeSafe(action, params) { try { |