summaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-09-13 18:43:44 -0400
committerGitHub <noreply@github.com>2020-09-13 18:43:44 -0400
commit5ec5d0c91c0726ed74b0cb8772d992ae478625b8 (patch)
tree65c5c17c0b8c8cea2def98a79801568ea55fd12d /ext/bg/js/backend.js
parent8b033a1650ff9425963c164aba1a744aada93f20 (diff)
Database change event (#826)
* Add api.triggerDatabaseUpdated and yomichan.on('databaseUpdated') * Update databaseUpdated event usage
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js13
1 files changed, 12 insertions, 1 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});
+ }
}