aboutsummaryrefslogtreecommitdiff
path: root/ext/js/app/popup-window.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-12-29 19:17:46 -0500
committerGitHub <noreply@github.com>2023-12-30 00:17:46 +0000
commit7303da3991814a0ce220bf2fff3e51b968913b86 (patch)
tree809c289d824ec2a08c5ff54579766b7f5c5e09e1 /ext/js/app/popup-window.js
parent1b0e0c551d1505ed4242c04ebac224e5fff81f04 (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-window.js')
-rw-r--r--ext/js/app/popup-window.js34
1 files changed, 22 insertions, 12 deletions
diff --git a/ext/js/app/popup-window.js b/ext/js/app/popup-window.js
index 801afb3f..a696885a 100644
--- a/ext/js/app/popup-window.js
+++ b/ext/js/app/popup-window.js
@@ -126,7 +126,7 @@ export class PopupWindow extends EventDispatcher {
* @returns {Promise<void>}
*/
async setOptionsContext(optionsContext) {
- await this._invoke(false, 'displaySetOptionsContext', {id: this._id, optionsContext});
+ await this._invoke(false, 'displaySetOptionsContext', {optionsContext});
}
/**
@@ -183,7 +183,7 @@ export class PopupWindow extends EventDispatcher {
*/
async showContent(_details, displayDetails) {
if (displayDetails === null) { return; }
- await this._invoke(true, 'displaySetContent', {id: this._id, details: displayDetails});
+ await this._invoke(true, 'displaySetContent', {details: displayDetails});
}
/**
@@ -192,7 +192,7 @@ export class PopupWindow extends EventDispatcher {
* @returns {Promise<void>}
*/
async setCustomCss(css) {
- await this._invoke(false, 'displaySetCustomCss', {id: this._id, css});
+ await this._invoke(false, 'displaySetCustomCss', {css});
}
/**
@@ -200,7 +200,7 @@ export class PopupWindow extends EventDispatcher {
* @returns {Promise<void>}
*/
async clearAutoPlayTimer() {
- await this._invoke(false, 'displayAudioClearAutoPlayTimer', {id: this._id});
+ await this._invoke(false, 'displayAudioClearAutoPlayTimer', void 0);
}
/**
@@ -266,24 +266,29 @@ export class PopupWindow extends EventDispatcher {
// Private
- // TODO : Type safety
/**
- * @template {import('core').SerializableObject} TParams
- * @template [TReturn=unknown]
+ * @template {import('display').DirectApiNames} TName
* @param {boolean} open
- * @param {string} action
- * @param {TParams} params
- * @returns {Promise<TReturn|undefined>}
+ * @param {TName} action
+ * @param {import('display').DirectApiParams<TName>} params
+ * @returns {Promise<import('display').DirectApiReturn<TName>|undefined>}
*/
async _invoke(open, action, params) {
if (yomitan.isExtensionUnloaded) {
return void 0;
}
+ const message = /** @type {import('display').DirectApiMessageAny} */ ({action, params});
+
const frameId = 0;
if (this._popupTabId !== null) {
try {
- return await yomitan.crossFrame.invokeTab(this._popupTabId, frameId, 'popupMessage', {action, params});
+ return /** @type {import('display').DirectApiReturn<TName>} */ (await yomitan.crossFrame.invokeTab(
+ this._popupTabId,
+ frameId,
+ 'displayPopupMessage2',
+ message
+ ));
} catch (e) {
if (yomitan.isExtensionUnloaded) {
open = false;
@@ -299,6 +304,11 @@ export class PopupWindow extends EventDispatcher {
const {tabId} = await yomitan.api.getOrCreateSearchPopup({focus: 'ifCreated'});
this._popupTabId = tabId;
- return await yomitan.crossFrame.invokeTab(this._popupTabId, frameId, 'popupMessage', {action, params});
+ return /** @type {import('display').DirectApiReturn<TName>} */ (await yomitan.crossFrame.invokeTab(
+ this._popupTabId,
+ frameId,
+ 'displayPopupMessage2',
+ message
+ ));
}
}