forked from whitewhidow/quest-sidenoder
-
Notifications
You must be signed in to change notification settings - Fork 20
/
versioncheck.js
33 lines (30 loc) · 973 Bytes
/
versioncheck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const pkg = require('./package.json');
const fetch = require('node-fetch');
const compareVersions = require('compare-versions');
global.version = pkg.version;
async function checkVersion() {
try {
const res = await fetch('https://api.github.com/repos/vKolerts/sidenoder/releases/latest');
const content = JSON.parse(await res.text())
const remoteversion = content.name;
console.log('Current version: ' + pkg.version);
console.log('Github version: ' + remoteversion);
if (!remoteversion) return;
if (compareVersions.compare(remoteversion, pkg.version, '<=')) {
console.log('Using latest version');
}
else {
console.log('requires update');
win.webContents.send('notify_update', {
success: true,
current: pkg.version,
remote: remoteversion,
url: content.html_url,
description: content.body,
});
}
}
catch (err) {
console.error('checkVersion.Fail', err);
}
}