@@ -216,9 +216,19 @@ const fetchOfficialReleaseAssetNames = async (version: string, extension: string
216216 const cacheKey = `${ version } |${ extension } ` ;
217217 const cached = releaseAssetNameCache . get ( cacheKey ) ;
218218 if ( cached ) {
219+ mainLogger . debug ( '[AutoUpdate] Using cached official release asset names.' , {
220+ version,
221+ extension,
222+ names : cached ,
223+ } ) ;
219224 return cached ;
220225 }
221226
227+ mainLogger . debug ( '[AutoUpdate] Fetching official release asset names from GitHub.' , {
228+ version,
229+ extension,
230+ } ) ;
231+
222232 const headers = await buildGitHubApiHeaders ( ) ;
223233 const candidateTags = new Set < string > ( ) ;
224234 candidateTags . add ( version ) ;
@@ -228,6 +238,11 @@ const fetchOfficialReleaseAssetNames = async (version: string, extension: string
228238 const release = await fetchReleaseByTag ( tag , headers ) ;
229239 if ( release ?. assets ) {
230240 const names = filterAssetNamesByExtension ( release . assets , extension ) ;
241+ mainLogger . debug ( '[AutoUpdate] Found release assets for tag.' , {
242+ tag,
243+ extension,
244+ names,
245+ } ) ;
231246 releaseAssetNameCache . set ( cacheKey , names ) ;
232247 if ( names . length > 0 ) {
233248 return names ;
@@ -240,12 +255,21 @@ const fetchOfficialReleaseAssetNames = async (version: string, extension: string
240255 for ( const release of releasesList ) {
241256 if ( typeof release ?. tag_name === 'string' && candidateTags . has ( release . tag_name ) ) {
242257 const names = filterAssetNamesByExtension ( release . assets , extension ) ;
258+ mainLogger . debug ( '[AutoUpdate] Matched release from recent releases listing.' , {
259+ tag : release . tag_name ,
260+ extension,
261+ names,
262+ } ) ;
243263 releaseAssetNameCache . set ( cacheKey , names ) ;
244264 return names ;
245265 }
246266 }
247267 }
248268
269+ mainLogger . warn ( '[AutoUpdate] Unable to determine official release asset names from GitHub listing.' , {
270+ version,
271+ extension,
272+ } ) ;
249273 releaseAssetNameCache . set ( cacheKey , [ ] ) ;
250274 return [ ] ;
251275} ;
@@ -294,7 +318,12 @@ const extractCandidateNamesFromUpdateInfo = (info: UpdateDownloadedEvent, extens
294318 considerName ( path . basename ( info . downloadedFile ) ) ;
295319 }
296320
297- return Array . from ( names ) ;
321+ const collected = Array . from ( names ) ;
322+ mainLogger . debug ( '[AutoUpdate] Candidate filenames extracted from update metadata.' , {
323+ extension,
324+ candidates : collected ,
325+ } ) ;
326+ return collected ;
298327} ;
299328
300329const safeRenameDownloadedUpdate = async ( currentPath : string , desiredPath : string ) : Promise < void > => {
@@ -309,6 +338,11 @@ const safeRenameDownloadedUpdate = async (currentPath: string, desiredPath: stri
309338 }
310339 }
311340 await fs . rename ( currentPath , desiredPath ) ;
341+ mainLogger . info ( '[AutoUpdate] Renamed downloaded update to align with official filename.' , {
342+ from : path . basename ( currentPath ) ,
343+ to : path . basename ( desiredPath ) ,
344+ directory : path . dirname ( desiredPath ) ,
345+ } ) ;
312346} ;
313347
314348const updateCachedDownloadedUpdateMetadata = async ( expectedFileName : string , directory : string ) : Promise < void > => {
@@ -319,6 +353,10 @@ const updateCachedDownloadedUpdateMetadata = async (expectedFileName: string, di
319353 if ( parsed && typeof parsed === 'object' ) {
320354 parsed . fileName = expectedFileName ;
321355 await fs . writeFile ( updateInfoPath , JSON . stringify ( parsed , null , 2 ) ) ;
356+ mainLogger . debug ( '[AutoUpdate] Updated cached update metadata with expected filename.' , {
357+ updateInfoPath,
358+ expectedFileName,
359+ } ) ;
322360 }
323361 } catch ( error : any ) {
324362 if ( error ?. code !== 'ENOENT' ) {
@@ -336,6 +374,13 @@ const ensureDownloadedFileMatchesOfficialRelease = async (info: UpdateDownloaded
336374 const downloadedName = path . basename ( downloadedPath ) ;
337375 const downloadedExt = path . extname ( downloadedName ) . toLowerCase ( ) ;
338376
377+ mainLogger . info ( '[AutoUpdate] Validating downloaded update filename.' , {
378+ version : info . version ,
379+ downloadedPath,
380+ downloadedName,
381+ downloadedExt,
382+ } ) ;
383+
339384 let officialNames : string [ ] = [ ] ;
340385 try {
341386 officialNames = await fetchOfficialReleaseAssetNames ( info . version , downloadedExt ) ;
@@ -348,15 +393,27 @@ const ensureDownloadedFileMatchesOfficialRelease = async (info: UpdateDownloaded
348393 }
349394
350395 if ( officialNames . length === 0 ) {
396+ mainLogger . error ( '[AutoUpdate] No official filenames available for validation.' , {
397+ version : info . version ,
398+ downloadedName,
399+ extension : downloadedExt ,
400+ } ) ;
351401 return { success : false , error : 'No official release filenames available for comparison.' , downloadedName, officialNames : [ ] } ;
352402 }
353403
354404 if ( officialNames . includes ( downloadedName ) ) {
405+ mainLogger . info ( '[AutoUpdate] Downloaded filename already matches official release asset.' , {
406+ downloadedName,
407+ } ) ;
355408 return { success : true , filePath : downloadedPath , expectedName : downloadedName , officialNames } ;
356409 }
357410
358411 const caseInsensitiveMatch = officialNames . find ( name => name . toLowerCase ( ) === downloadedName . toLowerCase ( ) ) ;
359412 if ( caseInsensitiveMatch ) {
413+ mainLogger . info ( '[AutoUpdate] Downloaded filename matches an official asset ignoring case.' , {
414+ downloadedName,
415+ expectedName : caseInsensitiveMatch ,
416+ } ) ;
360417 return { success : true , filePath : downloadedPath , expectedName : caseInsensitiveMatch , officialNames } ;
361418 }
362419
@@ -372,8 +429,19 @@ const ensureDownloadedFileMatchesOfficialRelease = async (info: UpdateDownloaded
372429 helper . _downloadedFileInfo . fileName = expectedName ;
373430 }
374431 }
432+ mainLogger . info ( '[AutoUpdate] Downloaded update renamed to expected filename.' , {
433+ previousName : downloadedName ,
434+ expectedName,
435+ helperAdjusted : Boolean ( helper ) ,
436+ } ) ;
375437 return { success : true , filePath : expectedPath , expectedName, renamed : true , officialNames } ;
376438 } catch ( error : any ) {
439+ mainLogger . error ( '[AutoUpdate] Failed to align downloaded filename with official asset.' , {
440+ version : info . version ,
441+ downloadedName,
442+ expectedName,
443+ error : error instanceof Error ? { message : error . message , stack : error . stack } : { message : String ( error ) } ,
444+ } ) ;
377445 return { success : false , error : error ?. message || String ( error ) , downloadedName, officialNames } ;
378446 }
379447} ;
@@ -438,22 +506,47 @@ app.on('ready', async () => {
438506 } ) ;
439507 autoUpdater . on ( 'update-available' , ( info ) => {
440508 lastDownloadedUpdateValidation = null ;
441- mainLogger . info ( 'Update available.' , info ) ;
509+ mainLogger . info ( 'Update available.' , {
510+ version : info . version ,
511+ files : Array . isArray ( info . files ) ? info . files . map ( file => ( {
512+ url : typeof file ?. url === 'string' ? getFileNameFromUrlLike ( file . url ) : undefined ,
513+ sha512 : ( file as any ) ?. sha512 ,
514+ size : ( file as any ) ?. size ,
515+ } ) ) : undefined ,
516+ } ) ;
442517 mainWindow ?. webContents . send ( 'update-status-change' , { status : 'available' , message : `Update v${ info . version } available. Downloading...` } ) ;
443518 } ) ;
444519 autoUpdater . on ( 'update-not-available' , ( info ) => {
445- mainLogger . info ( 'Update not available.' , info ) ;
520+ mainLogger . info ( 'Update not available.' , {
521+ version : info ?. version ,
522+ downloadedFile : info ?. downloadedFile ,
523+ } ) ;
446524 } ) ;
447525 autoUpdater . on ( 'error' , ( err ) => {
448526 lastDownloadedUpdateValidation = null ;
449- mainLogger . error ( 'Error in auto-updater.' , err ) ;
527+ mainLogger . error ( 'Error in auto-updater.' , {
528+ message : err ?. message ,
529+ stack : err ?. stack ,
530+ name : err ?. name ,
531+ code : ( err as any ) ?. code ,
532+ details : ( err as any ) ?. body || ( err as any ) ?. data ,
533+ } ) ;
450534 mainWindow ?. webContents . send ( 'update-status-change' , { status : 'error' , message : `Error in auto-updater: ${ err . message } ` } ) ;
451535 } ) ;
452536 autoUpdater . on ( 'download-progress' , ( progressObj ) => {
453537 const log_message = `Downloaded ${ progressObj . percent . toFixed ( 2 ) } %` ;
454538 mainLogger . debug ( log_message ) ;
455539 } ) ;
456540 autoUpdater . on ( 'update-downloaded' , ( info ) => {
541+ mainLogger . info ( 'Update downloaded event received. Validating filename.' , {
542+ version : info . version ,
543+ downloadedFile : info . downloadedFile ,
544+ files : Array . isArray ( info . files ) ? info . files . map ( file => ( {
545+ url : typeof file ?. url === 'string' ? getFileNameFromUrlLike ( file . url ) : undefined ,
546+ sha512 : ( file as any ) ?. sha512 ,
547+ size : ( file as any ) ?. size ,
548+ } ) ) : undefined ,
549+ } ) ;
457550 void ( async ( ) => {
458551 try {
459552 const validationResult = await ensureDownloadedFileMatchesOfficialRelease ( info ) ;
@@ -501,7 +594,33 @@ app.on('ready', async () => {
501594 } ) ;
502595
503596 // Check for updates
504- autoUpdater . checkForUpdatesAndNotify ( ) ;
597+ mainLogger . info ( 'Triggering auto-updater checkForUpdatesAndNotify call.' ) ;
598+ autoUpdater . checkForUpdatesAndNotify ( )
599+ . then ( result => {
600+ if ( ! result ) {
601+ mainLogger . info ( 'Auto-updater checkForUpdatesAndNotify resolved without update info.' ) ;
602+ return ;
603+ }
604+ mainLogger . info ( 'Auto-updater checkForUpdatesAndNotify resolved.' , {
605+ updateInfo : result . updateInfo ? {
606+ version : result . updateInfo . version ,
607+ files : Array . isArray ( result . updateInfo . files ) ? result . updateInfo . files . map ( file => ( {
608+ url : typeof file ?. url === 'string' ? getFileNameFromUrlLike ( file . url ) : undefined ,
609+ sha512 : ( file as any ) ?. sha512 ,
610+ size : ( file as any ) ?. size ,
611+ } ) ) : undefined ,
612+ } : undefined ,
613+ downloadPromise : Boolean ( result . downloadPromise ) ,
614+ } ) ;
615+ } )
616+ . catch ( error => {
617+ mainLogger . error ( 'checkForUpdatesAndNotify rejected.' , {
618+ message : error ?. message ,
619+ stack : error ?. stack ,
620+ name : error ?. name ,
621+ } ) ;
622+ mainWindow ?. webContents . send ( 'update-status-change' , { status : 'error' , message : `Failed to check for updates: ${ error ?. message || error } ` } ) ;
623+ } ) ;
505624 } else {
506625 mainLogger . info ( 'App is not packaged, skipping auto-updater.' ) ;
507626 }
0 commit comments