@@ -46,6 +46,38 @@ log.catchErrors({
4646console . log ( `Log file will be written to: ${ log . transports . file . getFile ( ) . path } ` ) ;
4747
4848let mainWindow : BrowserWindow | null ;
49+ let autoCheckEnabled = true ;
50+ let pendingAutoUpdateCheck : NodeJS . Timeout | null = null ;
51+
52+ const cancelScheduledAutoUpdateCheck = ( ) => {
53+ if ( pendingAutoUpdateCheck ) {
54+ clearTimeout ( pendingAutoUpdateCheck ) ;
55+ pendingAutoUpdateCheck = null ;
56+ }
57+ } ;
58+
59+ const scheduleAutoUpdateCheck = ( delayMs = 3000 ) => {
60+ if ( ! autoCheckEnabled ) {
61+ console . log ( 'Automatic update checks are disabled; skipping schedule.' ) ;
62+ return ;
63+ }
64+
65+ cancelScheduledAutoUpdateCheck ( ) ;
66+
67+ pendingAutoUpdateCheck = setTimeout ( async ( ) => {
68+ pendingAutoUpdateCheck = null ;
69+ if ( ! autoCheckEnabled ) {
70+ console . log ( 'Automatic update checks disabled before execution; skipping update check.' ) ;
71+ return ;
72+ }
73+
74+ try {
75+ await autoUpdater . checkForUpdatesAndNotify ( ) ;
76+ } catch ( error ) {
77+ console . error ( 'Automatic update check failed:' , error ) ;
78+ }
79+ } , delayMs ) ;
80+ } ;
4981
5082const broadcastPythonEvent = ( channel : string , payload : any ) => {
5183 const targets = BrowserWindow . getAllWindows ( ) ;
@@ -153,10 +185,25 @@ app.on('ready', () => {
153185 // The renderer process will detect the failure when it tries to communicate
154186 // via IPC and will display the fatal error screen. We still create the window.
155187 }
156-
188+
157189 createWindow ( ) ;
158- // Check for updates after window is created
159- setTimeout ( ( ) => autoUpdater . checkForUpdatesAndNotify ( ) , 3000 ) ;
190+
191+ try {
192+ const storedPreference = databaseService . getSetting ( 'autoCheckForUpdates' ) ;
193+ if ( typeof storedPreference === 'boolean' ) {
194+ autoCheckEnabled = storedPreference ;
195+ } else if ( typeof storedPreference !== 'undefined' ) {
196+ autoCheckEnabled = Boolean ( storedPreference ) ;
197+ }
198+ } catch ( error ) {
199+ console . error ( 'Failed to read auto-update preference from settings:' , error ) ;
200+ }
201+
202+ if ( autoCheckEnabled ) {
203+ scheduleAutoUpdateCheck ( ) ;
204+ } else {
205+ console . log ( 'Automatic update checks are disabled via settings.' ) ;
206+ }
160207} ) ;
161208
162209app . on ( 'window-all-closed' , ( ) => {
@@ -393,9 +440,38 @@ ipcMain.handle('app:get-log-path', () => log.transports.file.getFile().path);
393440ipcMain . on ( 'updater:set-allow-prerelease' , ( _ , allow : boolean ) => {
394441 autoUpdater . allowPrerelease = allow ;
395442} ) ;
443+ ipcMain . on ( 'updater:set-auto-check-enabled' , ( _ , enabled : boolean ) => {
444+ autoCheckEnabled = enabled ;
445+ if ( enabled ) {
446+ scheduleAutoUpdateCheck ( ) ;
447+ } else {
448+ cancelScheduledAutoUpdateCheck ( ) ;
449+ }
450+ } ) ;
396451ipcMain . on ( 'updater:quit-and-install' , ( ) => {
397452 autoUpdater . quitAndInstall ( ) ;
398453} ) ;
454+ ipcMain . handle ( 'updater:check-now' , async ( ) => {
455+ try {
456+ const result = await autoUpdater . checkForUpdates ( ) ;
457+ const updateInfo = result ?. updateInfo ;
458+ const version = updateInfo ?. version ?? null ;
459+ const releaseName = updateInfo ?. releaseName ?? null ;
460+ const currentVersion = app . getVersion ( ) ;
461+ const updateAvailable = Boolean ( version && version !== currentVersion ) ;
462+
463+ return {
464+ success : true ,
465+ updateAvailable,
466+ version,
467+ releaseName,
468+ } ;
469+ } catch ( error ) {
470+ const message = error instanceof Error ? error . message : String ( error ) ;
471+ console . error ( 'Manual update check failed:' , message ) ;
472+ return { success : false , error : message } ;
473+ }
474+ } ) ;
399475
400476
401477// Window Controls
0 commit comments