aboutsummaryrefslogtreecommitdiff
path: root/src/background/shared
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-07-13 22:36:56 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-07-13 22:36:56 +0900
commit944dea59199fa03f77e0e7c0d3c02acf8ccb458f (patch)
tree5f44471cdb32376a8c93e6f6eba738180f08c96f /src/background/shared
parent77b4e807e2a8b3e7ddb5f042719a34962a31b1c4 (diff)
parent28bfa3ac8124d3453cd539db26da4f4703e783df (diff)
Merge remote-tracking branch 'origin/master' into greenkeeper/css-loader-1.0.0
Diffstat (limited to 'src/background/shared')
-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
4 files changed, 124 insertions, 14 deletions
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 };