summaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-09-15 19:48:58 -0400
committerGitHub <noreply@github.com>2020-09-15 19:48:58 -0400
commit79ef6e151edec51b2484cdc00242dde71958ab3b (patch)
treec16519757900ac6dfc5678982ddfb48ef49da21b /ext/bg
parentf997f017422bba2527e620000e3a938b916f25ac (diff)
Cleanup unused utils (#832)
* Remove api.optionsSave * Remove getOptionsMutable and getOptionsFullMutable * Remove util.js * Remove yomichanBackend
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/background.html1
-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
-rw-r--r--ext/bg/settings.html1
6 files changed, 10 insertions, 60 deletions
diff --git a/ext/bg/background.html b/ext/bg/background.html
index 2f3fd441..57871242 100644
--- a/ext/bg/background.html
+++ b/ext/bg/background.html
@@ -38,7 +38,6 @@
<script src="/bg/js/simple-dom-parser.js"></script>
<script src="/bg/js/text-source-map.js"></script>
<script src="/bg/js/translator.js"></script>
- <script src="/bg/js/util.js"></script>
<script src="/mixed/js/cache-map.js"></script>
<script src="/mixed/js/audio-system.js"></script>
<script src="/mixed/js/dictionary-data-util.js"></script>
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;
-}
diff --git a/ext/bg/settings.html b/ext/bg/settings.html
index f46282e5..208f3d3f 100644
--- a/ext/bg/settings.html
+++ b/ext/bg/settings.html
@@ -1209,7 +1209,6 @@
<script src="/bg/js/anki.js"></script>
<script src="/bg/js/anki-note-builder.js"></script>
<script src="/bg/js/options.js"></script>
- <script src="/bg/js/util.js"></script>
<script src="/bg/js/database.js"></script>
<script src="/bg/js/dictionary-database.js"></script>
<script src="/bg/js/dictionary-importer.js"></script>