summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/backend.js13
-rw-r--r--ext/bg/js/settings/dictionary-controller.js6
-rw-r--r--ext/bg/js/settings/dictionary-import-controller.js9
-rw-r--r--ext/bg/js/settings/settings-controller.js4
4 files changed, 15 insertions, 17 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 0c7dc768..ceb1e257 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -115,7 +115,8 @@ class Backend {
['setAllSettings', {async: true, contentScript: false, handler: this._onApiSetAllSettings.bind(this)}],
['getOrCreateSearchPopup', {async: true, contentScript: true, handler: this._onApiGetOrCreateSearchPopup.bind(this)}],
['isTabSearchPopup', {async: true, contentScript: true, handler: this._onApiIsTabSearchPopup.bind(this)}],
- ['getDefinitionAudio', {async: true, contentScript: true, handler: this._onApiGetDefinitionAudio.bind(this)}]
+ ['getDefinitionAudio', {async: true, contentScript: true, handler: this._onApiGetDefinitionAudio.bind(this)}],
+ ['triggerDatabaseUpdated', {async: false, contentScript: true, handler: this._onApiTriggerDatabaseUpdated.bind(this)}]
]);
this._messageHandlersWithProgress = new Map([
['deleteDictionary', {async: true, contentScript: false, handler: this._onApiDeleteDictionary.bind(this)}]
@@ -709,6 +710,7 @@ class Backend {
async _onApiPurgeDatabase() {
this._translator.clearDatabaseCaches();
await this._dictionaryDatabase.purge();
+ this._triggerDatabaseUpdated('dictionary', 'purge');
}
async _onApiGetMedia({targets}) {
@@ -751,6 +753,7 @@ class Backend {
async _onApiDeleteDictionary({dictionaryName}, sender, onProgress) {
this._translator.clearDatabaseCaches();
await this._dictionaryDatabase.deleteDictionary(dictionaryName, {rate: 1000}, onProgress);
+ this._triggerDatabaseUpdated('dictionary', 'delete');
}
async _onApiModifySettings({targets, source}) {
@@ -807,6 +810,10 @@ class Backend {
return this._getDefinitionAudio(sources, expression, reading, details);
}
+ _onApiTriggerDatabaseUpdated({type, cause}) {
+ this._triggerDatabaseUpdated(type, cause);
+ }
+
// Command handlers
async _onCommandSearch(params) {
@@ -1720,4 +1727,8 @@ class Backend {
default: throw new Error('Unknown image media type');
}
}
+
+ _triggerDatabaseUpdated(type, cause) {
+ this._sendMessageAllTabs('databaseUpdated', {type, cause});
+ }
}
diff --git a/ext/bg/js/settings/dictionary-controller.js b/ext/bg/js/settings/dictionary-controller.js
index 9292d2c4..eccb0e88 100644
--- a/ext/bg/js/settings/dictionary-controller.js
+++ b/ext/bg/js/settings/dictionary-controller.js
@@ -307,8 +307,6 @@ class SettingsDictionaryEntryUI {
prevention.end();
this.isDeleting = false;
progress.hidden = true;
-
- this.parent.trigger('databaseUpdated');
}
}
@@ -397,13 +395,13 @@ class DictionaryController {
);
this._dictionaryUI.save = () => this._settingsController.save();
this._dictionaryUI.preventPageExit = this._preventPageExit.bind(this);
- this._dictionaryUI.on('databaseUpdated', this._onDatabaseUpdated.bind(this));
document.querySelector('#dict-main').addEventListener('change', this._onDictionaryMainChanged.bind(this), false);
document.querySelector('#database-enable-prefix-wildcard-searches').addEventListener('change', this._onDatabaseEnablePrefixWildcardSearchesChanged.bind(this), false);
this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this));
- this._settingsController.on('databaseUpdated', this._onDatabaseUpdated.bind(this));
+
+ yomichan.on('databaseUpdated', this._onDatabaseUpdated.bind(this));
await this._onOptionsChanged();
await this._onDatabaseUpdated();
diff --git a/ext/bg/js/settings/dictionary-import-controller.js b/ext/bg/js/settings/dictionary-import-controller.js
index b10c87d0..cce695d0 100644
--- a/ext/bg/js/settings/dictionary-import-controller.js
+++ b/ext/bg/js/settings/dictionary-import-controller.js
@@ -110,8 +110,6 @@ class DictionaryImportController {
if (errors.length > 0) {
this._showErrors(errors);
}
-
- this._triggerDatabaseUpdated('purge');
} catch (error) {
this._showErrors([error]);
} finally {
@@ -178,6 +176,7 @@ class DictionaryImportController {
const dictionaryImporter = new DictionaryImporter();
const archiveContent = await this._readFile(file);
const {result, errors} = await dictionaryImporter.importDictionary(dictionaryDatabase, archiveContent, importDetails, onProgress);
+ api.triggerDatabaseUpdated('dictionary', 'import');
const errors2 = await this._addDictionarySettings(result.sequenced, result.title);
if (errors.length > 0) {
@@ -185,8 +184,6 @@ class DictionaryImportController {
allErrors.push(new Error(`Dictionary may not have been imported properly: ${allErrors.length} error${allErrors.length === 1 ? '' : 's'} reported.`));
this._showErrors(allErrors);
}
-
- this._triggerDatabaseUpdated('import');
} finally {
dictionaryDatabase.close();
}
@@ -271,10 +268,6 @@ class DictionaryImportController {
this._errorContainer.hidden = true;
}
- _triggerDatabaseUpdated(cause) {
- this._settingsController.triggerDatabaseUpdated(cause);
- }
-
_readFile(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
diff --git a/ext/bg/js/settings/settings-controller.js b/ext/bg/js/settings/settings-controller.js
index d2656beb..4e61e05c 100644
--- a/ext/bg/js/settings/settings-controller.js
+++ b/ext/bg/js/settings/settings-controller.js
@@ -125,10 +125,6 @@ class SettingsController extends EventDispatcher {
return obj;
}
- triggerDatabaseUpdated(cause) {
- this.trigger('databaseUpdated', {cause});
- }
-
// Private
_setProfileIndex(value) {