From 7a85b203aca9b88a6e659987246a4b3915df2174 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 1 Oct 2017 13:37:27 +0900 Subject: [PATCH] load default settings --- src/actions/setting.js | 6 +++++- src/background/index.js | 8 +++++++- src/{background => shared}/default-settings.js | 6 ++++-- 3 files changed, 16 insertions(+), 4 deletions(-) rename src/{background => shared}/default-settings.js (97%) diff --git a/src/actions/setting.js b/src/actions/setting.js index d8e889e..7898f06 100644 --- a/src/actions/setting.js +++ b/src/actions/setting.js @@ -1,9 +1,13 @@ import actions from '../actions'; import messages from '../content/messages'; +import DefaultSettings from '../shared/default-settings'; const load = () => { return browser.storage.local.get('settings').then((value) => { - return set(value.settings); + if (value.settings) { + return set(value.settings); + } + return set(DefaultSettings); }, console.error); }; diff --git a/src/background/index.js b/src/background/index.js index 0e75a36..f2411c7 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -6,6 +6,7 @@ import * as consoleActions from '../actions/console'; import * as tabActions from '../actions/tab'; import reducers from '../reducers'; import messages from '../content/messages'; +import DefaultSettings from '../shared/default-settings'; import * as store from '../store'; let prevInput = []; @@ -58,7 +59,12 @@ const keyQueueChanged = (state, sender) => { const reloadSettings = () => { browser.storage.local.get('settings').then((value) => { - let settings = JSON.parse(value.settings.json); + let settings = null; + if (value.settings) { + settings = JSON.parse(value.settings.json); + } else { + settings = JSON.parse(DefaultSettings.json); + } let action = inputActions.setKeymaps(settings.keymaps); backgroundStore.dispatch(action); }, console.error); diff --git a/src/background/default-settings.js b/src/shared/default-settings.js similarity index 97% rename from src/background/default-settings.js rename to src/shared/default-settings.js index ea6318b..b186f95 100644 --- a/src/background/default-settings.js +++ b/src/shared/default-settings.js @@ -1,4 +1,5 @@ -export default `{ +export default { + json: `{ "keymaps": { "0": { "type": "scroll.home" }, ":": { "type": "command.show" }, @@ -36,4 +37,5 @@ export default `{ "gu": { "type": "navigate.parent" }, "gU": { "type": "navigate.root" } } -}`; +}` +};