parent
a63311bd34
commit
88e216d49b
7 changed files with 161 additions and 1 deletions
@ -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,5 @@ |
||||
const url = (version) => { |
||||
return 'https://github.com/ueokande/vim-vixen/releases/tag/' + version; |
||||
}; |
||||
|
||||
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 }; |
@ -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'); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
Reference in new issue