Add isEnabled function to AutoUpdateManager

This commit is contained in:
Ben Ogle
2016-02-25 16:01:23 -08:00
parent e477751c19
commit c19296efb7
2 changed files with 57 additions and 2 deletions

View File

@@ -63,6 +63,38 @@ describe('AutoUpdateManager (renderer)', () => {
})
})
describe('::isEnabled', () => {
let platform, releaseChannel
it('returns true on OS X and Windows, when in stable', () => {
spyOn(autoUpdateManager, 'getPlatform').andCallFake(() => platform)
spyOn(autoUpdateManager, 'getReleaseChannel').andCallFake(() => releaseChannel)
platform = 'win32'
releaseChannel = 'stable'
expect(autoUpdateManager.isEnabled()).toBe(true)
platform = 'win32'
releaseChannel = 'dev'
expect(autoUpdateManager.isEnabled()).toBe(false)
platform = 'darwin'
releaseChannel = 'stable'
expect(autoUpdateManager.isEnabled()).toBe(true)
platform = 'darwin'
releaseChannel = 'dev'
expect(autoUpdateManager.isEnabled()).toBe(false)
platform = 'linux'
releaseChannel = 'stable'
expect(autoUpdateManager.isEnabled()).toBe(false)
platform = 'linux'
releaseChannel = 'dev'
expect(autoUpdateManager.isEnabled()).toBe(false)
})
})
describe('::dispose', () => {
it('subscribes to "update-not-available" event', () => {
const spy = jasmine.createSpy('spy')

View File

@@ -31,6 +31,18 @@ export default class AutoUpdateManager {
this.emitter.dispose()
}
checkForUpdate () {
ipcRenderer.send('check-for-update')
}
quitAndInstallUpdate () {
ipcRenderer.send('install-update')
}
isEnabled () {
return this.getReleaseChannel() == 'stable' && (this.getPlatform() === 'darwin' || this.getPlatform() === 'win32')
}
onDidBeginCheckingForUpdate (callback) {
return this.emitter.on('did-begin-checking-for-update', callback)
}
@@ -47,7 +59,18 @@ export default class AutoUpdateManager {
return this.emitter.on('update-not-available', callback)
}
checkForUpdate () {
ipcRenderer.send('check-for-update')
getPlatform () {
return process.platform
}
// TODO: We should move this into atom env or something.
getReleaseChannel () {
let version = atom.getVersion()
if (version.indexOf('beta') > -1) {
return 'beta'
} else if (version.indexOf('dev') > -1) {
return 'dev'
}
return 'stable'
}
}