mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 12:38:39 -09:00
* Bumping electron to 3.0.10 * Updating node version in travis and appveyor * Fixing incorrect require of electron-fetch * Fix zoom to match previous versions Additionally I'm removing a call to disable pinch-zoom, it's disable by default since Electron 2 (https://electronjs.org/releases#2.0.0) * Bumping electron to 4.0.0-beta.8 * Bumping electron to 4.0.0-beta.9 * Work around for Copy accelerator not firing on electron v4 * Fixing header/titlebar in MacOS * Upgrading to electron 4.0.0 and node-pty 0.8.0 * Adding yarn.lock changes for electron 4.0.0 * Adding comments for editor:copy workaround. Scaling issue is only on Linux * Upgrading node-abi to support electron 4.0.0 * popup now takes an object as input
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const fetch = require('electron-fetch').default;
|
|
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();
|