1
1
import { appStore } from '@main/stores/app.store'
2
2
import { isProduction } from '@shared/config'
3
3
import { app , BrowserWindow , dialog } from 'electron'
4
- import { autoUpdater } from 'electron-updater'
4
+ import { autoUpdater , UpdateInfo } from 'electron-updater'
5
5
import semver from 'semver'
6
6
const [ GITHUB_AUTHOR , GITHUB_REPOSITORY ] = import . meta. env . VITE_GITHUB_REPOSITORY ?. split (
7
7
'/' ,
@@ -21,6 +21,29 @@ export function checkForUpdates() {
21
21
. then ( ( info ) => ( info && isUpdateInRange ( info . updateInfo . version ) && info ) || null )
22
22
}
23
23
export function checkForUpdatesAndNotify ( ) { }
24
+ export async function proceedUpdateDialog ( info : UpdateInfo ) {
25
+ const releaseNotes = (
26
+ typeof info . releaseNotes === 'string'
27
+ ? info . releaseNotes
28
+ : info . releaseNotes ?. map ( ( x ) => x . note ) . join ( '\n' )
29
+ )
30
+ ?. replace ( / < [ ^ > ] + > / g, '' )
31
+ . trimStart ( )
32
+ return await dialog
33
+ . showMessageBox ( {
34
+ title : `Update available (${ info . version } )` ,
35
+ message : `Hey there is a new version which you can update to.\n\n${
36
+ process . platform === 'win32' ? releaseNotes : info . releaseName
37
+ } `,
38
+ type : 'question' ,
39
+ buttons : [ 'Update now' , 'Update on quit' , 'Cancel' ] ,
40
+ cancelId : - 1
41
+ } )
42
+ . then ( ( { response } ) => {
43
+ if ( response === 0 ) autoUpdater . quitAndInstall ( )
44
+ else if ( response === 1 ) autoUpdater . autoInstallOnAppQuit = true
45
+ } )
46
+ }
24
47
export function attachAutoUpdaterIPC ( win : BrowserWindow ) {
25
48
autoUpdater . on (
26
49
'update-available' ,
@@ -31,36 +54,16 @@ export function attachAutoUpdaterIPC(win: BrowserWindow) {
31
54
win . webContents . send ( 'update-available' , false )
32
55
win . webContents . send ( 'update-checking' , false )
33
56
} )
34
- autoUpdater . on ( 'download-progress' , ( info ) =>
35
- win . webContents . send ( 'update-download-progress' , info )
36
- )
37
- autoUpdater . on ( 'update-downloaded' , ( info ) => win . webContents . send ( 'update-download-done' , info ) )
38
57
autoUpdater . on ( 'checking-for-update' , ( ) =>
39
58
win . webContents . send ( 'update-checking' , new Date ( ) . toISOString ( ) )
40
59
)
60
+ autoUpdater . signals . progress ( ( info ) => {
61
+ win . webContents . send ( 'update-download-progress' , info )
62
+ } )
41
63
autoUpdater . signals . updateDownloaded ( async ( x ) => {
64
+ win . webContents . send ( 'update-download-done' , x )
42
65
if ( updateQueuedInFrontend ) return
43
- const releaseNotes = (
44
- typeof x . releaseNotes === 'string'
45
- ? x . releaseNotes
46
- : x . releaseNotes ?. map ( ( x ) => x . note ) . join ( '\n' )
47
- )
48
- ?. replace ( / < [ ^ > ] + > / g, '' )
49
- . trimStart ( )
50
- return await dialog
51
- . showMessageBox ( {
52
- title : `Update available (${ x . version } )` ,
53
- message : `Hey there is a new version which you can update to.\n\n${
54
- process . platform === 'win32' ? releaseNotes : x . releaseName
55
- } `,
56
- type : 'question' ,
57
- buttons : [ 'Update now' , 'Update on quit' , 'Cancel' ] ,
58
- cancelId : - 1
59
- } )
60
- . then ( ( { response } ) => {
61
- if ( response === 0 ) autoUpdater . quitAndInstall ( )
62
- else if ( response === 1 ) autoUpdater . autoInstallOnAppQuit = true
63
- } )
66
+ return await proceedUpdateDialog ( x )
64
67
} )
65
68
if ( ! import . meta. env . VITE_GITHUB_REPOSITORY )
66
69
autoUpdater . setFeedURL ( {
0 commit comments