-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use same
hazel
endpoint to notify update to Linux users (#2497)
Add a pseudo auto-updater for Linux Fixes #2476
- Loading branch information
Showing
8 changed files
with
114 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const fetch = require('node-fetch'); | ||
const {EventEmitter} = require('events'); | ||
|
||
class AutoUpdater extends EventEmitter { | ||
quitAndInstall() { | ||
this.emitError('QuitAndInstall unimplemented'); | ||
} | ||
getFeedURL() { | ||
return this.updateURL; | ||
} | ||
|
||
setFeedURL(updateURL) { | ||
this.updateURL = updateURL; | ||
} | ||
|
||
checkForUpdates() { | ||
if (!this.updateURL) { | ||
return this.emitError('Update URL is not set'); | ||
} | ||
this.emit('checking-for-update'); | ||
|
||
fetch(this.updateURL) | ||
.then(res => { | ||
if (res.status === 204) { | ||
return this.emit('update-not-available'); | ||
} | ||
return res.json().then(({name, notes, pub_date}) => { | ||
// Only name is mandatory, needed to construct release URL. | ||
if (!name) { | ||
throw new Error('Malformed server response: release name is missing.'); | ||
} | ||
// If `null` is passed to Date constructor, current time will be used. This doesn't work with `undefined` | ||
const date = new Date(pub_date || null); | ||
this.emit('update-available', {}, notes, name, date); | ||
}); | ||
}) | ||
.catch(this.emitError.bind(this)); | ||
} | ||
|
||
emitError(error) { | ||
if (typeof error === 'string') { | ||
error = new Error(error); | ||
} | ||
this.emit('error', error, error.message); | ||
} | ||
} | ||
|
||
module.exports = new AutoUpdater(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters