aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/background.js27
-rw-r--r--src/components/content-input.js2
-rw-r--r--src/content/index.js15
-rw-r--r--src/content/messages.js3
4 files changed, 25 insertions, 22 deletions
diff --git a/src/components/background.js b/src/components/background.js
index 79a7a6a..4961d85 100644
--- a/src/components/background.js
+++ b/src/components/background.js
@@ -19,8 +19,6 @@ export default class BackgroundComponent {
});
}
});
- browser.tabs.onUpdated.addListener(this.onTabUpdated.bind(this));
- browser.tabs.onActivated.addListener(this.onTabActivated.bind(this));
}
update() {
@@ -59,28 +57,23 @@ export default class BackgroundComponent {
text: e.message,
});
});
+ case messages.SETTINGS_QUERY:
+ return Promise.resolve(this.store.getState().setting.settings);
case messages.CONSOLE_QUERY_COMPLETIONS:
return commands.complete(message.text, this.settings);
case messages.SETTINGS_RELOAD:
this.store.dispatch(settingsActions.load());
+ return this.broadcastSettingsChanged();
}
}
- onTabActivated(info) {
- this.syncSettings(info.tabId);
- }
-
- onTabUpdated(id, info) {
- if (info.status === 'complete') {
- this.syncSettings(id);
- }
- }
-
- syncSettings(id) {
- let { settings } = this.store.getState().setting;
- return browser.tabs.sendMessage(id, {
- type: messages.CONTENT_SET_SETTINGS,
- settings,
+ broadcastSettingsChanged() {
+ return browser.tabs.query({}).then((tabs) => {
+ for (let tab of tabs) {
+ browser.tabs.sendMessage(tab.id, {
+ type: messages.SETTINGS_CHANGED,
+ });
+ }
});
}
}
diff --git a/src/components/content-input.js b/src/components/content-input.js
index 1dbf48f..504835c 100644
--- a/src/components/content-input.js
+++ b/src/components/content-input.js
@@ -13,7 +13,7 @@ export default class ContentInputComponent {
update() {
let settings = this.store.getState().setting.settings;
- if (!settings) {
+ if (!settings || !settings.json) {
return;
}
let input = this.store.getState().input;
diff --git a/src/content/index.js b/src/content/index.js
index 09143b0..a2e3e3d 100644
--- a/src/content/index.js
+++ b/src/content/index.js
@@ -21,16 +21,25 @@ store.subscribe(() => {
consoleFrames.initialize(window.document);
+const reloadSettings = () => {
+ return browser.runtime.sendMessage({
+ type: messages.SETTINGS_QUERY,
+ }).then((settings) => {
+ store.dispatch(settingActions.set(settings));
+ });
+};
+
browser.runtime.onMessage.addListener((action) => {
switch (action.type) {
case messages.CONSOLE_HIDE:
window.focus();
consoleFrames.blur(window.document);
return Promise.resolve();
- case messages.CONTENT_SET_SETTINGS:
- store.dispatch(settingActions.set(action.settings));
- return Promise.resolve();
+ case messages.SETTINGS_CHANGED:
+ return reloadSettings();
default:
return Promise.resolve();
}
});
+
+reloadSettings();
diff --git a/src/content/messages.js b/src/content/messages.js
index eb056a7..138f0e0 100644
--- a/src/content/messages.js
+++ b/src/content/messages.js
@@ -1,5 +1,6 @@
export default {
- CONTENT_SET_SETTINGS: 'content.set.settings',
+ SETTINGS_QUERY: 'settings.query',
+
BACKGROUND_OPERATION: 'background.operation',
CONSOLE_BLURRED: 'console.blured',