aboutsummaryrefslogtreecommitdiff
path: root/src/background/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/index.js')
-rw-r--r--src/background/index.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/background/index.js b/src/background/index.js
index 9df22fd..5ae967c 100644
--- a/src/background/index.js
+++ b/src/background/index.js
@@ -41,7 +41,7 @@ backgroundStore.subscribe((sender) => {
const keyQueueChanged = (state, sender) => {
let prefix = keys.asKeymapChars(state.input.keys);
- let matched = Object.keys(keys.defaultKeymap).filter((keyStr) => {
+ let matched = Object.keys(state.input.keymaps).filter((keyStr) => {
return keyStr.startsWith(prefix);
});
if (matched.length === 0) {
@@ -51,11 +51,19 @@ const keyQueueChanged = (state, sender) => {
matched.length === 1 && prefix !== matched[0]) {
return Promise.resolve();
}
- let action = keys.defaultKeymap[matched];
+ let action = state.input.keymaps[matched];
backgroundStore.dispatch(operationActions.exec(action, sender.tab), sender);
backgroundStore.dispatch(inputActions.clearKeys(), sender);
};
+const reloadSettings = () => {
+ browser.storage.local.get('settings').then((value) => {
+ let settings = JSON.parse(value.settings.json);
+ let action = inputActions.setKeymaps(settings.keymaps);
+ backgroundStore.dispatch(action);
+ }, console.error);
+};
+
const handleMessage = (message, sender) => {
switch (message.type) {
case messages.KEYDOWN:
@@ -77,6 +85,8 @@ const handleMessage = (message, sender) => {
case messages.CONSOLE_CHANGEED:
return backgroundStore.dispatch(
commandActions.complete(message.text), sender);
+ case messages.SETTINGS_RELOAD:
+ return reloadSettings();
}
};
@@ -87,3 +97,9 @@ browser.runtime.onMessage.addListener((message, sender) => {
backgroundStore.dispatch(consoleActions.showError(e.message), sender);
}
});
+
+const initializeSettings = () => {
+ reloadSettings();
+};
+
+initializeSettings();