[Updater > Host] Simplify Linux and exporting

This commit is contained in:
Ducko 2022-03-14 18:35:46 +00:00
parent 14d9aab003
commit 6214ae0a24
1 changed files with 13 additions and 18 deletions

View File

@ -17,25 +17,22 @@ class HostLinux extends events.EventEmitter {
} }
async checkForUpdates() { async checkForUpdates() {
const current = vParse(app.getVersion());
this.emit('checking-for-update'); this.emit('checking-for-update');
try { try {
const [ res, body ] = await new Promise((res) => get(this.updateUrl, (_e, r, b) => res([r, b]))); const current = vParse(app.getVersion());
if (res.statusCode === 204) return this.emit('update-not-available');
const latest = vParse(JSON.parse(body).name); get(this.updateUrl, (_e, res, body) => {
if (res.statusCode === 204) return this.emit('update-not-available');
const latest = vParse(JSON.parse(body).name);
if (vNewer(latest, current)) { if (vNewer(latest, current)) return this.emit('update-manually', latest.join('.'));
log('HostLinux', 'Outdated');
return this.emit('update-manually', latest.join('.'));
}
log('HostLinux', 'Not outdated'); this.emit('update-not-available');
this.emit('update-not-available'); });
} catch (err) { } catch (e) {
log('HostLinux', 'Error', this.updateUrl, err.message); log('HostLinux', 'Error', e);
this.emit('error', err); this.emit('error', e);
} }
} }
} }
@ -43,12 +40,10 @@ class HostLinux extends events.EventEmitter {
switch (process.platform) { switch (process.platform) {
case 'darwin': case 'darwin':
exports.default = autoUpdater; module.exports = autoUpdater;
break; break;
case 'linux': case 'linux':
exports.default = new HostLinux(); module.exports = new HostLinux();
break; break;
} }
module.exports = exports.default;