Cleanup unused utils (#832)
* Remove api.optionsSave * Remove getOptionsMutable and getOptionsFullMutable * Remove util.js * Remove yomichanBackend
This commit is contained in:
parent
f997f01742
commit
79ef6e151e
@ -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>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,5 @@
|
||||
|
||||
(() => {
|
||||
const backend = new Backend();
|
||||
if (typeof window === 'object' && window !== null) {
|
||||
window.yomichanBackend = backend;
|
||||
}
|
||||
backend.prepare();
|
||||
})();
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
@ -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>
|
||||
|
@ -57,10 +57,6 @@ const api = (() => {
|
||||
return this._invoke('optionsGetFull');
|
||||
}
|
||||
|
||||
optionsSave(source) {
|
||||
return this._invoke('optionsSave', {source});
|
||||
}
|
||||
|
||||
termsFind(text, details, optionsContext) {
|
||||
return this._invoke('termsFind', {text, details, optionsContext});
|
||||
}
|
||||
|
@ -192,11 +192,6 @@ const clone = (() => {
|
||||
return clone;
|
||||
})();
|
||||
|
||||
// Expose clone function on the global object, since util.js's utilBackgroundIsolate needs access to it.
|
||||
if (typeof window === 'object' && window !== null) {
|
||||
window.clone = clone;
|
||||
}
|
||||
|
||||
function generateId(length) {
|
||||
const array = new Uint8Array(length);
|
||||
crypto.getRandomValues(array);
|
||||
|
Loading…
Reference in New Issue
Block a user