summaryrefslogtreecommitdiff
path: root/ext/js/pages
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-02-01 10:00:59 -0500
committerGitHub <noreply@github.com>2024-02-01 15:00:59 +0000
commitdfd42bad0b46845ad88d1fdc5fa82b4f03bab0f3 (patch)
tree04686b943b84b33b8927238be17e4bc0dda7eb62 /ext/js/pages
parent2356223942a21d1683ac38eed8e7b9485f453d87 (diff)
Application refactor (#591)
* Rename Yomitan class to Application, change initialization style * Rename file * Update init * Update config * Remove dead code
Diffstat (limited to 'ext/js/pages')
-rw-r--r--ext/js/pages/action-popup-main.js34
-rw-r--r--ext/js/pages/info-main.js29
-rw-r--r--ext/js/pages/permissions-main.js18
-rw-r--r--ext/js/pages/settings/anki-controller.js5
-rw-r--r--ext/js/pages/settings/anki-templates-controller.js7
-rw-r--r--ext/js/pages/settings/backup-controller.js11
-rw-r--r--ext/js/pages/settings/collapsible-dictionary-controller.js3
-rw-r--r--ext/js/pages/settings/dictionary-controller.js7
-rw-r--r--ext/js/pages/settings/dictionary-import-controller.js7
-rw-r--r--ext/js/pages/settings/extension-keyboard-shortcuts-controller.js3
-rw-r--r--ext/js/pages/settings/keyboard-shortcuts-controller.js3
-rw-r--r--ext/js/pages/settings/mecab-controller.js10
-rw-r--r--ext/js/pages/settings/persistent-storage-controller.js15
-rw-r--r--ext/js/pages/settings/popup-preview-frame-main.js13
-rw-r--r--ext/js/pages/settings/popup-preview-frame.js11
-rw-r--r--ext/js/pages/settings/popup-window-controller.js11
-rw-r--r--ext/js/pages/settings/profile-controller.js3
-rw-r--r--ext/js/pages/settings/scan-inputs-controller.js3
-rw-r--r--ext/js/pages/settings/scan-inputs-simple-controller.js3
-rw-r--r--ext/js/pages/settings/secondary-search-dictionary-controller.js3
-rw-r--r--ext/js/pages/settings/settings-controller.js27
-rw-r--r--ext/js/pages/settings/settings-main.js13
-rw-r--r--ext/js/pages/settings/sort-frequency-dictionary-controller.js5
-rw-r--r--ext/js/pages/settings/storage-controller.js3
-rw-r--r--ext/js/pages/welcome-main.js17
25 files changed, 150 insertions, 114 deletions
diff --git a/ext/js/pages/action-popup-main.js b/ext/js/pages/action-popup-main.js
index 86201e83..6d2c85ab 100644
--- a/ext/js/pages/action-popup-main.js
+++ b/ext/js/pages/action-popup-main.js
@@ -16,13 +16,18 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+import {Application} from '../application.js';
import {getAllPermissions, hasRequiredPermissionsForOptions} from '../data/permissions-util.js';
import {querySelectorNotNull} from '../dom/query-selector.js';
import {HotkeyHelpController} from '../input/hotkey-help-controller.js';
-import {yomitan} from '../yomitan.js';
class DisplayController {
- constructor() {
+ /**
+ * @param {import('../comm/api.js').API} api
+ */
+ constructor(api) {
+ /** @type {import('../comm/api.js').API} */
+ this._api = api;
/** @type {?import('settings').Options} */
this._optionsFull = null;
}
@@ -36,7 +41,7 @@ class DisplayController {
this._setupButtonEvents('.action-open-search', 'openSearchPage', chrome.runtime.getURL('/search.html'), this._onSearchClick.bind(this));
this._setupButtonEvents('.action-open-info', 'openInfoPage', chrome.runtime.getURL('/info.html'));
- const optionsFull = await yomitan.api.optionsGetFull();
+ const optionsFull = await this._api.optionsGetFull();
this._optionsFull = optionsFull;
this._setupHotkeys();
@@ -108,7 +113,7 @@ class DisplayController {
const result = customHandler(e);
if (typeof result !== 'undefined') { return; }
}
- yomitan.api.commandExec(command, {mode: e.ctrlKey ? 'newTab' : 'existingOrNewTab'});
+ this._api.commandExec(command, {mode: e.ctrlKey ? 'newTab' : 'existingOrNewTab'});
e.preventDefault();
};
/**
@@ -116,7 +121,7 @@ class DisplayController {
*/
const onAuxClick = (e) => {
if (e.button !== 1) { return; }
- yomitan.api.commandExec(command, {mode: 'newTab'});
+ this._api.commandExec(command, {mode: 'newTab'});
e.preventDefault();
};
node.addEventListener('click', onClick, false);
@@ -180,7 +185,7 @@ class DisplayController {
*/
_setupOptions({options}) {
const extensionEnabled = options.general.enable;
- const onToggleChanged = () => yomitan.api.commandExec('toggleTextScanning');
+ const onToggleChanged = () => this._api.commandExec('toggleTextScanning');
for (const toggle of /** @type {NodeListOf<HTMLInputElement>} */ (document.querySelectorAll('#enable-search,#enable-search2'))) {
toggle.checked = extensionEnabled;
toggle.addEventListener('change', onToggleChanged, false);
@@ -192,7 +197,7 @@ class DisplayController {
/** */
async _setupHotkeys() {
const hotkeyHelpController = new HotkeyHelpController();
- await hotkeyHelpController.prepare();
+ await hotkeyHelpController.prepare(this._api);
const {profiles, profileCurrent} = /** @type {import('settings').Options} */ (this._optionsFull);
const primaryProfile = (profileCurrent >= 0 && profileCurrent < profiles.length) ? profiles[profileCurrent] : null;
@@ -250,7 +255,7 @@ class DisplayController {
scope: 'global',
optionsContext: null
};
- await yomitan.api.modifySettings([modification], 'action-popup');
+ await this._api.modifySettings([modification], 'action-popup');
}
/**
@@ -258,7 +263,7 @@ class DisplayController {
*/
async _updateDictionariesEnabledWarnings(options) {
const noDictionariesEnabledWarnings = /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('.no-dictionaries-enabled-warning'));
- const dictionaries = await yomitan.api.getDictionaryInfo();
+ const dictionaries = await this._api.getDictionaryInfo();
const enabledDictionaries = new Set();
for (const {name, enabled} of options.dictionaries) {
@@ -295,21 +300,22 @@ class DisplayController {
/** @returns {Promise<boolean>} */
async _isSafari() {
- const {browser} = await yomitan.api.getEnvironmentInfo();
+ const {browser} = await this._api.getEnvironmentInfo();
return browser === 'safari';
}
}
/** Entry point. */
async function main() {
- await yomitan.prepare();
+ const application = new Application();
+ await application.prepare();
- yomitan.api.logIndicatorClear();
+ application.api.logIndicatorClear();
- const displayController = new DisplayController();
+ const displayController = new DisplayController(application.api);
displayController.prepare();
- yomitan.ready();
+ application.ready();
}
await main();
diff --git a/ext/js/pages/info-main.js b/ext/js/pages/info-main.js
index dd55ab4b..ca5094b1 100644
--- a/ext/js/pages/info-main.js
+++ b/ext/js/pages/info-main.js
@@ -16,11 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+import {Application} from '../application.js';
import {log} from '../core/logger.js';
import {promiseTimeout} from '../core/utilities.js';
import {DocumentFocusController} from '../dom/document-focus-controller.js';
import {querySelectorNotNull} from '../dom/query-selector.js';
-import {yomitan} from '../yomitan.js';
import {BackupController} from './settings/backup-controller.js';
import {SettingsController} from './settings/settings-controller.js';
@@ -57,11 +57,13 @@ function getOperatingSystemDisplayName(os) {
}
}
-/** */
-async function showAnkiConnectInfo() {
+/**
+ * @param {import('../comm/api.js').API} api
+ */
+async function showAnkiConnectInfo(api) {
let ankiConnectVersion = null;
try {
- ankiConnectVersion = await yomitan.api.getAnkiConnectVersion();
+ ankiConnectVersion = await api.getAnkiConnectVersion();
} catch (e) {
// NOP
}
@@ -78,11 +80,13 @@ async function showAnkiConnectInfo() {
ankiVersionUnknownElement.hidden = (ankiConnectVersion !== null);
}
-/** */
-async function showDictionaryInfo() {
+/**
+ * @param {import('../comm/api.js').API} api
+ */
+async function showDictionaryInfo(api) {
let dictionaryInfos;
try {
- dictionaryInfos = await yomitan.api.getDictionaryInfo();
+ dictionaryInfos = await api.getDictionaryInfo();
} catch (e) {
return;
}
@@ -121,11 +125,12 @@ async function main() {
const manifest = chrome.runtime.getManifest();
const language = chrome.i18n.getUILanguage();
- await yomitan.prepare();
+ const application = new Application();
+ await application.prepare();
const {userAgent} = navigator;
const {name, version} = manifest;
- const {browser, platform: {os}} = await yomitan.api.getEnvironmentInfo();
+ const {browser, platform: {os}} = await application.api.getEnvironmentInfo();
/** @type {HTMLLinkElement} */
const thisVersionLink = querySelectorNotNull(document, '#release-notes-this-version-link');
@@ -149,10 +154,10 @@ async function main() {
languageElement.textContent = `${language}`;
userAgentElement.textContent = userAgent;
- showAnkiConnectInfo();
- showDictionaryInfo();
+ showAnkiConnectInfo(application.api);
+ showDictionaryInfo(application.api);
- const settingsController = new SettingsController();
+ const settingsController = new SettingsController(application);
await settingsController.prepare();
const backupController = new BackupController(settingsController, null);
diff --git a/ext/js/pages/permissions-main.js b/ext/js/pages/permissions-main.js
index 38135689..1659bea5 100644
--- a/ext/js/pages/permissions-main.js
+++ b/ext/js/pages/permissions-main.js
@@ -16,11 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+import {Application} from '../application.js';
import {log} from '../core/logger.js';
import {promiseTimeout} from '../core/utilities.js';
import {DocumentFocusController} from '../dom/document-focus-controller.js';
import {querySelectorNotNull} from '../dom/query-selector.js';
-import {yomitan} from '../yomitan.js';
import {ExtensionContentController} from './common/extension-content-controller.js';
import {ModalController} from './settings/modal-controller.js';
import {PermissionsOriginController} from './settings/permissions-origin-controller.js';
@@ -30,11 +30,11 @@ import {SettingsController} from './settings/settings-controller.js';
import {SettingsDisplayController} from './settings/settings-display-controller.js';
/**
- * @returns {Promise<void>}
+ * @param {import('../comm/api.js').API} api
*/
-async function setupEnvironmentInfo() {
+async function setupEnvironmentInfo(api) {
const {manifest_version: manifestVersion} = chrome.runtime.getManifest();
- const {browser, platform} = await yomitan.api.getEnvironmentInfo();
+ const {browser, platform} = await api.getEnvironmentInfo();
document.documentElement.dataset.browser = browser;
document.documentElement.dataset.os = platform.os;
document.documentElement.dataset.manifestVersion = `${manifestVersion}`;
@@ -90,6 +90,8 @@ function setupPermissionsToggles() {
/** Entry point. */
async function main() {
try {
+ const application = new Application();
+
const documentFocusController = new DocumentFocusController();
documentFocusController.prepare();
@@ -98,9 +100,9 @@ async function main() {
setupPermissionsToggles();
- await yomitan.prepare();
+ await application.prepare();
- setupEnvironmentInfo();
+ setupEnvironmentInfo(application.api);
/** @type {HTMLInputElement} */
const permissionCheckbox1 = querySelectorNotNull(document, '#permission-checkbox-allow-in-private-windows');
@@ -121,7 +123,7 @@ async function main() {
const modalController = new ModalController();
modalController.prepare();
- const settingsController = new SettingsController();
+ const settingsController = new SettingsController(application);
await settingsController.prepare();
const permissionsToggleController = new PermissionsToggleController(settingsController);
@@ -130,7 +132,7 @@ async function main() {
const permissionsOriginController = new PermissionsOriginController(settingsController);
permissionsOriginController.prepare();
- const persistentStorageController = new PersistentStorageController();
+ const persistentStorageController = new PersistentStorageController(application);
persistentStorageController.prepare();
await promiseTimeout(100);
diff --git a/ext/js/pages/settings/anki-controller.js b/ext/js/pages/settings/anki-controller.js
index 09ab3c03..ae6a71db 100644
--- a/ext/js/pages/settings/anki-controller.js
+++ b/ext/js/pages/settings/anki-controller.js
@@ -26,7 +26,6 @@ import {getRequiredPermissionsForAnkiFieldValue, hasPermissions, setPermissionsG
import {querySelectorNotNull} from '../../dom/query-selector.js';
import {SelectorObserver} from '../../dom/selector-observer.js';
import {ObjectPropertyAccessor} from '../../general/object-property-accessor.js';
-import {yomitan} from '../../yomitan.js';
export class AnkiController {
/**
@@ -510,7 +509,7 @@ export class AnkiController {
let noteId = null;
for (const query of queries) {
- const notes = await yomitan.api.findAnkiNotes(query);
+ const notes = await this._settingsController.application.api.findAnkiNotes(query);
if (notes.length > 0) {
noteId = notes[0];
break;
@@ -521,7 +520,7 @@ export class AnkiController {
throw new Error('Could not find a note to test with');
}
- await yomitan.api.noteView(noteId, mode, false);
+ await this._settingsController.application.api.noteView(noteId, mode, false);
}
/**
diff --git a/ext/js/pages/settings/anki-templates-controller.js b/ext/js/pages/settings/anki-templates-controller.js
index 869c9e16..332102cf 100644
--- a/ext/js/pages/settings/anki-templates-controller.js
+++ b/ext/js/pages/settings/anki-templates-controller.js
@@ -21,7 +21,6 @@ import {toError} from '../../core/to-error.js';
import {AnkiNoteBuilder} from '../../data/anki-note-builder.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
import {TemplateRendererProxy} from '../../templates/template-renderer-proxy.js';
-import {yomitan} from '../../yomitan.js';
export class AnkiTemplatesController {
/**
@@ -55,12 +54,12 @@ export class AnkiTemplatesController {
/** @type {?import('./modal.js').Modal} */
this._fieldTemplateResetModal = null;
/** @type {AnkiNoteBuilder} */
- this._ankiNoteBuilder = new AnkiNoteBuilder(new TemplateRendererProxy());
+ this._ankiNoteBuilder = new AnkiNoteBuilder(settingsController.application.api, new TemplateRendererProxy());
}
/** */
async prepare() {
- this._defaultFieldTemplates = await yomitan.api.getDefaultAnkiFieldTemplates();
+ this._defaultFieldTemplates = await this._settingsController.application.api.getDefaultAnkiFieldTemplates();
/** @type {HTMLButtonElement} */
const menuButton = querySelectorNotNull(document, '#anki-card-templates-test-field-menu-button');
@@ -205,7 +204,7 @@ export class AnkiTemplatesController {
*/
async _getDictionaryEntry(text, optionsContext) {
if (this._cachedDictionaryEntryText !== text) {
- const {dictionaryEntries} = await yomitan.api.termsFind(text, {}, optionsContext);
+ const {dictionaryEntries} = await this._settingsController.application.api.termsFind(text, {}, optionsContext);
if (dictionaryEntries.length === 0) { return null; }
this._cachedDictionaryEntryValue = dictionaryEntries[0];
diff --git a/ext/js/pages/settings/backup-controller.js b/ext/js/pages/settings/backup-controller.js
index 053cc96b..79733c4d 100644
--- a/ext/js/pages/settings/backup-controller.js
+++ b/ext/js/pages/settings/backup-controller.js
@@ -25,7 +25,6 @@ import {OptionsUtil} from '../../data/options-util.js';
import {getAllPermissions} from '../../data/permissions-util.js';
import {arrayBufferUtf8Decode} from '../../data/sandbox/array-buffer-util.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
-import {yomitan} from '../../yomitan.js';
import {DictionaryController} from './dictionary-controller.js';
export class BackupController {
@@ -134,8 +133,8 @@ export class BackupController {
*/
async _getSettingsExportData(date) {
const optionsFull = await this._settingsController.getOptionsFull();
- const environment = await yomitan.api.getEnvironmentInfo();
- const fieldTemplatesDefault = await yomitan.api.getDefaultAnkiFieldTemplates();
+ const environment = await this._settingsController.application.api.getEnvironmentInfo();
+ const fieldTemplatesDefault = await this._settingsController.application.api.getDefaultAnkiFieldTemplates();
const permissions = await getAllPermissions();
// Format options
@@ -644,10 +643,10 @@ export class BackupController {
* @param {File} file
*/
async _importDatabase(databaseName, file) {
- await yomitan.api.purgeDatabase();
+ await this._settingsController.application.api.purgeDatabase();
await Dexie.import(file, {progressCallback: this._databaseImportProgressCallback});
- yomitan.api.triggerDatabaseUpdated('dictionary', 'import');
- yomitan.triggerStorageChanged();
+ this._settingsController.application.api.triggerDatabaseUpdated('dictionary', 'import');
+ this._settingsController.application.triggerStorageChanged();
}
/** */
diff --git a/ext/js/pages/settings/collapsible-dictionary-controller.js b/ext/js/pages/settings/collapsible-dictionary-controller.js
index e6930049..5ba61e0c 100644
--- a/ext/js/pages/settings/collapsible-dictionary-controller.js
+++ b/ext/js/pages/settings/collapsible-dictionary-controller.js
@@ -18,7 +18,6 @@
import {EventListenerCollection} from '../../core/event-listener-collection.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
-import {yomitan} from '../../yomitan.js';
export class CollapsibleDictionaryController {
/**
@@ -45,7 +44,7 @@ export class CollapsibleDictionaryController {
async prepare() {
await this._onDatabaseUpdated();
- yomitan.on('databaseUpdated', this._onDatabaseUpdated.bind(this));
+ this._settingsController.application.on('databaseUpdated', this._onDatabaseUpdated.bind(this));
this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this));
this._settingsController.on('dictionarySettingsReordered', this._onDictionarySettingsReordered.bind(this));
}
diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js
index 10dfdcdc..1d3c1730 100644
--- a/ext/js/pages/settings/dictionary-controller.js
+++ b/ext/js/pages/settings/dictionary-controller.js
@@ -20,7 +20,6 @@ import {EventListenerCollection} from '../../core/event-listener-collection.js';
import {log} from '../../core/logger.js';
import {DictionaryWorker} from '../../dictionary/dictionary-worker.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
-import {yomitan} from '../../yomitan.js';
class DictionaryEntry {
/**
@@ -437,7 +436,7 @@ export class DictionaryController {
/** @type {HTMLButtonElement} */
const dictionaryMoveButton = querySelectorNotNull(document, '#dictionary-move-button');
- yomitan.on('databaseUpdated', this._onDatabaseUpdated.bind(this));
+ this._settingsController.application.on('databaseUpdated', this._onDatabaseUpdated.bind(this));
this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this));
this._allCheckbox.addEventListener('change', this._onAllCheckboxChange.bind(this), false);
dictionaryDeleteButton.addEventListener('click', this._onDictionaryConfirmDelete.bind(this), false);
@@ -917,7 +916,7 @@ export class DictionaryController {
*/
async _deleteDictionaryInternal(dictionaryTitle, onProgress) {
await new DictionaryWorker().deleteDictionary(dictionaryTitle, onProgress);
- yomitan.api.triggerDatabaseUpdated('dictionary', 'delete');
+ this._settingsController.application.api.triggerDatabaseUpdated('dictionary', 'delete');
}
/**
@@ -947,7 +946,7 @@ export class DictionaryController {
/** */
_triggerStorageChanged() {
- yomitan.triggerStorageChanged();
+ this._settingsController.application.triggerStorageChanged();
}
/** */
diff --git a/ext/js/pages/settings/dictionary-import-controller.js b/ext/js/pages/settings/dictionary-import-controller.js
index 183c0ccd..0484001d 100644
--- a/ext/js/pages/settings/dictionary-import-controller.js
+++ b/ext/js/pages/settings/dictionary-import-controller.js
@@ -21,7 +21,6 @@ import {log} from '../../core/logger.js';
import {toError} from '../../core/to-error.js';
import {DictionaryWorker} from '../../dictionary/dictionary-worker.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
-import {yomitan} from '../../yomitan.js';
import {DictionaryController} from './dictionary-controller.js';
export class DictionaryImportController {
@@ -120,7 +119,7 @@ export class DictionaryImportController {
this._setModifying(true);
this._hideErrors();
- await yomitan.api.purgeDatabase();
+ await this._settingsController.application.api.purgeDatabase();
const errors = await this._clearDictionarySettings();
if (errors.length > 0) {
@@ -236,7 +235,7 @@ export class DictionaryImportController {
async _importDictionary(file, importDetails, onProgress) {
const archiveContent = await this._readFile(file);
const {result, errors} = await new DictionaryWorker().importDictionary(archiveContent, importDetails, onProgress);
- yomitan.api.triggerDatabaseUpdated('dictionary', 'import');
+ this._settingsController.application.api.triggerDatabaseUpdated('dictionary', 'import');
const errors2 = await this._addDictionarySettings(result.sequenced, result.title);
if (errors.length > 0) {
@@ -399,6 +398,6 @@ export class DictionaryImportController {
/** */
_triggerStorageChanged() {
- yomitan.triggerStorageChanged();
+ this._settingsController.application.triggerStorageChanged();
}
}
diff --git a/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js b/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js
index 61330bb8..61eefffa 100644
--- a/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js
+++ b/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js
@@ -20,7 +20,6 @@ import {EventListenerCollection} from '../../core/event-listener-collection.js';
import {isObject} from '../../core/utilities.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
import {HotkeyUtil} from '../../input/hotkey-util.js';
-import {yomitan} from '../../yomitan.js';
import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js';
export class ExtensionKeyboardShortcutController {
@@ -63,7 +62,7 @@ export class ExtensionKeyboardShortcutController {
this._clearButton.addEventListener('click', this._onClearClick.bind(this));
}
- const {platform: {os}} = await yomitan.api.getEnvironmentInfo();
+ const {platform: {os}} = await this._settingsController.application.api.getEnvironmentInfo();
this._os = os;
this._hotkeyUtil.os = os;
diff --git a/ext/js/pages/settings/keyboard-shortcuts-controller.js b/ext/js/pages/settings/keyboard-shortcuts-controller.js
index 396b0cc2..9392f768 100644
--- a/ext/js/pages/settings/keyboard-shortcuts-controller.js
+++ b/ext/js/pages/settings/keyboard-shortcuts-controller.js
@@ -20,7 +20,6 @@ import {EventListenerCollection} from '../../core/event-listener-collection.js';
import {DocumentUtil} from '../../dom/document-util.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
import {ObjectPropertyAccessor} from '../../general/object-property-accessor.js';
-import {yomitan} from '../../yomitan.js';
import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js';
export class KeyboardShortcutController {
@@ -81,7 +80,7 @@ export class KeyboardShortcutController {
/** */
async prepare() {
- const {platform: {os}} = await yomitan.api.getEnvironmentInfo();
+ const {platform: {os}} = await this._settingsController.application.api.getEnvironmentInfo();
this._os = os;
this._addButton.addEventListener('click', this._onAddClick.bind(this));
diff --git a/ext/js/pages/settings/mecab-controller.js b/ext/js/pages/settings/mecab-controller.js
index dec2be68..ba2f6166 100644
--- a/ext/js/pages/settings/mecab-controller.js
+++ b/ext/js/pages/settings/mecab-controller.js
@@ -18,10 +18,14 @@
import {toError} from '../../core/to-error.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
-import {yomitan} from '../../yomitan.js';
export class MecabController {
- constructor() {
+ /**
+ * @param {import('../../comm/api.js').API} api
+ */
+ constructor(api) {
+ /** @type {import('../../comm/api.js').API} */
+ this._api = api;
/** @type {HTMLButtonElement} */
this._testButton = querySelectorNotNull(document, '#test-mecab-button');
/** @type {HTMLElement} */
@@ -55,7 +59,7 @@ export class MecabController {
/** @type {HTMLButtonElement} */ (this._testButton).disabled = true;
resultsContainer.textContent = '';
resultsContainer.hidden = true;
- await yomitan.api.testMecab();
+ await this._api.testMecab();
this._setStatus('Connection was successful', false);
} catch (e) {
this._setStatus(toError(e).message, true);
diff --git a/ext/js/pages/settings/persistent-storage-controller.js b/ext/js/pages/settings/persistent-storage-controller.js
index baffa969..8b7726dd 100644
--- a/ext/js/pages/settings/persistent-storage-controller.js
+++ b/ext/js/pages/settings/persistent-storage-controller.js
@@ -18,14 +18,23 @@
import {isObject} from '../../core/utilities.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
-import {yomitan} from '../../yomitan.js';
export class PersistentStorageController {
- constructor() {
+ /**
+ * @param {import('../../application.js').Application} application
+ */
+ constructor(application) {
+ /** @type {import('../../application.js').Application} */
+ this._application = application;
/** @type {HTMLInputElement} */
this._persistentStorageCheckbox = querySelectorNotNull(document, '#storage-persistent-checkbox');
}
+ /** @type {import('../../application.js').Application} */
+ get application() {
+ return this._application;
+ }
+
/** */
async prepare() {
this._persistentStorageCheckbox.addEventListener('change', this._onPersistentStorageCheckboxChange.bind(this), false);
@@ -82,7 +91,7 @@ export class PersistentStorageController {
const node = document.querySelector('#storage-persistent-fail-warning');
if (node !== null) { node.hidden = isStoragePeristent; }
- yomitan.triggerStorageChanged();
+ this._application.triggerStorageChanged();
}
/**
diff --git a/ext/js/pages/settings/popup-preview-frame-main.js b/ext/js/pages/settings/popup-preview-frame-main.js
index e3d7d0ec..fd08bf1d 100644
--- a/ext/js/pages/settings/popup-preview-frame-main.js
+++ b/ext/js/pages/settings/popup-preview-frame-main.js
@@ -17,17 +17,18 @@
*/
import {PopupFactory} from '../../app/popup-factory.js';
+import {Application} from '../../application.js';
import {log} from '../../core/logger.js';
import {HotkeyHandler} from '../../input/hotkey-handler.js';
-import {yomitan} from '../../yomitan.js';
import {PopupPreviewFrame} from './popup-preview-frame.js';
/** Entry point. */
async function main() {
try {
- await yomitan.prepare();
+ const application = new Application();
+ await application.prepare();
- const {tabId, frameId} = await yomitan.api.frameInformationGet();
+ const {tabId, frameId} = await application.api.frameInformationGet();
if (typeof tabId === 'undefined') {
throw new Error('Failed to get tabId');
}
@@ -36,12 +37,12 @@ async function main() {
}
const hotkeyHandler = new HotkeyHandler();
- hotkeyHandler.prepare();
+ hotkeyHandler.prepare(application.crossFrame);
- const popupFactory = new PopupFactory(frameId);
+ const popupFactory = new PopupFactory(application, frameId);
popupFactory.prepare();
- const preview = new PopupPreviewFrame(tabId, frameId, popupFactory, hotkeyHandler);
+ const preview = new PopupPreviewFrame(application, tabId, frameId, popupFactory, hotkeyHandler);
await preview.prepare();
document.documentElement.dataset.loaded = 'true';
diff --git a/ext/js/pages/settings/popup-preview-frame.js b/ext/js/pages/settings/popup-preview-frame.js
index 7a899641..e9cfa541 100644
--- a/ext/js/pages/settings/popup-preview-frame.js
+++ b/ext/js/pages/settings/popup-preview-frame.js
@@ -20,16 +20,18 @@ import * as wanakana from '../../../lib/wanakana.js';
import {Frontend} from '../../app/frontend.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
import {TextSourceRange} from '../../dom/text-source-range.js';
-import {yomitan} from '../../yomitan.js';
export class PopupPreviewFrame {
/**
+ * @param {import('../../application.js').Application} application
* @param {number} tabId
* @param {number} frameId
* @param {import('../../app/popup-factory.js').PopupFactory} popupFactory
* @param {import('../../input/hotkey-handler.js').HotkeyHandler} hotkeyHandler
*/
- constructor(tabId, frameId, popupFactory, hotkeyHandler) {
+ constructor(application, tabId, frameId, popupFactory, hotkeyHandler) {
+ /** @type {import('../../application.js').Application} */
+ this._application = application;
/** @type {number} */
this._tabId = tabId;
/** @type {number} */
@@ -86,11 +88,12 @@ export class PopupPreviewFrame {
// Overwrite API functions
/** @type {?(optionsContext: import('settings').OptionsContext) => Promise<import('settings').ProfileOptions>} */
- this._apiOptionsGetOld = yomitan.api.optionsGet.bind(yomitan.api);
- yomitan.api.optionsGet = this._apiOptionsGet.bind(this);
+ this._apiOptionsGetOld = this._application.api.optionsGet.bind(this._application.api);
+ this._application.api.optionsGet = this._apiOptionsGet.bind(this);
// Overwrite frontend
this._frontend = new Frontend({
+ application: this._application,
tabId: this._tabId,
frameId: this._frameId,
popupFactory: this._popupFactory,
diff --git a/ext/js/pages/settings/popup-window-controller.js b/ext/js/pages/settings/popup-window-controller.js
index 1b767f77..62879f3b 100644
--- a/ext/js/pages/settings/popup-window-controller.js
+++ b/ext/js/pages/settings/popup-window-controller.js
@@ -17,9 +17,16 @@
*/
import {querySelectorNotNull} from '../../dom/query-selector.js';
-import {yomitan} from '../../yomitan.js';
export class PopupWindowController {
+ /**
+ * @param {import('../../comm/api.js').API} api
+ */
+ constructor(api) {
+ /** @type {import('../../comm/api.js').API} */
+ this._api = api;
+ }
+
/** */
prepare() {
/** @type {HTMLElement} */
@@ -39,6 +46,6 @@ export class PopupWindowController {
/** */
async _testWindowOpen() {
- await yomitan.api.getOrCreateSearchPopup({focus: true});
+ await this._api.getOrCreateSearchPopup({focus: true});
}
}
diff --git a/ext/js/pages/settings/profile-controller.js b/ext/js/pages/settings/profile-controller.js
index 73926a69..c5ccbe7d 100644
--- a/ext/js/pages/settings/profile-controller.js
+++ b/ext/js/pages/settings/profile-controller.js
@@ -19,7 +19,6 @@
import {EventListenerCollection} from '../../core/event-listener-collection.js';
import {clone} from '../../core/utilities.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
-import {yomitan} from '../../yomitan.js';
import {ProfileConditionsUI} from './profile-conditions-ui.js';
export class ProfileController {
@@ -82,7 +81,7 @@ export class ProfileController {
/** */
async prepare() {
- const {platform: {os}} = await yomitan.api.getEnvironmentInfo();
+ const {platform: {os}} = await this._settingsController.application.api.getEnvironmentInfo();
this._profileConditionsUI.os = os;
this._profileRemoveModal = this._modalController.getModal('profile-remove');
diff --git a/ext/js/pages/settings/scan-inputs-controller.js b/ext/js/pages/settings/scan-inputs-controller.js
index 2dfa3de3..f1547fe4 100644
--- a/ext/js/pages/settings/scan-inputs-controller.js
+++ b/ext/js/pages/settings/scan-inputs-controller.js
@@ -19,7 +19,6 @@
import {EventListenerCollection} from '../../core/event-listener-collection.js';
import {DocumentUtil} from '../../dom/document-util.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
-import {yomitan} from '../../yomitan.js';
import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js';
export class ScanInputsController {
@@ -43,7 +42,7 @@ export class ScanInputsController {
/** */
async prepare() {
- const {platform: {os}} = await yomitan.api.getEnvironmentInfo();
+ const {platform: {os}} = await this._settingsController.application.api.getEnvironmentInfo();
this._os = os;
this._scanningInputCountNodes = /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('.scanning-input-count'));
diff --git a/ext/js/pages/settings/scan-inputs-simple-controller.js b/ext/js/pages/settings/scan-inputs-simple-controller.js
index e4f34c99..b09a3a76 100644
--- a/ext/js/pages/settings/scan-inputs-simple-controller.js
+++ b/ext/js/pages/settings/scan-inputs-simple-controller.js
@@ -18,7 +18,6 @@
import {querySelectorNotNull} from '../../dom/query-selector.js';
import {HotkeyUtil} from '../../input/hotkey-util.js';
-import {yomitan} from '../../yomitan.js';
import {ScanInputsController} from './scan-inputs-controller.js';
export class ScanInputsSimpleController {
@@ -40,7 +39,7 @@ export class ScanInputsSimpleController {
/** */
async prepare() {
- const {platform: {os}} = await yomitan.api.getEnvironmentInfo();
+ const {platform: {os}} = await this._settingsController.application.api.getEnvironmentInfo();
this._hotkeyUtil.os = os;
this._mainScanModifierKeyInputHasOther = false;
diff --git a/ext/js/pages/settings/secondary-search-dictionary-controller.js b/ext/js/pages/settings/secondary-search-dictionary-controller.js
index 592f5eeb..c708bf65 100644
--- a/ext/js/pages/settings/secondary-search-dictionary-controller.js
+++ b/ext/js/pages/settings/secondary-search-dictionary-controller.js
@@ -18,7 +18,6 @@
import {EventListenerCollection} from '../../core/event-listener-collection.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
-import {yomitan} from '../../yomitan.js';
export class SecondarySearchDictionaryController {
/**
@@ -41,7 +40,7 @@ export class SecondarySearchDictionaryController {
async prepare() {
await this._onDatabaseUpdated();
- yomitan.on('databaseUpdated', this._onDatabaseUpdated.bind(this));
+ this._settingsController.application.on('databaseUpdated', this._onDatabaseUpdated.bind(this));
this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this));
this._settingsController.on('dictionarySettingsReordered', this._onDictionarySettingsReordered.bind(this));
}
diff --git a/ext/js/pages/settings/settings-controller.js b/ext/js/pages/settings/settings-controller.js
index 49fa9c9e..3f389271 100644
--- a/ext/js/pages/settings/settings-controller.js
+++ b/ext/js/pages/settings/settings-controller.js
@@ -22,14 +22,18 @@ import {generateId, isObject} from '../../core/utilities.js';
import {OptionsUtil} from '../../data/options-util.js';
import {getAllPermissions} from '../../data/permissions-util.js';
import {HtmlTemplateCollection} from '../../dom/html-template-collection.js';
-import {yomitan} from '../../yomitan.js';
/**
* @augments EventDispatcher<import('settings-controller').Events>
*/
export class SettingsController extends EventDispatcher {
- constructor() {
+ /**
+ * @param {import('../../application.js').Application} application
+ */
+ constructor(application) {
super();
+ /** @type {import('../../application.js').Application} */
+ this._application = application;
/** @type {number} */
this._profileIndex = 0;
/** @type {string} */
@@ -43,6 +47,11 @@ export class SettingsController extends EventDispatcher {
this._templates.load(document);
}
+ /** @type {import('../../application.js').Application} */
+ get application() {
+ return this._application;
+ }
+
/** @type {string} */
get source() {
return this._source;
@@ -60,7 +69,7 @@ export class SettingsController extends EventDispatcher {
/** */
async prepare() {
- yomitan.on('optionsUpdated', this._onOptionsUpdated.bind(this));
+ this._application.on('optionsUpdated', this._onOptionsUpdated.bind(this));
if (this._canObservePermissionsChanges()) {
chrome.permissions.onAdded.addListener(this._onPermissionsChanged.bind(this));
chrome.permissions.onRemoved.addListener(this._onPermissionsChanged.bind(this));
@@ -82,14 +91,14 @@ export class SettingsController extends EventDispatcher {
*/
async getOptions() {
const optionsContext = this.getOptionsContext();
- return await yomitan.api.optionsGet(optionsContext);
+ return await this._application.api.optionsGet(optionsContext);
}
/**
* @returns {Promise<import('settings').Options>}
*/
async getOptionsFull() {
- return await yomitan.api.optionsGetFull();
+ return await this._application.api.optionsGetFull();
}
/**
@@ -97,7 +106,7 @@ export class SettingsController extends EventDispatcher {
*/
async setAllSettings(value) {
const profileIndex = value.profileCurrent;
- await yomitan.api.setAllSettings(value, this._source);
+ await this._application.api.setAllSettings(value, this._source);
this._setProfileIndex(profileIndex, true);
}
@@ -171,7 +180,7 @@ export class SettingsController extends EventDispatcher {
* @returns {Promise<import('dictionary-importer').Summary[]>}
*/
async getDictionaryInfo() {
- return await yomitan.api.getDictionaryInfo();
+ return await this._application.api.getDictionaryInfo();
}
/**
@@ -279,7 +288,7 @@ export class SettingsController extends EventDispatcher {
this._modifyOptionsScope(target2);
return target2;
});
- return await yomitan.api.getSettings(targets2);
+ return await this._application.api.getSettings(targets2);
}
/**
@@ -294,7 +303,7 @@ export class SettingsController extends EventDispatcher {
this._modifyOptionsScope(target2);
return target2;
});
- return await yomitan.api.modifySettings(targets2, this._source);
+ return await this._application.api.modifySettings(targets2, this._source);
}
/**
diff --git a/ext/js/pages/settings/settings-main.js b/ext/js/pages/settings/settings-main.js
index 7e458043..c3391173 100644
--- a/ext/js/pages/settings/settings-main.js
+++ b/ext/js/pages/settings/settings-main.js
@@ -16,10 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+import {Application} from '../../application.js';
import {log} from '../../core/logger.js';
import {DocumentFocusController} from '../../dom/document-focus-controller.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
-import {yomitan} from '../../yomitan.js';
import {ExtensionContentController} from '../common/extension-content-controller.js';
import {AnkiController} from './anki-controller.js';
import {AnkiTemplatesController} from './anki-templates-controller.js';
@@ -78,7 +78,8 @@ async function main() {
document.documentElement.dataset.loadingStalled = 'true';
}, 1000);
- await yomitan.prepare();
+ const application = new Application();
+ await application.prepare();
if (prepareTimer !== null) {
clearTimeout(prepareTimer);
@@ -91,10 +92,10 @@ async function main() {
const modalController = new ModalController();
modalController.prepare();
- const settingsController = new SettingsController();
+ const settingsController = new SettingsController(application);
await settingsController.prepare();
- const persistentStorageController = new PersistentStorageController();
+ const persistentStorageController = new PersistentStorageController(application);
persistentStorageController.prepare();
const storageController = new StorageController(persistentStorageController);
@@ -154,10 +155,10 @@ async function main() {
const extensionKeyboardShortcutController = new ExtensionKeyboardShortcutController(settingsController);
extensionKeyboardShortcutController.prepare();
- const popupWindowController = new PopupWindowController();
+ const popupWindowController = new PopupWindowController(application.api);
popupWindowController.prepare();
- const mecabController = new MecabController();
+ const mecabController = new MecabController(application.api);
mecabController.prepare();
const collapsibleDictionaryController = new CollapsibleDictionaryController(settingsController);
diff --git a/ext/js/pages/settings/sort-frequency-dictionary-controller.js b/ext/js/pages/settings/sort-frequency-dictionary-controller.js
index f5b230f0..c8e9918b 100644
--- a/ext/js/pages/settings/sort-frequency-dictionary-controller.js
+++ b/ext/js/pages/settings/sort-frequency-dictionary-controller.js
@@ -17,7 +17,6 @@
*/
import {querySelectorNotNull} from '../../dom/query-selector.js';
-import {yomitan} from '../../yomitan.js';
export class SortFrequencyDictionaryController {
/**
@@ -42,7 +41,7 @@ export class SortFrequencyDictionaryController {
async prepare() {
await this._onDatabaseUpdated();
- yomitan.on('databaseUpdated', this._onDatabaseUpdated.bind(this));
+ this._settingsController.application.on('databaseUpdated', this._onDatabaseUpdated.bind(this));
this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this));
this._sortFrequencyDictionarySelect.addEventListener('change', this._onSortFrequencyDictionarySelectChange.bind(this));
this._sortFrequencyDictionaryOrderSelect.addEventListener('change', this._onSortFrequencyDictionaryOrderSelectChange.bind(this));
@@ -157,7 +156,7 @@ export class SortFrequencyDictionaryController {
const lessCommonTerms = ['行なう', '論じる', '過す', '行方', '人口', '猫', '犬', '滝', '理', '暁'];
const terms = [...moreCommonTerms, ...lessCommonTerms];
- const frequencies = await yomitan.api.getTermFrequencies(
+ const frequencies = await this._settingsController.application.api.getTermFrequencies(
terms.map((term) => ({term, reading: null})),
[dictionary]
);
diff --git a/ext/js/pages/settings/storage-controller.js b/ext/js/pages/settings/storage-controller.js
index 6be1fe24..9a3aa23a 100644
--- a/ext/js/pages/settings/storage-controller.js
+++ b/ext/js/pages/settings/storage-controller.js
@@ -17,7 +17,6 @@
*/
import {querySelectorNotNull} from '../../dom/query-selector.js';
-import {yomitan} from '../../yomitan.js';
export class StorageController {
/**
@@ -61,7 +60,7 @@ export class StorageController {
const storageRefreshButton = querySelectorNotNull(document, '#storage-refresh');
storageRefreshButton.addEventListener('click', this._onStorageRefreshButtonClick.bind(this), false);
- yomitan.on('storageChanged', this._onStorageChanged.bind(this));
+ this._persistentStorageController.application.on('storageChanged', this._onStorageChanged.bind(this));
this._updateStats();
}
diff --git a/ext/js/pages/welcome-main.js b/ext/js/pages/welcome-main.js
index 35472ec2..030d2826 100644
--- a/ext/js/pages/welcome-main.js
+++ b/ext/js/pages/welcome-main.js
@@ -16,10 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+import {Application} from '../application.js';
import {log} from '../core/logger.js';
import {DocumentFocusController} from '../dom/document-focus-controller.js';
import {querySelectorNotNull} from '../dom/query-selector.js';
-import {yomitan} from '../yomitan.js';
import {ExtensionContentController} from './common/extension-content-controller.js';
import {DictionaryController} from './settings/dictionary-controller.js';
import {DictionaryImportController} from './settings/dictionary-import-controller.js';
@@ -31,10 +31,12 @@ import {SettingsController} from './settings/settings-controller.js';
import {SettingsDisplayController} from './settings/settings-display-controller.js';
import {StatusFooter} from './settings/status-footer.js';
-/** */
-async function setupEnvironmentInfo() {
+/**
+ * @param {import('../comm/api.js').API} api
+ */
+async function setupEnvironmentInfo(api) {
const {manifest_version: manifestVersion} = chrome.runtime.getManifest();
- const {browser, platform} = await yomitan.api.getEnvironmentInfo();
+ const {browser, platform} = await api.getEnvironmentInfo();
document.documentElement.dataset.browser = browser;
document.documentElement.dataset.os = platform.os;
document.documentElement.dataset.manifestVersion = `${manifestVersion}`;
@@ -62,9 +64,10 @@ async function main() {
const statusFooter = new StatusFooter(statusFooterElement);
statusFooter.prepare();
- await yomitan.prepare();
+ const application = new Application();
+ await application.prepare();
- setupEnvironmentInfo();
+ setupEnvironmentInfo(application.api);
chrome.storage.session.get({'needsCustomTemplatesWarning': false}).then((result) => {
if (result.needsCustomTemplatesWarning) {
@@ -78,7 +81,7 @@ async function main() {
const modalController = new ModalController();
modalController.prepare();
- const settingsController = new SettingsController();
+ const settingsController = new SettingsController(application);
await settingsController.prepare();
const dictionaryController = new DictionaryController(settingsController, modalController, statusFooter);