-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathupdater.js
More file actions
48 lines (42 loc) · 1.27 KB
/
Copy pathupdater.js
File metadata and controls
48 lines (42 loc) · 1.27 KB
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
const {logger, packageInfos} = require('./config');
const {autoUpdater} = require('electron');
const got = require('got');
const semver = require('semver');
const appVersion = packageInfos.version;
const options = {
repo: 'https://raw.githubusercontent.com/aaabhilash97/cliptext/master/auto_updater.json',
};
/**
* Start update checker
*/
function checkForUpdates() {
setInterval(async ()=>{
try {
let data = await got(options.repo);
data = JSON.parse(data.body);
const regex = /-(\d+\.\d+\.\d+)-/;
const version = data.url.match(regex);
if (semver.gt(version[1], appVersion)) {
autoUpdater.setFeedURL(options.repo);
autoUpdater.on('checking-for-update', ()=>{
logger.info('checking for updates');
});
autoUpdater.on('update-available', ()=>{
logger.info('update-available');
});
autoUpdater.on('update-not-available', ()=>{
logger.info('update-not-available');
});
autoUpdater.on('update-downloaded', ()=>{
autoUpdater.quitAndInstall();
});
autoUpdater.checkForUpdates();
}
} catch (error) {
logger.error('Error in checking update', error);
}
}, 1000000);
}
module.exports = {
checkForUpdates: checkForUpdates,
};