aboutsummaryrefslogtreecommitdiff
path: root/src/background
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-07-13 22:30:05 +0900
committerGitHub <noreply@github.com>2018-07-13 22:30:05 +0900
commit28bfa3ac8124d3453cd539db26da4f4703e783df (patch)
treedd4461af8343a7d5c9fc13cc51cd0fd5edd0285e /src/background
parent37840c2abb02948d36cdcfaab9063f3ea67fdb6b (diff)
parent803e6ea7af60107182356b5fda8e3c2ddfacaefa (diff)
Merge pull request #431 from ueokande/command-completions
Command completions
Diffstat (limited to 'src/background')
-rw-r--r--src/background/index.js2
-rw-r--r--src/background/reducers/index.js23
-rw-r--r--src/background/shared/completions/index.js82
-rw-r--r--src/background/shared/versions/index.js38
-rw-r--r--src/background/shared/versions/release-notes.js8
-rw-r--r--src/background/shared/versions/storage.js10
6 files changed, 132 insertions, 31 deletions
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/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,
+});
diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js
index d5875fe..9ca13f7 100644
--- a/src/background/shared/completions/index.js
+++ b/src/background/shared/completions/index.js
@@ -1,6 +1,19 @@
+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);
+ 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);
@@ -74,20 +87,63 @@ const getBufferCompletions = async(command, keywords, excludePinned) => {
];
};
-const getCompletions = (line, settings) => {
- let typedWords = line.trim().split(/ +/);
- let typing = '';
- if (!line.endsWith(' ')) {
- typing = typedWords.pop();
+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],
+ }
+ ];
+ });
+ items = items.reduce((acc, val) => acc.concat(val), []);
+ if (items.length === 0) {
+ return Promise.resolve([]);
}
+ return Promise.resolve([
+ {
+ name: 'Properties',
+ items,
+ }
+ ]);
+};
- 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) {
+ let items = completeCommands(name);
+ if (items.length === 0) {
+ return Promise.resolve([]);
+ }
+ 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':
@@ -108,12 +164,10 @@ const getCompletions = (line, settings) => {
case 'bdelete':
case 'bdeletes':
return getBufferCompletions(name, keywords, true);
+ case 'set':
+ return getSetCompletions(name, keywords);
}
return Promise.resolve([]);
};
-const complete = (line, settings) => {
- return getCompletions(line, settings);
-};
-
export { complete };
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 };