aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/settings
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/pages/settings')
-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
21 files changed, 93 insertions, 73 deletions
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();
}