From dfd42bad0b46845ad88d1fdc5fa82b4f03bab0f3 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 1 Feb 2024 10:00:59 -0500 Subject: Application refactor (#591) * Rename Yomitan class to Application, change initialization style * Rename file * Update init * Update config * Remove dead code --- ext/js/app/popup.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'ext/js/app/popup.js') diff --git a/ext/js/app/popup.js b/ext/js/app/popup.js index c741e8f1..08ff0661 100644 --- a/ext/js/app/popup.js +++ b/ext/js/app/popup.js @@ -24,7 +24,6 @@ import {ExtensionError} from '../core/extension-error.js'; import {deepEqual} from '../core/utilities.js'; import {DocumentUtil} from '../dom/document-util.js'; import {loadStyle} from '../dom/style-util.js'; -import {yomitan} from '../yomitan.js'; import {ThemeController} from './theme-controller.js'; /** @@ -37,12 +36,15 @@ export class Popup extends EventDispatcher { * @param {import('popup').PopupConstructorDetails} details The details used to construct the new instance. */ constructor({ + application, id, depth, frameId, childrenSupported }) { super(); + /** @type {import('../application.js').Application} */ + this._application = application; /** @type {string} */ this._id = id; /** @type {number} */ @@ -206,7 +208,7 @@ export class Popup extends EventDispatcher { this._frame.addEventListener('scroll', (e) => e.stopPropagation()); this._frame.addEventListener('load', this._onFrameLoad.bind(this)); this._visible.on('change', this._onVisibleChange.bind(this)); - yomitan.on('extensionUnloaded', this._onExtensionUnloaded.bind(this)); + this._application.on('extensionUnloaded', this._onExtensionUnloaded.bind(this)); this._onVisibleChange({value: this.isVisibleSync()}); this._themeController.prepare(); } @@ -362,7 +364,7 @@ export class Popup extends EventDispatcher { useWebExtensionApi = false; parentNode = this._shadow; } - const node = await loadStyle('yomitan-popup-outer-user-stylesheet', 'code', css, useWebExtensionApi, parentNode); + const node = await loadStyle(this._application, 'yomitan-popup-outer-user-stylesheet', 'code', css, useWebExtensionApi, parentNode); this.trigger('customOuterCssChanged', {node, useWebExtensionApi, inShadow}); } @@ -575,7 +577,7 @@ export class Popup extends EventDispatcher { useWebExtensionApi = false; parentNode = this._shadow; } - await loadStyle('yomitan-popup-outer-stylesheet', fileType, '/css/popup-outer.css', useWebExtensionApi, parentNode); + await loadStyle(this._application, 'yomitan-popup-outer-stylesheet', fileType, '/css/popup-outer.css', useWebExtensionApi, parentNode); } /** @@ -697,7 +699,7 @@ export class Popup extends EventDispatcher { /** @type {import('display').DirectApiMessage} */ const message = {action, params}; const wrappedMessage = this._frameClient.createMessage(message); - return /** @type {import('display').DirectApiReturn} */ (await yomitan.crossFrame.invoke( + return /** @type {import('display').DirectApiReturn} */ (await this._application.crossFrame.invoke( this._frameClient.frameId, 'displayPopupMessage1', /** @type {import('display').DirectApiFrameClientMessageAny} */ (wrappedMessage) @@ -714,7 +716,7 @@ export class Popup extends EventDispatcher { try { return await this._invoke(action, params); } catch (e) { - if (!yomitan.webExtension.unloaded) { throw e; } + if (!this._application.webExtension.unloaded) { throw e; } return void 0; } } @@ -1008,7 +1010,7 @@ export class Popup extends EventDispatcher { */ async _setOptionsContext(optionsContext) { this._optionsContext = optionsContext; - const options = await yomitan.api.optionsGet(optionsContext); + const options = await this._application.api.optionsGet(optionsContext); const {general} = options; this._themeController.theme = general.popupTheme; this._themeController.outerTheme = general.popupOuterTheme; -- cgit v1.2.3