@@ -47,6 +47,38 @@ log.catchErrors({
4747console . log ( `Log file will be written to: ${ log . transports . file . getFile ( ) . path } ` ) ;
4848
4949let mainWindow : BrowserWindow | null ;
50+ let autoCheckEnabled = true ;
51+ let pendingAutoUpdateCheck : NodeJS . Timeout | null = null ;
52+
53+ const cancelScheduledAutoUpdateCheck = ( ) => {
54+ if ( pendingAutoUpdateCheck ) {
55+ clearTimeout ( pendingAutoUpdateCheck ) ;
56+ pendingAutoUpdateCheck = null ;
57+ }
58+ } ;
59+
60+ const scheduleAutoUpdateCheck = ( delayMs = 3000 ) => {
61+ if ( ! autoCheckEnabled ) {
62+ console . log ( 'Automatic update checks are disabled; skipping schedule.' ) ;
63+ return ;
64+ }
65+
66+ cancelScheduledAutoUpdateCheck ( ) ;
67+
68+ pendingAutoUpdateCheck = setTimeout ( async ( ) => {
69+ pendingAutoUpdateCheck = null ;
70+ if ( ! autoCheckEnabled ) {
71+ console . log ( 'Automatic update checks disabled before execution; skipping update check.' ) ;
72+ return ;
73+ }
74+
75+ try {
76+ await autoUpdater . checkForUpdatesAndNotify ( ) ;
77+ } catch ( error ) {
78+ console . error ( 'Automatic update check failed:' , error ) ;
79+ }
80+ } , delayMs ) ;
81+ } ;
5082
5183const broadcastPythonEvent = ( channel : string , payload : any ) => {
5284 const targets = BrowserWindow . getAllWindows ( ) ;
@@ -186,10 +218,25 @@ app.on('ready', () => {
186218 // The renderer process will detect the failure when it tries to communicate
187219 // via IPC and will display the fatal error screen. We still create the window.
188220 }
189-
221+
190222 createWindow ( ) ;
191- // Check for updates after window is created
192- setTimeout ( ( ) => autoUpdater . checkForUpdatesAndNotify ( ) , 3000 ) ;
223+
224+ try {
225+ const storedPreference = databaseService . getSetting ( 'autoCheckForUpdates' ) ;
226+ if ( typeof storedPreference === 'boolean' ) {
227+ autoCheckEnabled = storedPreference ;
228+ } else if ( typeof storedPreference !== 'undefined' ) {
229+ autoCheckEnabled = Boolean ( storedPreference ) ;
230+ }
231+ } catch ( error ) {
232+ console . error ( 'Failed to read auto-update preference from settings:' , error ) ;
233+ }
234+
235+ if ( autoCheckEnabled ) {
236+ scheduleAutoUpdateCheck ( ) ;
237+ } else {
238+ console . log ( 'Automatic update checks are disabled via settings.' ) ;
239+ }
193240} ) ;
194241
195242app . on ( 'window-all-closed' , ( ) => {
@@ -426,9 +473,38 @@ ipcMain.handle('app:get-log-path', () => log.transports.file.getFile().path);
426473ipcMain . on ( 'updater:set-allow-prerelease' , ( _ , allow : boolean ) => {
427474 autoUpdater . allowPrerelease = allow ;
428475} ) ;
476+ ipcMain . on ( 'updater:set-auto-check-enabled' , ( _ , enabled : boolean ) => {
477+ autoCheckEnabled = enabled ;
478+ if ( enabled ) {
479+ scheduleAutoUpdateCheck ( ) ;
480+ } else {
481+ cancelScheduledAutoUpdateCheck ( ) ;
482+ }
483+ } ) ;
429484ipcMain . on ( 'updater:quit-and-install' , ( ) => {
430485 autoUpdater . quitAndInstall ( ) ;
431486} ) ;
487+ ipcMain . handle ( 'updater:check-now' , async ( ) => {
488+ try {
489+ const result = await autoUpdater . checkForUpdates ( ) ;
490+ const updateInfo = result ?. updateInfo ;
491+ const version = updateInfo ?. version ?? null ;
492+ const releaseName = updateInfo ?. releaseName ?? null ;
493+ const currentVersion = app . getVersion ( ) ;
494+ const updateAvailable = Boolean ( version && version !== currentVersion ) ;
495+
496+ return {
497+ success : true ,
498+ updateAvailable,
499+ version,
500+ releaseName,
501+ } ;
502+ } catch ( error ) {
503+ const message = error instanceof Error ? error . message : String ( error ) ;
504+ console . error ( 'Manual update check failed:' , message ) ;
505+ return { success : false , error : message } ;
506+ }
507+ } ) ;
432508
433509
434510// Window Controls
0 commit comments