aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/settings
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-04-26 22:33:50 +0300
committerGitHub <noreply@github.com>2020-04-26 22:33:50 +0300
commitca033a87a0d302151b430acfdf9d480514c14aed (patch)
treeebb783c7bd371a6859c25009a57799d70ac73bac /ext/bg/js/settings
parenta49e4ccc4e5c7defb30bd88535c18137acf9812c (diff)
Update Popup and DisplayFloat optionsContext from Frontend (#464)
* set optionsContext from Frontend * update Popup+Display options on Frontend change * remove popup setOptions * only update DisplayFloat options from Frontend * fix optionsContext usage * fix preview frame arguments * keep Frontend URL up to date * cache url * fix preview frame * trigger modifyingProfileChange in correct places * remove async from function not using await * refactor optionsContext in Frontend
Diffstat (limited to 'ext/bg/js/settings')
-rw-r--r--ext/bg/js/settings/popup-preview-frame-main.js5
-rw-r--r--ext/bg/js/settings/popup-preview-frame.js22
-rw-r--r--ext/bg/js/settings/popup-preview.js18
-rw-r--r--ext/bg/js/settings/profiles.js10
4 files changed, 47 insertions, 8 deletions
diff --git a/ext/bg/js/settings/popup-preview-frame-main.js b/ext/bg/js/settings/popup-preview-frame-main.js
index 86c2814c..2ab6af6b 100644
--- a/ext/bg/js/settings/popup-preview-frame-main.js
+++ b/ext/bg/js/settings/popup-preview-frame-main.js
@@ -19,7 +19,6 @@
* SettingsPopupPreview
*/
-(async () => {
- const instance = new SettingsPopupPreview();
- await instance.prepare();
+(() => {
+ new SettingsPopupPreview();
})();
diff --git a/ext/bg/js/settings/popup-preview-frame.js b/ext/bg/js/settings/popup-preview-frame.js
index 420a7c5a..05a2a41b 100644
--- a/ext/bg/js/settings/popup-preview-frame.js
+++ b/ext/bg/js/settings/popup-preview-frame.js
@@ -32,19 +32,24 @@ class SettingsPopupPreview {
this.popupShown = false;
this.themeChangeTimeout = null;
this.textSource = null;
+ this.optionsContext = null;
this._targetOrigin = chrome.runtime.getURL('/').replace(/\/$/, '');
this._windowMessageHandlers = new Map([
+ ['prepare', ({optionsContext}) => this.prepare(optionsContext)],
['setText', ({text}) => this.setText(text)],
['setCustomCss', ({css}) => this.setCustomCss(css)],
- ['setCustomOuterCss', ({css}) => this.setCustomOuterCss(css)]
+ ['setCustomOuterCss', ({css}) => this.setCustomOuterCss(css)],
+ ['updateOptionsContext', ({optionsContext}) => this.updateOptionsContext(optionsContext)]
]);
- }
- async prepare() {
- // Setup events
window.addEventListener('message', this.onMessage.bind(this), false);
+ }
+
+ async prepare(optionsContext) {
+ this.optionsContext = optionsContext;
+ // Setup events
document.querySelector('#theme-dark-checkbox').addEventListener('change', this.onThemeDarkCheckboxChanged.bind(this), false);
// Overwrite API functions
@@ -62,8 +67,9 @@ class SettingsPopupPreview {
this.frontend = new Frontend(this.popup);
+ this.frontend.getOptionsContext = async () => this.optionsContext;
this.frontend.setEnabled = () => {};
- this.frontend.searchClear = () => {};
+ this.frontend.onSearchClear = () => {};
await this.frontend.prepare();
@@ -145,6 +151,12 @@ class SettingsPopupPreview {
this.frontend.popup.setCustomOuterCss(css, false);
}
+ async updateOptionsContext(optionsContext) {
+ this.optionsContext = optionsContext;
+ await this.frontend.updateOptions();
+ await this.updateSearch();
+ }
+
async updateSearch() {
const exampleText = document.querySelector('#example-text');
if (exampleText === null) { return; }
diff --git a/ext/bg/js/settings/popup-preview.js b/ext/bg/js/settings/popup-preview.js
index 45bf531e..fdc3dd94 100644
--- a/ext/bg/js/settings/popup-preview.js
+++ b/ext/bg/js/settings/popup-preview.js
@@ -16,6 +16,7 @@
*/
/* global
+ * getOptionsContext
* wanakana
*/
@@ -60,6 +61,23 @@ function showAppearancePreview() {
frame.contentWindow.postMessage({action, params}, targetOrigin);
});
+ const updateOptionsContext = () => {
+ const action = 'updateOptionsContext';
+ const params = {
+ optionsContext: getOptionsContext()
+ };
+ frame.contentWindow.postMessage({action, params}, targetOrigin);
+ };
+ yomichan.on('modifyingProfileChange', updateOptionsContext);
+
+ frame.addEventListener('load', () => {
+ const action = 'prepare';
+ const params = {
+ optionsContext: getOptionsContext()
+ };
+ frame.contentWindow.postMessage({action, params}, targetOrigin);
+ });
+
container.append(frame);
buttonContainer.remove();
settings.css('display', '');
diff --git a/ext/bg/js/settings/profiles.js b/ext/bg/js/settings/profiles.js
index 867b17aa..3f4b1da7 100644
--- a/ext/bg/js/settings/profiles.js
+++ b/ext/bg/js/settings/profiles.js
@@ -190,6 +190,8 @@ async function onTargetProfileChanged() {
currentProfileIndex = index;
await profileOptionsUpdateTarget(optionsFull);
+
+ yomichan.trigger('modifyingProfileChange');
}
async function onProfileAdd() {
@@ -197,9 +199,13 @@ async function onProfileAdd() {
const profile = utilBackgroundIsolate(optionsFull.profiles[currentProfileIndex]);
profile.name = profileOptionsCreateCopyName(profile.name, optionsFull.profiles, 100);
optionsFull.profiles.push(profile);
+
currentProfileIndex = optionsFull.profiles.length - 1;
+
await profileOptionsUpdateTarget(optionsFull);
await settingsSaveOptions();
+
+ yomichan.trigger('modifyingProfileChange');
}
async function onProfileRemove(e) {
@@ -238,6 +244,8 @@ async function onProfileRemoveConfirm() {
await profileOptionsUpdateTarget(optionsFull);
await settingsSaveOptions();
+
+ yomichan.trigger('modifyingProfileChange');
}
function onProfileNameChanged() {
@@ -263,6 +271,8 @@ async function onProfileMove(offset) {
await profileOptionsUpdateTarget(optionsFull);
await settingsSaveOptions();
+
+ yomichan.trigger('modifyingProfileChange');
}
async function onProfileCopy() {