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-proxy.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-proxy.js')
-rw-r--r-- | ext/js/app/popup-proxy.js | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/ext/js/app/popup-proxy.js b/ext/js/app/popup-proxy.js index 2821d774..e581be82 100644 --- a/ext/js/app/popup-proxy.js +++ b/ext/js/app/popup-proxy.js @@ -140,7 +140,7 @@ export class PopupProxy extends EventDispatcher { * @returns {Promise<void>} */ async setOptionsContext(optionsContext) { - await this._invokeSafe('PopupFactory.setOptionsContext', {id: this._id, optionsContext}, void 0); + await this._invokeSafe('popupFactorySetOptionsContext', {id: this._id, optionsContext}, void 0); } /** @@ -149,7 +149,7 @@ export class PopupProxy extends EventDispatcher { * @returns {Promise<void>} */ async hide(changeFocus) { - await this._invokeSafe('PopupFactory.hide', {id: this._id, changeFocus}, void 0); + await this._invokeSafe('popupFactoryHide', {id: this._id, changeFocus}, void 0); } /** @@ -157,7 +157,7 @@ export class PopupProxy extends EventDispatcher { * @returns {Promise<boolean>} `true` if the popup is visible, `false` otherwise. */ isVisible() { - return this._invokeSafe('PopupFactory.isVisible', {id: this._id}, false); + return this._invokeSafe('popupFactoryIsVisible', {id: this._id}, false); } /** @@ -168,7 +168,7 @@ export class PopupProxy extends EventDispatcher { * or null if the override wasn't assigned. */ setVisibleOverride(value, priority) { - return this._invokeSafe('PopupFactory.setVisibleOverride', {id: this._id, value, priority}, null); + return this._invokeSafe('popupFactorySetVisibleOverride', {id: this._id, value, priority}, null); } /** @@ -177,7 +177,7 @@ export class PopupProxy extends EventDispatcher { * @returns {Promise<boolean>} `true` if the override existed and was removed, `false` otherwise. */ clearVisibleOverride(token) { - return this._invokeSafe('PopupFactory.clearVisibleOverride', {id: this._id, token}, false); + return this._invokeSafe('popupFactoryClearVisibleOverride', {id: this._id, token}, false); } /** @@ -192,7 +192,7 @@ export class PopupProxy extends EventDispatcher { x += this._frameOffsetX; y += this._frameOffsetY; } - return await this._invokeSafe('PopupFactory.containsPoint', {id: this._id, x, y}, false); + return await this._invokeSafe('popupFactoryContainsPoint', {id: this._id, x, y}, false); } /** @@ -212,7 +212,7 @@ export class PopupProxy extends EventDispatcher { sourceRect.bottom += this._frameOffsetY; } } - await this._invokeSafe('PopupFactory.showContent', {id: this._id, details, displayDetails}, void 0); + await this._invokeSafe('popupFactoryShowContent', {id: this._id, details, displayDetails}, void 0); } /** @@ -221,7 +221,7 @@ export class PopupProxy extends EventDispatcher { * @returns {Promise<void>} */ async setCustomCss(css) { - await this._invokeSafe('PopupFactory.setCustomCss', {id: this._id, css}, void 0); + await this._invokeSafe('popupFactorySetCustomCss', {id: this._id, css}, void 0); } /** @@ -229,7 +229,7 @@ export class PopupProxy extends EventDispatcher { * @returns {Promise<void>} */ async clearAutoPlayTimer() { - await this._invokeSafe('PopupFactory.clearAutoPlayTimer', {id: this._id}, void 0); + await this._invokeSafe('popupFactoryClearAutoPlayTimer', {id: this._id}, void 0); } /** @@ -238,7 +238,7 @@ export class PopupProxy extends EventDispatcher { * @returns {Promise<void>} */ async setContentScale(scale) { - await this._invokeSafe('PopupFactory.setContentScale', {id: this._id, scale}, void 0); + await this._invokeSafe('popupFactorySetContentScale', {id: this._id, scale}, void 0); } /** @@ -254,7 +254,7 @@ export class PopupProxy extends EventDispatcher { * @returns {Promise<void>} */ async updateTheme() { - await this._invokeSafe('PopupFactory.updateTheme', {id: this._id}, void 0); + await this._invokeSafe('popupFactoryUpdateTheme', {id: this._id}, void 0); } /** @@ -265,7 +265,7 @@ export class PopupProxy extends EventDispatcher { * @returns {Promise<void>} */ async setCustomOuterCss(css, useWebExtensionApi) { - await this._invokeSafe('PopupFactory.setCustomOuterCss', {id: this._id, css, useWebExtensionApi}, void 0); + await this._invokeSafe('popupFactorySetCustomOuterCss', {id: this._id, css, useWebExtensionApi}, void 0); } /** @@ -282,7 +282,7 @@ export class PopupProxy extends EventDispatcher { * @returns {Promise<import('popup').ValidSize>} The size and whether or not it is valid. */ getFrameSize() { - return this._invokeSafe('PopupFactory.getFrameSize', {id: this._id}, {width: 0, height: 0, valid: false}); + return this._invokeSafe('popupFactoryGetFrameSize', {id: this._id}, {width: 0, height: 0, valid: false}); } /** @@ -292,32 +292,28 @@ export class PopupProxy extends EventDispatcher { * @returns {Promise<boolean>} `true` if the size assignment was successful, `false` otherwise. */ setFrameSize(width, height) { - return this._invokeSafe('PopupFactory.setFrameSize', {id: this._id, width, height}, false); + return this._invokeSafe('popupFactorySetFrameSize', {id: this._id, width, height}, false); } // Private - // TODO : Type safety /** - * @template {import('core').SerializableObject} TParams - * @template [TReturn=unknown] - * @param {string} action - * @param {TParams} params - * @returns {Promise<TReturn>} + * @template {import('cross-frame-api').ApiNames} TName + * @param {TName} action + * @param {import('cross-frame-api').ApiParams<TName>} params + * @returns {Promise<import('cross-frame-api').ApiReturn<TName>>} */ _invoke(action, params) { return yomitan.crossFrame.invoke(this._frameId, action, params); } - // TODO : Type safety /** - * @template {import('core').SerializableObject} TParams - * @template [TReturn=unknown] + * @template {import('cross-frame-api').ApiNames} TName * @template [TReturnDefault=unknown] - * @param {string} action - * @param {TParams} params + * @param {TName} action + * @param {import('cross-frame-api').ApiParams<TName>} params * @param {TReturnDefault} defaultReturnValue - * @returns {Promise<TReturn|TReturnDefault>} + * @returns {Promise<import('cross-frame-api').ApiReturn<TName>|TReturnDefault>} */ async _invokeSafe(action, params, defaultReturnValue) { try { |