-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.ts
58 lines (54 loc) · 1.74 KB
/
update.ts
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
import { app, dialog } from 'electron'
import { WindowManager } from './../managers/window'
import { autoUpdater } from 'electron-updater'
import { AppEvent } from '@janhq/core'
export function handleAppUpdates() {
/* Should not check for update during development */
if (!app.isPackaged) {
return
}
/* New Update Available */
autoUpdater.on('update-available', async (_info: any) => {
const action = await dialog.showMessageBox({
message: `Update available. Do you want to download the latest update?`,
buttons: ['Download', 'Later'],
})
if (action.response === 0) await autoUpdater.downloadUpdate()
})
/* App Update Completion Message */
autoUpdater.on('update-downloaded', async (_info: any) => {
WindowManager.instance.currentWindow?.webContents.send(
AppEvent.onAppUpdateDownloadSuccess,
{}
)
const action = await dialog.showMessageBox({
message: `Update downloaded. Please restart the application to apply the updates.`,
buttons: ['Restart', 'Later'],
})
if (action.response === 0) {
autoUpdater.quitAndInstall()
}
})
/* App Update Error */
autoUpdater.on('error', (info: any) => {
WindowManager.instance.currentWindow?.webContents.send(
AppEvent.onAppUpdateDownloadError,
{}
)
})
/* App Update Progress */
autoUpdater.on('download-progress', (progress: any) => {
console.debug('app update progress: ', progress.percent)
WindowManager.instance.currentWindow?.webContents.send(
AppEvent.onAppUpdateDownloadUpdate,
{
percent: progress.percent,
}
)
})
autoUpdater.autoDownload = false
autoUpdater.autoInstallOnAppQuit = true
if (process.env.CI !== 'e2e') {
autoUpdater.checkForUpdates()
}
}