2022-01-28 20:06:36 +00:00
|
|
|
const { app, autoUpdater } = require('electron');
|
|
|
|
const events = require('events');
|
2021-12-09 16:25:14 +00:00
|
|
|
|
2022-02-08 13:07:28 +00:00
|
|
|
const { get } = require('request');
|
2021-12-09 16:25:14 +00:00
|
|
|
|
2022-02-08 13:07:28 +00:00
|
|
|
const vParse = (s) => s.split('.').map((x) => parseInt(x));
|
|
|
|
const vNewer = (a, b) => a.some((x, i) => x === b[i] ? undefined : (x > b[i]));
|
2021-12-09 16:25:14 +00:00
|
|
|
|
2022-01-28 20:06:36 +00:00
|
|
|
class HostLinux extends events.EventEmitter {
|
2021-12-09 16:25:14 +00:00
|
|
|
setFeedURL(url) {
|
|
|
|
this.updateUrl = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
quitAndInstall() {
|
2022-01-28 20:06:36 +00:00
|
|
|
app.relaunch();
|
|
|
|
app.quit();
|
2021-12-09 16:25:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async checkForUpdates() {
|
|
|
|
this.emit('checking-for-update');
|
|
|
|
|
|
|
|
try {
|
2022-03-14 18:35:46 +00:00
|
|
|
const current = vParse(app.getVersion());
|
2021-12-09 16:25:14 +00:00
|
|
|
|
2022-03-14 18:35:46 +00:00
|
|
|
get(this.updateUrl, (_e, res, body) => {
|
|
|
|
if (res.statusCode === 204) return this.emit('update-not-available');
|
|
|
|
const latest = vParse(JSON.parse(body).name);
|
2021-12-09 16:25:14 +00:00
|
|
|
|
2022-03-14 18:35:46 +00:00
|
|
|
if (vNewer(latest, current)) return this.emit('update-manually', latest.join('.'));
|
2022-01-28 20:06:36 +00:00
|
|
|
|
2022-03-14 18:35:46 +00:00
|
|
|
this.emit('update-not-available');
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
log('HostLinux', 'Error', e);
|
|
|
|
this.emit('error', e);
|
2021-12-09 16:25:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (process.platform) {
|
|
|
|
case 'darwin':
|
2022-03-14 18:35:46 +00:00
|
|
|
module.exports = autoUpdater;
|
2021-12-09 16:25:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'linux':
|
2022-03-14 18:35:46 +00:00
|
|
|
module.exports = new HostLinux();
|
2021-12-09 16:25:14 +00:00
|
|
|
break;
|
2022-03-14 18:35:46 +00:00
|
|
|
}
|