@@ -114,10 +114,33 @@ export class AppUpdater {
114114
115115 ipcMain . handle ( 'download-update' , async ( ) => {
116116 try {
117- await autoUpdater . downloadUpdate ( ) ;
118- return { success : true } ;
117+ log . info ( '[AppUpdater] Download request received' ) ;
118+
119+ // Check if already downloaded first
120+ if ( this . lastStatus === 'downloaded' ) {
121+ log . info ( '[AppUpdater] Update already downloaded, notifying UI' ) ;
122+ this . sendStatusToWindow ( 'downloaded' , this . lastInfo ) ;
123+ return { success : true , alreadyDownloaded : true } ;
124+ }
125+
126+ // If we have update info but no download yet, start download
127+ if ( this . lastInfo && this . lastStatus === 'available' ) {
128+ log . info ( '[AppUpdater] Starting download for available update' ) ;
129+ this . sendStatusToWindow ( 'downloading' , this . lastInfo , undefined , { percent : 0 , transferred : 0 , total : 0 } ) ;
130+
131+ await autoUpdater . downloadUpdate ( ) ;
132+ log . info ( '[AppUpdater] Download completed' ) ;
133+ return { success : true } ;
134+ }
135+
136+ // No update available
137+ log . warn ( '[AppUpdater] No update available to download' ) ;
138+ this . sendStatusToWindow ( 'error' , null , 'No update available to download' ) ;
139+ return { success : false , error : 'No update available to download' } ;
140+
119141 } catch ( error ) {
120142 log . error ( '[AppUpdater] Download failed:' , error ) ;
143+ this . sendStatusToWindow ( 'error' , null , error instanceof Error ? error . message : 'Unknown error' ) ;
121144 return { success : false , error : error instanceof Error ? error . message : 'Unknown error' } ;
122145 }
123146 } ) ;
@@ -189,6 +212,42 @@ export class AppUpdater {
189212 this . checkPromise = null ;
190213 }
191214 } ) ;
215+
216+ ipcMain . handle ( 'enable-auto-install' , ( ) => {
217+ log . info ( '[AppUpdater] Enabling auto-install on next quit' ) ;
218+ autoUpdater . autoInstallOnAppQuit = true ;
219+ return { success : true } ;
220+ } ) ;
221+
222+ ipcMain . handle ( 'download-and-install' , async ( ) => {
223+ try {
224+ log . info ( '[AppUpdater] Download and install requested' ) ;
225+
226+ // Check current status
227+ if ( this . lastStatus === 'downloaded' ) {
228+ log . info ( '[AppUpdater] Update already downloaded, ready to install' ) ;
229+ return { success : true , readyToInstall : true } ;
230+ }
231+
232+ if ( this . lastStatus === 'available' && this . lastInfo ) {
233+ log . info ( '[AppUpdater] Starting download...' ) ;
234+ this . sendStatusToWindow ( 'downloading' , this . lastInfo , undefined , { percent : 0 , transferred : 0 , total : 0 } ) ;
235+
236+ // Download the update
237+ await autoUpdater . downloadUpdate ( ) ;
238+
239+ log . info ( '[AppUpdater] Download completed, ready to install' ) ;
240+ return { success : true , readyToInstall : true } ;
241+ }
242+
243+ return { success : false , error : 'No update available to download' } ;
244+
245+ } catch ( error ) {
246+ log . error ( '[AppUpdater] Download and install failed:' , error ) ;
247+ this . sendStatusToWindow ( 'error' , null , error instanceof Error ? error . message : 'Unknown error' ) ;
248+ return { success : false , error : error instanceof Error ? error . message : 'Unknown error' } ;
249+ }
250+ } ) ;
192251 }
193252
194253 private sendStatusToWindow ( status : string , info ?: any , error ?: string , progress ?: any ) {
@@ -200,7 +259,9 @@ export class AppUpdater {
200259 log . info ( `[AppUpdater] Sending status to window: ${ status } ` , {
201260 hasMainWindow : ! ! this . mainWindow ,
202261 isDestroyed : this . mainWindow ?. isDestroyed ( ) ,
203- info : info ? { version : info . version } : undefined
262+ info : info ? { version : info . version } : undefined ,
263+ error,
264+ progress
204265 } ) ;
205266
206267 if ( this . mainWindow && ! this . mainWindow . isDestroyed ( ) ) {
@@ -210,20 +271,21 @@ export class AppUpdater {
210271 error,
211272 progress
212273 } ) ;
274+ log . info ( `[AppUpdater] Status sent to renderer: ${ status } ` ) ;
275+ } else {
276+ log . warn ( '[AppUpdater] Cannot send status - main window not available' ) ;
213277 }
214278 }
215279
216280 checkForUpdatesOnStartup ( ) {
217281 if ( ! app . isPackaged ) {
282+ log . info ( '[AppUpdater] Skipping startup check - not packaged' ) ;
218283 return ;
219284 }
220285
221- if ( app . isPackaged ) {
222- return ;
223- }
224-
225- // Check for updates 3 seconds after startup to avoid conflicts
286+ // Check for updates 3 seconds after startup to avoid conflicts
226287 setTimeout ( ( ) => {
288+ log . info ( '[AppUpdater] Starting automatic update check' ) ;
227289 this . sendStatusToWindow ( 'checking' ) ;
228290 autoUpdater . checkForUpdatesAndNotify ( ) . catch ( err => {
229291 log . error ( '[AppUpdater] Startup check failed:' , err . message ) ;
0 commit comments