diff options
-rw-r--r-- | src/background/index.js | 27 | ||||
-rw-r--r-- | src/messages/index.js | 4 | ||||
-rw-r--r-- | src/settings/index.js | 5 |
3 files changed, 19 insertions, 17 deletions
diff --git a/src/background/index.js b/src/background/index.js index 89d519c..5ae967c 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -6,7 +6,6 @@ import * as consoleActions from '../actions/console'; import * as tabActions from '../actions/tab'; import reducers from '../reducers'; import messages from '../messages'; -import DefaultSettings from './default-settings'; import * as store from '../store'; let prevInput = []; @@ -57,6 +56,14 @@ const keyQueueChanged = (state, 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: @@ -78,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(); } }; @@ -90,21 +99,7 @@ browser.runtime.onMessage.addListener((message, sender) => { }); const initializeSettings = () => { - browser.storage.local.get('settings').then((value) => { - let settings = {}; - if (value.settings && value.settings.json) { - settings = JSON.parse(value.settings.json); - } else { - settings = DefaultSettings; - browser.storage.local.set({ - settings: { - json: DefaultSettings - } - }); - } - let action = inputActions.setKeymaps(settings.keymaps); - backgroundStore.dispatch(action); - }, console.error); + reloadSettings(); }; initializeSettings(); diff --git a/src/messages/index.js b/src/messages/index.js index 4e34436..df9fba2 100644 --- a/src/messages/index.js +++ b/src/messages/index.js @@ -8,5 +8,7 @@ export default { KEYDOWN: 'keydown', - OPEN_URL: 'open.url' + OPEN_URL: 'open.url', + + SETTINGS_RELOAD: 'settings.reload', }; diff --git a/src/settings/index.js b/src/settings/index.js index e075385..2ed060c 100644 --- a/src/settings/index.js +++ b/src/settings/index.js @@ -1,4 +1,5 @@ import './settings.scss'; +import messages from '../messages'; document.addEventListener('DOMContentLoaded', () => { let form = document.getElementById('vimvixen-settings-form'); @@ -8,6 +9,10 @@ document.addEventListener('DOMContentLoaded', () => { settings: { json: e.target.elements['plain-json'].value } + }).then(() => { + return browser.runtime.sendMessage({ + type: messages.SETTINGS_RELOAD + }); }); }); |