From b69cc04856fd21d325193d56e212e4dbf07cb762 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 11 Jul 2018 21:01:22 +0900 Subject: Use combineReducers --- src/background/reducers/index.js | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'src/background') diff --git a/src/background/reducers/index.js b/src/background/reducers/index.js index 78f855c..465f927 100644 --- a/src/background/reducers/index.js +++ b/src/background/reducers/index.js @@ -1,17 +1,8 @@ -import settingReducer from './setting'; -import findReducer from './find'; -import tabReducer from './tab'; +import { combineReducers } from 'redux'; +import setting from './setting'; +import find from './find'; +import tab from './tab'; -// Make setting reducer instead of re-use -const defaultState = { - setting: settingReducer(undefined, {}), - find: findReducer(undefined, {}), - tab: tabReducer(undefined, {}), -}; - -export default function reducer(state = defaultState, action = {}) { - return { ...state, - setting: settingReducer(state.setting, action), - find: findReducer(state.find, action), - tab: tabReducer(state.tab, action), }; -} +export default combineReducers({ + setting, find, tab, +}); -- cgit v1.2.3 From 067da88d06fbffca323ecdbaf8b1011f88225219 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 11 Jul 2018 21:01:48 +0900 Subject: Move versions to background --- src/background/index.js | 2 +- src/background/shared/versions/index.js | 38 +++++++++++++++++++++++ src/background/shared/versions/release-notes.js | 8 +++++ src/background/shared/versions/storage.js | 10 +++++++ src/shared/versions/index.js | 38 ----------------------- src/shared/versions/release-notes.js | 8 ----- src/shared/versions/storage.js | 10 ------- test/background/shared/versions/index.test.js | 40 +++++++++++++++++++++++++ test/background/shared/versions/storage.test.js | 28 +++++++++++++++++ test/shared/versions/index.test.js | 40 ------------------------- test/shared/versions/storage.test.js | 28 ----------------- 11 files changed, 125 insertions(+), 125 deletions(-) create mode 100644 src/background/shared/versions/index.js create mode 100644 src/background/shared/versions/release-notes.js create mode 100644 src/background/shared/versions/storage.js delete mode 100644 src/shared/versions/index.js delete mode 100644 src/shared/versions/release-notes.js delete mode 100644 src/shared/versions/storage.js create mode 100644 test/background/shared/versions/index.test.js create mode 100644 test/background/shared/versions/storage.test.js delete mode 100644 test/shared/versions/index.test.js delete mode 100644 test/shared/versions/storage.test.js (limited to 'src/background') diff --git a/src/background/index.js b/src/background/index.js index 8c4eafc..1e4c078 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -6,7 +6,7 @@ import IndicatorComponent from 'background/components/indicator'; import reducers from 'background/reducers'; import { createStore, applyMiddleware } from 'redux'; import promise from 'redux-promise'; -import * as versions from 'shared/versions'; +import * as versions from './shared/versions'; const store = createStore( reducers, diff --git a/src/background/shared/versions/index.js b/src/background/shared/versions/index.js new file mode 100644 index 0000000..aa09c92 --- /dev/null +++ b/src/background/shared/versions/index.js @@ -0,0 +1,38 @@ +import * as storage from './storage'; +import * as releaseNotes from './release-notes'; +import manifest from '../../../../manifest.json'; + +const NOTIFICATION_ID = 'vimvixen-update'; + +const notificationClickListener = (id) => { + if (id !== NOTIFICATION_ID) { + return; + } + + browser.tabs.create({ url: releaseNotes.url(manifest.version) }); + browser.notifications.onClicked.removeListener(notificationClickListener); +}; + +const checkUpdated = async() => { + let prev = await storage.load(); + if (!prev) { + return true; + } + return manifest.version !== prev; +}; + +const notify = () => { + browser.notifications.onClicked.addListener(notificationClickListener); + return browser.notifications.create(NOTIFICATION_ID, { + 'type': 'basic', + 'iconUrl': browser.extension.getURL('resources/icon_48x48.png'), + 'title': 'Vim Vixen ' + manifest.version + ' has been installed', + 'message': 'Click here to see release notes', + }); +}; + +const commit = () => { + storage.save(manifest.version); +}; + +export { checkUpdated, notify, commit }; diff --git a/src/background/shared/versions/release-notes.js b/src/background/shared/versions/release-notes.js new file mode 100644 index 0000000..6ef2335 --- /dev/null +++ b/src/background/shared/versions/release-notes.js @@ -0,0 +1,8 @@ +const url = (version) => { + if (version) { + return 'https://github.com/ueokande/vim-vixen/releases/tag/' + version; + } + return 'https://github.com/ueokande/vim-vixen/releases/'; +}; + +export { url }; diff --git a/src/background/shared/versions/storage.js b/src/background/shared/versions/storage.js new file mode 100644 index 0000000..7883258 --- /dev/null +++ b/src/background/shared/versions/storage.js @@ -0,0 +1,10 @@ +const load = async() => { + let { version } = await browser.storage.local.get('version'); + return version; +}; + +const save = (version) => { + return browser.storage.local.set({ version }); +}; + +export { load, save }; diff --git a/src/shared/versions/index.js b/src/shared/versions/index.js deleted file mode 100644 index ba3d183..0000000 --- a/src/shared/versions/index.js +++ /dev/null @@ -1,38 +0,0 @@ -import * as storage from './storage'; -import * as releaseNotes from './release-notes'; -import manifest from '../../../manifest.json'; - -const NOTIFICATION_ID = 'vimvixen-update'; - -const notificationClickListener = (id) => { - if (id !== NOTIFICATION_ID) { - return; - } - - browser.tabs.create({ url: releaseNotes.url(manifest.version) }); - browser.notifications.onClicked.removeListener(notificationClickListener); -}; - -const checkUpdated = async() => { - let prev = await storage.load(); - if (!prev) { - return true; - } - return manifest.version !== prev; -}; - -const notify = () => { - browser.notifications.onClicked.addListener(notificationClickListener); - return browser.notifications.create(NOTIFICATION_ID, { - 'type': 'basic', - 'iconUrl': browser.extension.getURL('resources/icon_48x48.png'), - 'title': 'Vim Vixen ' + manifest.version + ' has been installed', - 'message': 'Click here to see release notes', - }); -}; - -const commit = () => { - storage.save(manifest.version); -}; - -export { checkUpdated, notify, commit }; diff --git a/src/shared/versions/release-notes.js b/src/shared/versions/release-notes.js deleted file mode 100644 index 6ef2335..0000000 --- a/src/shared/versions/release-notes.js +++ /dev/null @@ -1,8 +0,0 @@ -const url = (version) => { - if (version) { - return 'https://github.com/ueokande/vim-vixen/releases/tag/' + version; - } - return 'https://github.com/ueokande/vim-vixen/releases/'; -}; - -export { url }; diff --git a/src/shared/versions/storage.js b/src/shared/versions/storage.js deleted file mode 100644 index 7883258..0000000 --- a/src/shared/versions/storage.js +++ /dev/null @@ -1,10 +0,0 @@ -const load = async() => { - let { version } = await browser.storage.local.get('version'); - return version; -}; - -const save = (version) => { - return browser.storage.local.set({ version }); -}; - -export { load, save }; diff --git a/test/background/shared/versions/index.test.js b/test/background/shared/versions/index.test.js new file mode 100644 index 0000000..d65dd9a --- /dev/null +++ b/test/background/shared/versions/index.test.js @@ -0,0 +1,40 @@ +import * as versions from 'background/shared/versions'; +import manifest from '../../../../manifest.json'; + +describe("shared/versions/storage", () => { + describe('#checkUpdated', () => { + beforeEach(() => { + return browser.storage.local.remove('version'); + }); + + it('return true if no previous versions', async() => { + let updated = await versions.checkUpdated(); + expect(updated).to.be.true; + }); + + it('return true if updated', async() => { + await browser.storage.local.set({ version: '0.001' }); + let updated = await versions.checkUpdated(); + expect(updated).to.be.true; + }); + + it('return false if not updated', async() => { + await browser.storage.local.set({ version: manifest.version }); + let updated = await versions.checkUpdated(); + expect(updated).to.be.false; + }); + }); + + describe('#commit', () => { + beforeEach(() => { + return browser.storage.local.remove('version'); + }); + + it('saves current version from manifest.json', async() => { + await versions.commit(); + let { version } = await browser.storage.local.get('version'); + expect(version).to.be.a('string'); + expect(version).to.equal(manifest.version); + }); + }); +}); diff --git a/test/background/shared/versions/storage.test.js b/test/background/shared/versions/storage.test.js new file mode 100644 index 0000000..f452516 --- /dev/null +++ b/test/background/shared/versions/storage.test.js @@ -0,0 +1,28 @@ +import * as storage from 'background/shared/versions/storage'; + +describe("shared/versions/storage", () => { + describe('#load', () => { + beforeEach(() => { + return browser.storage.local.remove('version'); + }); + + it('loads saved version', async() => { + await browser.storage.local.set({ version: '1.2.3' }); + let version = await storage.load(); + expect(version).to.equal('1.2.3'); + }); + + it('returns undefined if no versions in storage', async() => { + let version = await storage.load(); + expect(version).to.be.a('undefined'); + }); + }); + + describe('#save', () => { + it('saves version string', async() => { + await storage.save('2.3.4'); + let { version } = await browser.storage.local.get('version'); + expect(version).to.equal('2.3.4'); + }); + }); +}); diff --git a/test/shared/versions/index.test.js b/test/shared/versions/index.test.js deleted file mode 100644 index d90f04c..0000000 --- a/test/shared/versions/index.test.js +++ /dev/null @@ -1,40 +0,0 @@ -import * as versions from 'shared/versions'; -import manifest from '../../../manifest.json'; - -describe("shared/versions/storage", () => { - describe('#checkUpdated', () => { - beforeEach(() => { - return browser.storage.local.remove('version'); - }); - - it('return true if no previous versions', async() => { - let updated = await versions.checkUpdated(); - expect(updated).to.be.true; - }); - - it('return true if updated', async() => { - await browser.storage.local.set({ version: '0.001' }); - let updated = await versions.checkUpdated(); - expect(updated).to.be.true; - }); - - it('return false if not updated', async() => { - await browser.storage.local.set({ version: manifest.version }); - let updated = await versions.checkUpdated(); - expect(updated).to.be.false; - }); - }); - - describe('#commit', () => { - beforeEach(() => { - return browser.storage.local.remove('version'); - }); - - it('saves current version from manifest.json', async() => { - await versions.commit(); - let { version } = await browser.storage.local.get('version'); - expect(version).to.be.a('string'); - expect(version).to.equal(manifest.version); - }); - }); -}); diff --git a/test/shared/versions/storage.test.js b/test/shared/versions/storage.test.js deleted file mode 100644 index f541abf..0000000 --- a/test/shared/versions/storage.test.js +++ /dev/null @@ -1,28 +0,0 @@ -import * as storage from 'shared/versions/storage'; - -describe("shared/versions/storage", () => { - describe('#load', () => { - beforeEach(() => { - return browser.storage.local.remove('version'); - }); - - it('loads saved version', async() => { - await browser.storage.local.set({ version: '1.2.3' }); - let version = await storage.load(); - expect(version).to.equal('1.2.3'); - }); - - it('returns undefined if no versions in storage', async() => { - let version = await storage.load(); - expect(version).to.be.a('undefined'); - }); - }); - - describe('#save', () => { - it('saves version string', async() => { - await storage.save('2.3.4'); - let { version } = await browser.storage.local.get('version'); - expect(version).to.equal('2.3.4'); - }); - }); -}); -- cgit v1.2.3 From a28f6f916d77baf87e3c023abbd6494e009a8d12 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 11 Jul 2018 21:32:28 +0900 Subject: Complete console commands --- src/background/shared/completions/index.js | 41 ++++++++++++++++++------------ src/shared/commands/docs.js | 11 ++++++++ 2 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 src/shared/commands/docs.js (limited to 'src/background') diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js index d5875fe..22713e7 100644 --- a/src/background/shared/completions/index.js +++ b/src/background/shared/completions/index.js @@ -1,7 +1,19 @@ +import commandDocs from 'shared/commands/docs'; import * as tabs from './tabs'; import * as histories from './histories'; import * as bookmarks from './bookmarks'; +const completeCommands = (typing) => { + let keys = Object.keys(commandDocs); + return keys + .filter(name => name.startsWith(typing)) + .map(name => ({ + caption: name, + content: name, + url: commandDocs[name], + })); +}; + const getSearchCompletions = (command, keywords, searchConfig) => { let engineNames = Object.keys(searchConfig.engines); let engineItems = engineNames.filter(name => name.startsWith(keywords)) @@ -74,20 +86,21 @@ const getBufferCompletions = async(command, keywords, excludePinned) => { ]; }; -const getCompletions = (line, settings) => { - let typedWords = line.trim().split(/ +/); - let typing = ''; - if (!line.endsWith(' ')) { - typing = typedWords.pop(); - } - - if (typedWords.length === 0) { - return Promise.resolve([]); +const complete = (line, settings) => { + let trimmed = line.trimStart(); + let words = trimmed.split(/ +/); + let name = words[0]; + if (words.length === 1) { + return Promise.resolve([ + { + name: 'Console Command', + items: completeCommands(name), + } + ]); } - let name = typedWords.shift(); - let keywords = typedWords.concat(typing).join(' '); + let keywords = trimmed.slice(name.length).trimStart(); - switch (name) { + switch (words[0]) { case 'o': case 'open': case 't': @@ -112,8 +125,4 @@ const getCompletions = (line, settings) => { return Promise.resolve([]); }; -const complete = (line, settings) => { - return getCompletions(line, settings); -}; - export { complete }; diff --git a/src/shared/commands/docs.js b/src/shared/commands/docs.js new file mode 100644 index 0000000..c73eb71 --- /dev/null +++ b/src/shared/commands/docs.js @@ -0,0 +1,11 @@ +export default { + set: 'Set a value of the property', + open: 'Open a URL or search by keywords in current tab', + tabopen: 'Open a URL or search by keywords in new tab', + winopen: 'Open a URL or search by keywords in new window', + buffer: 'Sekect tabs by matched keywords', + bdelete: 'Close a certain tab matched by keywords', + bdeletes: 'Close all tabs matched by keywords', + quit: 'Close the current tab', + quitall: 'Close all tabs', +}; -- cgit v1.2.3 From 1e39fed6183bf3b10f48eb52868bb5ab3fe3134f Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 11 Jul 2018 21:58:41 +0900 Subject: Complete set commands --- src/background/shared/completions/index.js | 37 ++++++++++++++++++++++++++++++ src/shared/settings/properties.js | 8 ++++++- 2 files changed, 44 insertions(+), 1 deletion(-) (limited to 'src/background') diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js index 22713e7..d630f33 100644 --- a/src/background/shared/completions/index.js +++ b/src/background/shared/completions/index.js @@ -2,6 +2,7 @@ import commandDocs from 'shared/commands/docs'; import * as tabs from './tabs'; import * as histories from './histories'; import * as bookmarks from './bookmarks'; +import * as properties from 'shared/settings/properties'; const completeCommands = (typing) => { let keys = Object.keys(commandDocs); @@ -86,6 +87,40 @@ const getBufferCompletions = async(command, keywords, excludePinned) => { ]; }; +const getSetCompletions = (command, keywords) => { + let keys = Object.keys(properties.docs).filter( + name => name.startsWith(keywords) + ); + let items = keys.map((key) => { + if (properties.types[key] === 'boolean') { + return [ + { + caption: key, + content: command + ' ' + key, + url: 'Enable ' + properties.docs[key], + }, { + caption: 'no' + key, + content: command + ' no' + key, + url: 'Disable ' + properties.docs[key], + } + ]; + } + return [ + { + caption: key, + content: command + ' ' + key, + url: 'Set ' + properties.docs[key], + } + ]; + }).flat(); + return Promise.resolve([ + { + name: 'Properties', + items, + } + ]); +}; + const complete = (line, settings) => { let trimmed = line.trimStart(); let words = trimmed.split(/ +/); @@ -121,6 +156,8 @@ const complete = (line, settings) => { case 'bdelete': case 'bdeletes': return getBufferCompletions(name, keywords, true); + case 'set': + return getSetCompletions(name, keywords); } return Promise.resolve([]); }; diff --git a/src/shared/settings/properties.js b/src/shared/settings/properties.js index 4bda8d6..b392cbb 100644 --- a/src/shared/settings/properties.js +++ b/src/shared/settings/properties.js @@ -15,4 +15,10 @@ const defaults = { adjacenttab: true, }; -export { types, defaults }; +const docs = { + hintchars: 'Hint characters on follow mode', + smoothscroll: 'smooth scroll', + adjacenttab: 'open adjacent tabs', +}; + +export { types, defaults, docs }; -- cgit v1.2.3 From f555e1348c8e383983487a79f797fe06540862f4 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 13 Jul 2018 21:49:34 +0900 Subject: Fix command and property completions --- src/background/shared/completions/index.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/background') diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js index d630f33..4fd37fd 100644 --- a/src/background/shared/completions/index.js +++ b/src/background/shared/completions/index.js @@ -113,6 +113,9 @@ const getSetCompletions = (command, keywords) => { } ]; }).flat(); + if (items.length === 0) { + return Promise.resolve([]); + } return Promise.resolve([ { name: 'Properties', @@ -126,6 +129,10 @@ const complete = (line, settings) => { let words = trimmed.split(/ +/); let name = words[0]; if (words.length === 1) { + let items = completeCommands(name); + if (items.length === 0) { + return Promise.resolve([]); + } return Promise.resolve([ { name: 'Console Command', -- cgit v1.2.3 From ccc6a31ddeab78660305d9088e8260156b251779 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 13 Jul 2018 22:09:04 +0900 Subject: fix --- src/background/shared/completions/index.js | 2 +- src/console/reducers/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/background') diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js index 4fd37fd..d0d00ef 100644 --- a/src/background/shared/completions/index.js +++ b/src/background/shared/completions/index.js @@ -130,7 +130,7 @@ const complete = (line, settings) => { let name = words[0]; if (words.length === 1) { let items = completeCommands(name); - if (items.length === 0) { + if (items.length === 0) { return Promise.resolve([]); } return Promise.resolve([ diff --git a/src/console/reducers/index.js b/src/console/reducers/index.js index 043689c..7dcad17 100644 --- a/src/console/reducers/index.js +++ b/src/console/reducers/index.js @@ -13,7 +13,7 @@ const defaultState = { const nextSelection = (state) => { if (state.completions.length === 0) { return [-1, -1]; - }; + } if (state.groupSelection < 0) { return [0, 0]; } -- cgit v1.2.3 From 803e6ea7af60107182356b5fda8e3c2ddfacaefa Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 13 Jul 2018 22:14:19 +0900 Subject: Replace flat with reduce-concat --- src/background/shared/completions/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/background') diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js index d0d00ef..9ca13f7 100644 --- a/src/background/shared/completions/index.js +++ b/src/background/shared/completions/index.js @@ -112,7 +112,8 @@ const getSetCompletions = (command, keywords) => { url: 'Set ' + properties.docs[key], } ]; - }).flat(); + }); + items = items.reduce((acc, val) => acc.concat(val), []); if (items.length === 0) { return Promise.resolve([]); } -- cgit v1.2.3