This repository has been archived by the owner on Jul 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
updater.js
61 lines (50 loc) · 1.58 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
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
const {dialog, BrowserWindow} = require('electron')
const {autoUpdater} = require('electron-updater')
const path = require('path')
const url = require('url')
autoUpdater.logger = require('electron-log')
autoUpdater.logger.transports.file.level = 'info'
autoUpdater.autoDownload = false
exports.check = () => {
autoUpdater.checkForUpdates()
autoUpdater.on('update-available', () => {
dialog.showMessageBox({
type: 'info',
title: 'Update Available',
message: 'A new version of PIA is available. Do you want to update now?',
buttons: ['Update', 'No']
}, (buttonIndex) => {
if(buttonIndex !== 0) return
autoUpdater.downloadUpdate()
let progressWin = new BrowserWindow({
width: 350,
height: 35,
useContentSize: true,
autoHideMenuBar: true,
maximizable: false,
fullscreen: false,
fullscreenable: false,
resizable: false
})
progressWin.loadURL(url.format({
pathname: path.join(__dirname, 'renderer', 'progress.html'),
protocol: 'file:',
slashes: true
}))
progressWin.on('closed', () => {
progressWin = null
})
autoUpdater.on('update-downloaded', () => {
if (progressWin) progressWin.close()
dialog.showMessageBox({
type: 'info',
title: 'Update ready',
message: 'A new version of PIA is ready. Quit and install now?',
buttons: ['Yes', 'Later']
}, (buttonIndex) => {
if (buttonIndex === 0) autoUpdater.quitAndInstall()
})
})
})
})
}