diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-13 22:36:56 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-13 22:36:56 +0900 |
commit | 944dea59199fa03f77e0e7c0d3c02acf8ccb458f (patch) | |
tree | 5f44471cdb32376a8c93e6f6eba738180f08c96f /src/content/actions | |
parent | 77b4e807e2a8b3e7ddb5f042719a34962a31b1c4 (diff) | |
parent | 28bfa3ac8124d3453cd539db26da4f4703e783df (diff) |
Merge remote-tracking branch 'origin/master' into greenkeeper/css-loader-1.0.0
Diffstat (limited to 'src/content/actions')
-rw-r--r-- | src/content/actions/addon.js | 22 | ||||
-rw-r--r-- | src/content/actions/index.js | 4 | ||||
-rw-r--r-- | src/content/actions/operation.js | 62 | ||||
-rw-r--r-- | src/content/actions/setting.js | 10 |
4 files changed, 64 insertions, 34 deletions
diff --git a/src/content/actions/addon.js b/src/content/actions/addon.js index 8d38025..b30cf16 100644 --- a/src/content/actions/addon.js +++ b/src/content/actions/addon.js @@ -1,15 +1,19 @@ +import messages from 'shared/messages'; import actions from 'content/actions'; -const enable = () => { - return { type: actions.ADDON_ENABLE }; -}; +const enable = () => setEnabled(true); -const disable = () => { - return { type: actions.ADDON_DISABLE }; -}; +const disable = () => setEnabled(false); -const toggleEnabled = () => { - return { type: actions.ADDON_TOGGLE_ENABLED }; +const setEnabled = async(enabled) => { + await browser.runtime.sendMessage({ + type: messages.ADDON_ENABLED_RESPONSE, + enabled, + }); + return { + type: actions.ADDON_SET_ENABLED, + enabled, + }; }; -export { enable, disable, toggleEnabled }; +export { enable, disable, setEnabled }; diff --git a/src/content/actions/index.js b/src/content/actions/index.js index 7e32e12..1c51ab0 100644 --- a/src/content/actions/index.js +++ b/src/content/actions/index.js @@ -1,8 +1,6 @@ export default { // Enable/disable - ADDON_ENABLE: 'addon.enable', - ADDON_DISABLE: 'addon.disable', - ADDON_TOGGLE_ENABLED: 'addon.toggle.enabled', + ADDON_SET_ENABLED: 'addon.set.enabled', // Settings SETTING_SET: 'setting.set', diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index 40ac52d..c1bd1c8 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -9,7 +9,7 @@ import * as addonActions from './addon'; import * as properties from 'shared/settings/properties'; // eslint-disable-next-line complexity, max-lines-per-function -const exec = (operation, repeat, settings) => { +const exec = (operation, repeat, settings, addonEnabled) => { let smoothscroll = settings.properties.smoothscroll || properties.defaults.smoothscroll; switch (operation.type) { @@ -18,60 +18,80 @@ const exec = (operation, repeat, settings) => { case operations.ADDON_DISABLE: return addonActions.disable(); case operations.ADDON_TOGGLE_ENABLED: - return addonActions.toggleEnabled(); + return addonActions.setEnabled(!addonEnabled); case operations.FIND_NEXT: - return window.top.postMessage(JSON.stringify({ + window.top.postMessage(JSON.stringify({ type: messages.FIND_NEXT, }), '*'); + break; case operations.FIND_PREV: - return window.top.postMessage(JSON.stringify({ + window.top.postMessage(JSON.stringify({ type: messages.FIND_PREV, }), '*'); + break; case operations.SCROLL_VERTICALLY: - return scrolls.scrollVertically(operation.count, smoothscroll, repeat); + scrolls.scrollVertically(operation.count, smoothscroll, repeat); + break; case operations.SCROLL_HORIZONALLY: - return scrolls.scrollHorizonally(operation.count, smoothscroll, repeat); + scrolls.scrollHorizonally(operation.count, smoothscroll, repeat); + break; case operations.SCROLL_PAGES: - return scrolls.scrollPages(operation.count, smoothscroll, repeat); + scrolls.scrollPages(operation.count, smoothscroll, repeat); + break; case operations.SCROLL_TOP: - return scrolls.scrollTop(smoothscroll, repeat); + scrolls.scrollTop(smoothscroll, repeat); + break; case operations.SCROLL_BOTTOM: - return scrolls.scrollBottom(smoothscroll, repeat); + scrolls.scrollBottom(smoothscroll, repeat); + break; case operations.SCROLL_HOME: - return scrolls.scrollHome(smoothscroll, repeat); + scrolls.scrollHome(smoothscroll, repeat); + break; case operations.SCROLL_END: - return scrolls.scrollEnd(smoothscroll, repeat); + scrolls.scrollEnd(smoothscroll, repeat); + break; case operations.FOLLOW_START: - return window.top.postMessage(JSON.stringify({ + window.top.postMessage(JSON.stringify({ type: messages.FOLLOW_START, newTab: operation.newTab, background: operation.background, }), '*'); + break; case operations.NAVIGATE_HISTORY_PREV: - return navigates.historyPrev(window); + navigates.historyPrev(window); + break; case operations.NAVIGATE_HISTORY_NEXT: - return navigates.historyNext(window); + navigates.historyNext(window); + break; case operations.NAVIGATE_LINK_PREV: - return navigates.linkPrev(window); + navigates.linkPrev(window); + break; case operations.NAVIGATE_LINK_NEXT: - return navigates.linkNext(window); + navigates.linkNext(window); + break; case operations.NAVIGATE_PARENT: - return navigates.parent(window); + navigates.parent(window); + break; case operations.NAVIGATE_ROOT: - return navigates.root(window); + navigates.root(window); + break; case operations.FOCUS_INPUT: - return focuses.focusInput(); + focuses.focusInput(); + break; case operations.URLS_YANK: urls.yank(window); - return consoleFrames.postInfo(window.document, 'Current url yanked'); + consoleFrames.postInfo(window.document, 'Current url yanked'); + break; case operations.URLS_PASTE: - return urls.paste(window, operation.newTab ? operation.newTab : false); + urls.paste(window, operation.newTab ? operation.newTab : false); + break; default: browser.runtime.sendMessage({ type: messages.BACKGROUND_OPERATION, operation, }); } + return { type: '' }; }; export { exec }; diff --git a/src/content/actions/setting.js b/src/content/actions/setting.js index e34b6e0..1c15dd7 100644 --- a/src/content/actions/setting.js +++ b/src/content/actions/setting.js @@ -1,6 +1,7 @@ import actions from 'content/actions'; import * as keyUtils from 'shared/utils/keys'; import operations from 'shared/operations'; +import messages from 'shared/messages'; const reservedKeymaps = { '<Esc>': { type: operations.CANCEL }, @@ -26,4 +27,11 @@ const set = (value) => { }; }; -export { set }; +const load = async() => { + let settings = await browser.runtime.sendMessage({ + type: messages.SETTINGS_QUERY, + }); + return set(settings); +}; + +export { set, load }; |