-
Notifications
You must be signed in to change notification settings - Fork 60
/
updater.js
36 lines (33 loc) · 1.39 KB
/
updater.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
const nowTime = new Date().getTime();
const version = require("./package.json")["version"];
const fetch = require('node-fetch');
const compareVersion = require('compare-version');
let manuallyCheckText = '';
function updateChecker(method) {
if (method === 2) {
manuallyCheckText = document.getElementById("manually").innerHTML;
document.getElementById("manually").innerHTML = "...";
}
fetch('https://gitee.com/roderickqiu/wnr-backup/raw/master/package.json')
.then(res => res.json())
.then(json => {
if (compareVersion(json.version, version) === 1) {
ipc.send("update-feedback", "update-available");
} else if (method === 2) {// manually
ipc.send("update-feedback", "no-update");
}
if (method === 2) document.getElementById("manually").innerHTML = manuallyCheckText;
})
.catch(() => {
if (method === 2) {
ipc.send("update-feedback", "web-problem");
document.getElementById("manually").innerHTML = manuallyCheckText;
}
});
store.set("last-check-time", nowTime);
}
if (store.get("autocheck") !== false && process.env.NODE_ENV !== "msstore") {
if (store.get("last-check-time") === undefined || store.get("last-check-time") - nowTime > 86400000) {
updateChecker(1);
}// check for updates every day
}