summaryrefslogtreecommitdiff
path: root/ext/bg/js/settings/main.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-05-30 09:33:13 -0400
committerGitHub <noreply@github.com>2020-05-30 09:33:13 -0400
commit63a3e56367b95f7ea64a5701d17179de60ed8718 (patch)
treefc811028b127abf9c1ff1dbdbb4663ba70b60649 /ext/bg/js/settings/main.js
parent1a5a37c9e47dc4d1f1e1b3ffaf990e792140b912 (diff)
Use SettingsController (#576)
* Use settingsController internally in settings/main.js * Replace modifyingProfileChange with SettingsController.optionsContextChanged * Update ClipboardPopupsController to use SettingsController * Store reference to checkbox * Use this._settingsController for everything * Change where current profile is initially assigned from * Remove some unnecessary async calls * Move setup calls * Update AnkiTemplatesController to use SettingsController * Cache default field templates * Update AnkiController to use SettingsController * Update AudioController to use SettingsController * Update SettingsBackup to use SettingsController * Update DictionaryController to use SettingsController * Update GenericSettingController to use SettingsController * Update ProfileController to use SettingsController * Remove unused * Remove unused * Replace some uses of api.options* functions * Fix missing awaits * Fix invalid function
Diffstat (limited to 'ext/bg/js/settings/main.js')
-rw-r--r--ext/bg/js/settings/main.js97
1 files changed, 14 insertions, 83 deletions
diff --git a/ext/bg/js/settings/main.js b/ext/bg/js/settings/main.js
index d6f55bde..cf74c0fc 100644
--- a/ext/bg/js/settings/main.js
+++ b/ext/bg/js/settings/main.js
@@ -28,71 +28,8 @@
* SettingsController
* StorageController
* api
- * utilBackend
- * utilBackgroundIsolate
*/
-let profileIndex = 0;
-
-function getOptionsContext() {
- return {index: getProfileIndex()};
-}
-
-function getProfileIndex() {
- return profileIndex;
-}
-
-function setProfileIndex(value) {
- profileIndex = value;
-}
-
-
-function getOptionsMutable(optionsContext) {
- return utilBackend().getOptions(
- utilBackgroundIsolate(optionsContext)
- );
-}
-
-function getOptionsFullMutable() {
- return utilBackend().getFullOptions();
-}
-
-
-function settingsGetSource() {
- return new Promise((resolve) => {
- chrome.tabs.getCurrent((tab) => resolve(`settings${tab ? tab.id : ''}`));
- });
-}
-
-async function settingsSaveOptions() {
- const source = await settingsGetSource();
- await api.optionsSave(source);
-}
-
-async function onOptionsUpdated({source}) {
- const thisSource = await settingsGetSource();
- if (source === thisSource) { return; }
-
- const optionsContext = getOptionsContext();
- const options = await getOptionsMutable(optionsContext);
-
- document.querySelector('#enable-clipboard-popups').checked = options.general.enableClipboardPopups;
- if (ankiTemplatesController !== null) {
- ankiTemplatesController.updateValue();
- }
- if (dictionaryController !== null) {
- dictionaryController.optionsChanged();
- }
- if (ankiController !== null) {
- ankiController.optionsChanged();
- }
-
- if (genericSettingController !== null) {
- genericSettingController.optionsChanged(options);
- }
-}
-
-
function showExtensionInformation() {
const node = document.getElementById('extension-info');
if (node === null) { return; }
@@ -124,40 +61,34 @@ async function setupEnvironmentInfo() {
document.documentElement.dataset.operatingSystem = platform.os;
}
-let ankiController = null;
-let ankiTemplatesController = null;
-let dictionaryController = null;
-let genericSettingController = null;
async function onReady() {
api.forwardLogsToBackend();
await yomichan.prepare();
- const settingsController = new SettingsController();
- settingsController.prepare();
-
setupEnvironmentInfo();
showExtensionInformation();
+ settingsPopulateModifierKeys();
+
+ const optionsFull = await api.optionsGetFull();
+ const settingsController = new SettingsController(optionsFull.profileCurrent);
+ settingsController.prepare();
const storageController = new StorageController();
storageController.prepare();
- await settingsPopulateModifierKeys();
- genericSettingController = new GenericSettingController();
+ const genericSettingController = new GenericSettingController(settingsController);
genericSettingController.prepare();
- new ClipboardPopupsController().prepare();
- new PopupPreviewController().prepare();
- new AudioController().prepare();
- await (new ProfileController()).prepare();
- dictionaryController = new DictionaryController(storageController);
+ new ClipboardPopupsController(settingsController).prepare();
+ new PopupPreviewController(settingsController).prepare();
+ new AudioController(settingsController).prepare();
+ new ProfileController(settingsController).prepare();
+ const dictionaryController = new DictionaryController(settingsController, storageController);
dictionaryController.prepare();
- ankiController = new AnkiController();
+ const ankiController = new AnkiController(settingsController);
ankiController.prepare();
- ankiTemplatesController = new AnkiTemplatesController(ankiController);
- ankiTemplatesController.prepare();
- new SettingsBackup().prepare();
-
- yomichan.on('optionsUpdated', onOptionsUpdated);
+ new AnkiTemplatesController(settingsController, ankiController).prepare();
+ new SettingsBackup(settingsController).prepare();
}
$(document).ready(() => onReady());