Merge pull request #385 from ueokande/update_notification

Update notification
jh-changes
Shin'ya Ueoka 7 years ago committed by GitHub
commit e68c0b0f80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      karma.conf.js
  2. 3
      manifest.json
  3. 9329
      package-lock.json
  4. 3
      package.json
  5. 10
      src/background/index.js
  6. 39
      src/shared/versions/index.js
  7. 8
      src/shared/versions/release-notes.js
  8. 11
      src/shared/versions/storage.js
  9. 4
      test/main.js
  10. 55
      test/shared/versions/index.test.js
  11. 39
      test/shared/versions/storage.test.js

@ -4,7 +4,7 @@ module.exports = function (config) {
config.set({ config.set({
basePath: '', basePath: '',
frameworks: ['mocha'], frameworks: ['mocha', 'sinon'],
files: [ files: [
'test/main.js', 'test/main.js',
'test/**/*.test.js', 'test/**/*.test.js',

@ -31,7 +31,8 @@
"sessions", "sessions",
"storage", "storage",
"tabs", "tabs",
"clipboardRead" "clipboardRead",
"notifications"
], ],
"web_accessible_resources": [ "web_accessible_resources": [
"build/console.html", "build/console.html",

9329
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -37,14 +37,17 @@
"karma-html2js-preprocessor": "^1.1.0", "karma-html2js-preprocessor": "^1.1.0",
"karma-mocha": "^1.3.0", "karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.3", "karma-mocha-reporter": "^2.2.3",
"karma-sinon": "^1.0.5",
"karma-sourcemap-loader": "^0.3.7", "karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^3.0.0", "karma-webpack": "^3.0.0",
"mocha": "^5.0.0", "mocha": "^5.0.0",
"node-sass": "^4.5.3", "node-sass": "^4.5.3",
"preact": "^8.2.6", "preact": "^8.2.6",
"sass-loader": "^7.0.1", "sass-loader": "^7.0.1",
"sinon-chrome": "^2.3.1",
"style-loader": "^0.21.0", "style-loader": "^0.21.0",
"web-ext": "github:ueokande/web-ext#patched-2.4.0", "web-ext": "github:ueokande/web-ext#patched-2.4.0",
"webextensions-api-fake": "^0.5.1",
"webpack": "^4.1.1", "webpack": "^4.1.1",
"webpack-cli": "^2.0.11" "webpack-cli": "^2.0.11"
} }

@ -3,6 +3,7 @@ import messages from 'shared/messages';
import BackgroundComponent from 'background/components/background'; import BackgroundComponent from 'background/components/background';
import reducers from 'background/reducers'; import reducers from 'background/reducers';
import { createStore } from 'shared/store'; import { createStore } from 'shared/store';
import * as versions from 'shared/versions';
const store = createStore(reducers, (e, sender) => { const store = createStore(reducers, (e, sender) => {
console.error('Vim-Vixen:', e); console.error('Vim-Vixen:', e);
@ -17,3 +18,12 @@ const store = createStore(reducers, (e, sender) => {
const backgroundComponent = new BackgroundComponent(store); const backgroundComponent = new BackgroundComponent(store);
store.dispatch(settingActions.load()); store.dispatch(settingActions.load());
versions.checkUpdated().then((updated) => {
if (!updated) {
return;
}
return versions.notify();
}).then(() => {
return versions.commit();
});

@ -0,0 +1,39 @@
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 = () => {
return storage.load().then((prev) => {
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 };

@ -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 };

@ -0,0 +1,11 @@
const load = () => {
return browser.storage.local.get('version').then(({ version }) => {
return version;
});
};
const save = (version) => {
return browser.storage.local.set({ version });
};
export { load, save };

@ -1,2 +1,6 @@
import chai from 'chai'; import chai from 'chai';
const browserFake = require('webextensions-api-fake');
const browser = browserFake();
global.expect = chai.expect; global.expect = chai.expect;
global.browser = browser;

@ -0,0 +1,55 @@
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', () => {
return Promise.resolve().then(() => {
return versions.checkUpdated();
}).then((updated) => {
expect(updated).to.be.true;
});
});
it('return true if updated', () => {
return Promise.resolve().then(() => {
return browser.storage.local.set({ version: '0.001' });
}).then(() => {
return versions.checkUpdated();
}).then((updated) => {
expect(updated).to.be.true;
});
});
it('return false if not updated', () => {
return Promise.resolve().then(() => {
return browser.storage.local.set({ version: manifest.version });
}).then(() => {
return versions.checkUpdated();
}).then((updated) => {
expect(updated).to.be.false;
});
});
});
describe('#commit', () => {
beforeEach(() => {
return browser.storage.local.remove('version');
});
it('saves current version from manifest.json', () => {
return Promise.resolve().then(() => {
return versions.commit();
}).then(() => {
return browser.storage.local.get('version');
}).then(({version}) => {
expect(version).to.be.a('string');
expect(version).to.equal(manifest.version);
});
});
});
});

@ -0,0 +1,39 @@
import * as storage from 'shared/versions/storage';
describe("shared/versions/storage", () => {
describe('#load', () => {
beforeEach(() => {
return browser.storage.local.remove('version');
});
it('loads saved version', () => {
return Promise.resolve().then(() => {
return browser.storage.local.set({ version: '1.2.3' });
}).then(() => {
return storage.load();
}).then((version) => {
expect(version).to.equal('1.2.3');
});
});
it('returns undefined if no versions in storage', () => {
return Promise.resolve().then(() => {
return storage.load();
}).then((version) => {
expect(version).to.be.a('undefined');
});
});
});
describe('#save', () => {
it('saves version string', () => {
return Promise.resolve().then(() => {
return storage.save('2.3.4');
}).then(() => {
return browser.storage.local.get('version');
}).then(({version}) => {
expect(version).to.equal('2.3.4');
});
});
});
});