aboutsummaryrefslogtreecommitdiff
path: root/ext/js/comm/api.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/comm/api.js')
-rw-r--r--ext/js/comm/api.js27
1 files changed, 11 insertions, 16 deletions
diff --git a/ext/js/comm/api.js b/ext/js/comm/api.js
index 50814aa2..2e1e8826 100644
--- a/ext/js/comm/api.js
+++ b/ext/js/comm/api.js
@@ -20,11 +20,11 @@ import {ExtensionError} from '../core/extension-error.js';
export class API {
/**
- * @param {import('../yomitan.js').Yomitan} yomitan
+ * @param {import('../extension/web-extension.js').WebExtension} webExtension
*/
- constructor(yomitan) {
- /** @type {import('../yomitan.js').Yomitan} */
- this._yomitan = yomitan;
+ constructor(webExtension) {
+ /** @type {import('../extension/web-extension.js').WebExtension} */
+ this._webExtension = webExtension;
}
/**
@@ -375,13 +375,15 @@ export class API {
const data = {action, params};
return new Promise((resolve, reject) => {
try {
- this._yomitan.sendMessage(data, (response) => {
- this._checkLastError(chrome.runtime.lastError);
+ this._webExtension.sendMessage(data, (response) => {
+ this._webExtension.getLastError();
if (response !== null && typeof response === 'object') {
- if (typeof response.error !== 'undefined') {
- reject(ExtensionError.deserialize(response.error));
+ const {error} = /** @type {import('core').UnknownObject} */ (response);
+ if (typeof error !== 'undefined') {
+ reject(ExtensionError.deserialize(/** @type {import('core').SerializedError} */ (error)));
} else {
- resolve(response.result);
+ const {result} = /** @type {import('core').UnknownObject} */ (response);
+ resolve(/** @type {import('api').ApiReturn<TAction>} */ (result));
}
} else {
const message = response === null ? 'Unexpected null response' : `Unexpected response of type ${typeof response}`;
@@ -393,11 +395,4 @@ export class API {
}
});
}
-
- /**
- * @param {chrome.runtime.LastError|undefined} _ignore
- */
- _checkLastError(_ignore) {
- // NOP
- }
}