Initialize default settings on background

This commit is contained in:
Shin'ya Ueoka 2017-09-28 21:02:47 +09:00
parent e97ffafea3
commit e3f95f9ecf
4 changed files with 57 additions and 59 deletions

View file

@ -6,7 +6,7 @@ import * as consoleActions from '../actions/console';
import * as tabActions from '../actions/tab';
import reducers from '../reducers';
import messages from '../messages';
import DefaultSettings from '../settings/default-settings';
import DefaultSettings from './default-settings';
import * as store from '../store';
let prevInput = [];
@ -92,10 +92,15 @@ browser.runtime.onMessage.addListener((message, sender) => {
const initializeSettings = () => {
browser.storage.local.get('settings').then((value) => {
let settings = {};
if (value.settings.json) {
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);