-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAutoUpdater.js
65 lines (55 loc) · 1.74 KB
/
AutoUpdater.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
54
55
56
57
58
59
60
61
62
63
64
65
const { autoUpdater } = require("electron-updater");
module.exports = mainWindow => {
autoUpdater.logger = console;
autoUpdater.allowPrerelease = true;
autoUpdater.on("checking-for-update", () => {
mainWindow.webContents.send("sendTextUpdate", {
event: "checking-for-update",
msg: "Verificando atualizações..."
});
});
autoUpdater.on("update-available", info => {
mainWindow.webContents.send("sendTextUpdate", {
event: "update-available",
msg: "Atualização disponível."
});
});
autoUpdater.on("update-not-available", info => {
mainWindow.webContents.send("sendTextUpdate", {
event: "update-not-available",
msg: "Atualização não disponível."
});
});
autoUpdater.on("error", err => {
mainWindow.webContents.send("sendTextUpdate", {
event: "error",
msg: {
t: "Erro no atualizador automático.",
err: err
}
});
});
autoUpdater.on("download-progress", progressObj => {
let speed = (progressObj.bytesPerSecond / 1000 / 1000).toFixed(1);
let transferred = (progressObj.transferred / 1000 / 1000).toFixed(1);
let total = (progressObj.total / 1000 / 1000).toFixed(1);
let percent = progressObj.percent.toFixed(1);
let log_message = "Velocidade de download: " + speed + " Mb/s";
log_message = log_message + " - Baixado: " + percent + "%";
log_message = log_message + " (" + transferred + "/" + total + ")";
mainWindow.webContents.send("sendTextUpdate", {
event: "download-progress",
msg: log_message
});
});
autoUpdater.on("update-downloaded", info => {
mainWindow.webContents.send("sendTextUpdate", {
event: "update-downloaded",
msg: "Atualização baixada. Reiniciando..."
});
setTimeout(function() {
autoUpdater.quitAndInstall();
}, 5000);
});
return autoUpdater;
};