11import { appStore } from '@main/stores/app.store'
22import { isProduction } from '@shared/config'
33import { app , BrowserWindow , dialog } from 'electron'
4- import { autoUpdater } from 'electron-updater'
4+ import { autoUpdater , UpdateInfo } from 'electron-updater'
55import semver from 'semver'
66const [ GITHUB_AUTHOR , GITHUB_REPOSITORY ] = import . meta. env . VITE_GITHUB_REPOSITORY ?. split (
77 '/' ,
@@ -21,6 +21,29 @@ export function checkForUpdates() {
2121 . then ( ( info ) => ( info && isUpdateInRange ( info . updateInfo . version ) && info ) || null )
2222}
2323export 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+ }
2447export function attachAutoUpdaterIPC ( win : BrowserWindow ) {
2548 autoUpdater . on (
2649 'update-available' ,
@@ -31,36 +54,16 @@ export function attachAutoUpdaterIPC(win: BrowserWindow) {
3154 win . webContents . send ( 'update-available' , false )
3255 win . webContents . send ( 'update-checking' , false )
3356 } )
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 ) )
3857 autoUpdater . on ( 'checking-for-update' , ( ) =>
3958 win . webContents . send ( 'update-checking' , new Date ( ) . toISOString ( ) )
4059 )
60+ autoUpdater . signals . progress ( ( info ) => {
61+ win . webContents . send ( 'update-download-progress' , info )
62+ } )
4163 autoUpdater . signals . updateDownloaded ( async ( x ) => {
64+ win . webContents . send ( 'update-download-done' , x )
4265 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 )
6467 } )
6568 if ( ! import . meta. env . VITE_GITHUB_REPOSITORY )
6669 autoUpdater . setFeedURL ( {
0 commit comments