Move database creation into Backend

This commit is contained in:
toasted-nutbread 2020-03-30 20:39:04 -04:00
parent 8095d9138c
commit c193a703cc
2 changed files with 9 additions and 14 deletions

View File

@ -24,6 +24,7 @@
* AudioUriBuilder * AudioUriBuilder
* BackendApiForwarder * BackendApiForwarder
* ClipboardMonitor * ClipboardMonitor
* Database
* JsonSchema * JsonSchema
* Mecab * Mecab
* Translator * Translator
@ -43,7 +44,8 @@
class Backend { class Backend {
constructor() { constructor() {
this.translator = new Translator(); this.database = new Database();
this.translator = new Translator(this.database);
this.anki = new AnkiNull(); this.anki = new AnkiNull();
this.mecab = new Mecab(); this.mecab = new Mecab();
this.clipboardMonitor = new ClipboardMonitor({getClipboard: this._onApiClipboardGet.bind(this)}); this.clipboardMonitor = new ClipboardMonitor({getClipboard: this._onApiClipboardGet.bind(this)});
@ -107,6 +109,7 @@ class Backend {
} }
async prepare() { async prepare() {
await this.database.prepare();
await this.translator.prepare(); await this.translator.prepare();
this.optionsSchema = await requestJson(chrome.runtime.getURL('/bg/data/options-schema.json'), 'GET'); this.optionsSchema = await requestJson(chrome.runtime.getURL('/bg/data/options-schema.json'), 'GET');

View File

@ -17,7 +17,6 @@
*/ */
/* global /* global
* Database
* Deinflector * Deinflector
* dictEnabledSet * dictEnabledSet
* dictTagBuildSource * dictTagBuildSource
@ -34,23 +33,16 @@
*/ */
class Translator { class Translator {
constructor() { constructor(database) {
this.database = null; this.database = database;
this.deinflector = null; this.deinflector = null;
this.tagCache = new Map(); this.tagCache = new Map();
} }
async prepare() { async prepare() {
if (!this.database) { const url = chrome.runtime.getURL('/bg/lang/deinflect.json');
this.database = new Database(); const reasons = await requestJson(url, 'GET');
await this.database.prepare(); this.deinflector = new Deinflector(reasons);
}
if (!this.deinflector) {
const url = chrome.runtime.getURL('/bg/lang/deinflect.json');
const reasons = await requestJson(url, 'GET');
this.deinflector = new Deinflector(reasons);
}
} }
async purgeDatabase() { async purgeDatabase() {