diff options
Diffstat (limited to 'src/background')
-rw-r--r-- | src/background/default-settings.js | 39 | ||||
-rw-r--r-- | src/background/index.js | 20 | ||||
-rw-r--r-- | src/background/keys.js | 42 |
3 files changed, 58 insertions, 43 deletions
diff --git a/src/background/default-settings.js b/src/background/default-settings.js new file mode 100644 index 0000000..ea6318b --- /dev/null +++ b/src/background/default-settings.js @@ -0,0 +1,39 @@ +export default `{ + "keymaps": { + "0": { "type": "scroll.home" }, + ":": { "type": "command.show" }, + "o": { "type": "command.show.open", "alter": false }, + "O": { "type": "command.show.open", "alter": true }, + "t": { "type": "command.show.tabopen", "alter": false }, + "T": { "type": "command.show.tabopen", "alter": true }, + "b": { "type": "command.show.buffer" }, + "k": { "type": "scroll.lines", "count": -1 }, + "j": { "type": "scroll.lines", "count": 1 }, + "<C-E>": { "type": "scroll.lines", "count": -1 }, + "<C-Y>": { "type": "scroll.lines", "count": 1 }, + "<C-U>": { "type": "scroll.pages", "count": -0.5 }, + "<C-D>": { "type": "scroll.pages", "count": 0.5 }, + "<C-B>": { "type": "scroll.pages", "count": -1 }, + "<C-F>": { "type": "scroll.pages", "count": 1 }, + "gg": { "type": "scroll.top" }, + "G": { "type": "scroll.bottom" }, + "$": { "type": "scroll.end" }, + "d": { "type": "tabs.close" }, + "u": { "type": "tabs.reopen" }, + "h": { "type": "tabs.prev", "count": 1 }, + "l": { "type": "tabs.next", "count": 1 }, + "r": { "type": "tabs.reload", "cache": false }, + "R": { "type": "tabs.reload", "cache": true }, + "zi": { "type": "zoom.in" }, + "zo": { "type": "zoom.out" }, + "zz": { "type": "zoom.neutral" }, + "f": { "type": "follow.start", "newTab": false }, + "F": { "type": "follow.start", "newTab": true }, + "H": { "type": "navigate.history.prev" }, + "L": { "type": "navigate.history.next" }, + "[[": { "type": "navigate.link.prev" }, + "]]": { "type": "navigate.link.next" }, + "gu": { "type": "navigate.parent" }, + "gU": { "type": "navigate.root" } + } +}`; 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(); diff --git a/src/background/keys.js b/src/background/keys.js index e4a8b19..aca050e 100644 --- a/src/background/keys.js +++ b/src/background/keys.js @@ -1,43 +1,3 @@ -import operations from '../operations'; - -const defaultKeymap = { - ':': { type: operations.COMMAND_OPEN }, - 'o': { type: operations.COMMAND_TABS_OPEN, alter: false }, - 'O': { type: operations.COMMAND_TABS_OPEN, alter: true }, - 't': { type: operations.COMMAND_TABS_NEW, alter: false }, - 'T': { type: operations.COMMAND_TABS_NEW, alter: true }, - 'b': { type: operations.COMMAND_BUFFER }, - 'k': { type: operations.SCROLL_LINES, count: -1 }, - 'j': { type: operations.SCROLL_LINES, count: 1 }, - '<C-E>': { type: operations.SCROLL_LINES, count: -1 }, - '<C-Y>': { type: operations.SCROLL_LINES, count: 1 }, - '<C-U>': { type: operations.SCROLL_PAGES, count: -0.5 }, - '<C-D>': { type: operations.SCROLL_PAGES, count: 0.5 }, - '<C-B>': { type: operations.SCROLL_PAGES, count: -1 }, - '<C-F>': { type: operations.SCROLL_PAGES, count: 1 }, - 'gg': { type: operations.SCROLL_TOP }, - 'G': { type: operations.SCROLL_BOTTOM }, - '0': { type: operations.SCROLL_LEFT }, - '$': { type: operations.SCROLL_RIGHT }, - 'd': { type: operations.TABS_CLOSE }, - 'u': { type: operations.TABS_REOPEN }, - 'h': { type: operations.TABS_PREV, count: 1 }, - 'l': { type: operations.TABS_NEXT, count: 1 }, - 'r': { type: operations.TABS_RELOAD, cache: false }, - 'R': { type: operations.TABS_RELOAD, cache: true }, - 'zi': { type: operations.ZOOM_IN }, - 'zo': { type: operations.ZOOM_OUT }, - 'zz': { type: operations.ZOOM_NEUTRAL }, - 'f': { type: operations.FOLLOW_START, newTab: false }, - 'F': { type: operations.FOLLOW_START, newTab: true }, - 'H': { type: operations.NAVIGATE_HISTORY_PREV }, - 'L': { type: operations.NAVIGATE_HISTORY_NEXT }, - '[[': { type: operations.NAVIGATE_LINK_PREV }, - ']]': { type: operations.NAVIGATE_LINK_NEXT }, - 'gu': { type: operations.NAVIGATE_PARENT }, - 'gU': { type: operations.NAVIGATE_ROOT }, -}; - const asKeymapChars = (keys) => { return keys.map((k) => { let c = String.fromCharCode(k.code); @@ -58,4 +18,4 @@ const asCaretChars = (keys) => { }).join(''); }; -export { defaultKeymap, asKeymapChars, asCaretChars }; +export { asKeymapChars, asCaretChars }; |