forked from terkelg/ramme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.js
53 lines (45 loc) · 1.31 KB
/
version.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const electron = require('electron');
const https = require('https');
const shell = electron.shell;
const app = electron.app;
function updateDialog(newVersion) {
let versionMessage = electron.dialog.showMessageBox({
type: 'info',
title: `Update available`,
message: `${app.getName()} ${newVersion} is available`,
buttons: [`Download now`, 'Remind me later'],
cancelId: 3
});
if (versionMessage === 0) {
shell.openExternal('https://github.com/terkelg/ramme/releases');
};
if (versionMessage === 1) {
// TODO: Ask user in like 7 days. Don't ask every time
}
}
function errorDialog() {
let errorMessage = electron.dialog.showMessageBox({
type: 'error',
title: `Ups, Something went wrong`,
message: `Unable to check for new updates at the moment`,
buttons: ['Try later']
});
}
exports.check = () => {
https.get('https://raw.githubusercontent.com/terkelg/ramme/master/package.json', res => {
if (!res.error && res.statusCode === 200) {
let body = '';
res.on('data', d => body += d);
res.on('end', () => {
let json = JSON.parse(body);
let newestVersion = json.version;
if(newestVersion > app.getVersion()) {
updateDialog(newestVersion);
}
});
} else {
errorDialog();
}
});
};