aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/backend.js21
-rw-r--r--ext/bg/js/background-main.js3
-rw-r--r--ext/bg/js/settings/settings-controller.js15
-rw-r--r--ext/bg/js/util.js29
4 files changed, 10 insertions, 58 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index ceb1e257..54982098 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -80,7 +80,6 @@ class Backend {
['requestBackendReadySignal', {async: false, contentScript: true, handler: this._onApiRequestBackendReadySignal.bind(this)}],
['optionsGet', {async: false, contentScript: true, handler: this._onApiOptionsGet.bind(this)}],
['optionsGetFull', {async: false, contentScript: true, handler: this._onApiOptionsGetFull.bind(this)}],
- ['optionsSave', {async: true, contentScript: true, handler: this._onApiOptionsSave.bind(this)}],
['kanjiFind', {async: true, contentScript: true, handler: this._onApiKanjiFind.bind(this)}],
['termsFind', {async: true, contentScript: true, handler: this._onApiTermsFind.bind(this)}],
['textParse', {async: true, contentScript: true, handler: this._onApiTextParse.bind(this)}],
@@ -377,13 +376,6 @@ class Backend {
return this.getFullOptions();
}
- async _onApiOptionsSave({source}) {
- this._clearProfileConditionsSchemaCache();
- const options = this.getFullOptions();
- await this._optionsUtil.save(options);
- this._applyOptions(source);
- }
-
async _onApiKanjiFind({text, optionsContext}) {
const options = this.getOptions(optionsContext);
const definitions = await this._translator.findKanji(text, options);
@@ -766,7 +758,7 @@ class Backend {
results.push({error: errorToJson(e)});
}
}
- await this._onApiOptionsSave({source});
+ await this._saveOptions(source);
return results;
}
@@ -786,7 +778,7 @@ class Backend {
async _onApiSetAllSettings({value, source}) {
this._optionsUtil.validate(value);
this._options = clone(value);
- await this._onApiOptionsSave({source});
+ await this._saveOptions(source);
}
async _onApiGetOrCreateSearchPopup({focus=false, text=null}) {
@@ -879,7 +871,7 @@ class Backend {
const source = 'popup';
const options = this.getOptions({current: true});
options.general.enable = !options.general.enable;
- await this._onApiOptionsSave({source});
+ await this._saveOptions(source);
}
// Utilities
@@ -1731,4 +1723,11 @@ class Backend {
_triggerDatabaseUpdated(type, cause) {
this._sendMessageAllTabs('databaseUpdated', {type, cause});
}
+
+ async _saveOptions(source) {
+ this._clearProfileConditionsSchemaCache();
+ const options = this.getFullOptions();
+ await this._optionsUtil.save(options);
+ this._applyOptions(source);
+ }
}
diff --git a/ext/bg/js/background-main.js b/ext/bg/js/background-main.js
index 1b6bd138..6b64ad37 100644
--- a/ext/bg/js/background-main.js
+++ b/ext/bg/js/background-main.js
@@ -21,8 +21,5 @@
(() => {
const backend = new Backend();
- if (typeof window === 'object' && window !== null) {
- window.yomichanBackend = backend;
- }
backend.prepare();
})();
diff --git a/ext/bg/js/settings/settings-controller.js b/ext/bg/js/settings/settings-controller.js
index 4e61e05c..f4ddf6fb 100644
--- a/ext/bg/js/settings/settings-controller.js
+++ b/ext/bg/js/settings/settings-controller.js
@@ -17,8 +17,6 @@
/* global
* api
- * utilBackend
- * utilBackgroundIsolate
*/
class SettingsController extends EventDispatcher {
@@ -51,10 +49,6 @@ class SettingsController extends EventDispatcher {
await this._onOptionsUpdatedInternal();
}
- async save() {
- await api.optionsSave(this._source);
- }
-
async getOptions() {
const optionsContext = this.getOptionsContext();
return await api.optionsGet(optionsContext);
@@ -64,15 +58,6 @@ class SettingsController extends EventDispatcher {
return await api.optionsGetFull();
}
- async getOptionsMutable() {
- const optionsContext = this.getOptionsContext();
- return utilBackend().getOptions(utilBackgroundIsolate(optionsContext));
- }
-
- async getOptionsFullMutable() {
- return utilBackend().getFullOptions();
- }
-
async setAllSettings(value) {
const profileIndex = value.profileCurrent;
await api.setAllSettings(value, this._source);
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
deleted file mode 100644
index a0f31653..00000000
--- a/ext/bg/js/util.js
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2016-2020 Yomichan Authors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-function utilBackgroundIsolate(data) {
- const backgroundPage = chrome.extension.getBackgroundPage();
- return backgroundPage.clone(data);
-}
-
-function utilBackend() {
- const backend = chrome.extension.getBackgroundPage().yomichanBackend;
- if (!backend.isPrepared()) {
- throw new Error('Backend not ready yet');
- }
- return backend;
-}