@@ -44,7 +44,6 @@ class TalkitoUpdater:
4444
4545 GITHUB_REPO_URL = "https://github.com/robdmac/talkito"
4646 UPDATE_CHECK_URL = "https://talkito-app-updates.robbomacrae.workers.dev/check-update"
47- UPDATE_CHECK_INTERVAL = 3600 * 24 # Check every day
4847
4948 def __init__ (self ):
5049 self .current_version = __version__
@@ -255,16 +254,6 @@ def _save_state(self, state):
255254 except Exception as e :
256255 log_message ("ERROR" , f"Failed to save update state: { e } " )
257256
258- def should_check_for_updates (self ):
259- """Check if enough time has passed since last update check"""
260- if os .environ .get ('TALKITO_AUTO_UPDATE' , 'true' ).lower () == 'false' :
261- return False
262-
263- state = self ._load_state ()
264- last_check = state .get ('last_check' , 0 )
265- now = time .time ()
266-
267- return (now - last_check ) > self .UPDATE_CHECK_INTERVAL
268257
269258 def stage_update (self , version ):
270259 """Download and stage an update for next restart"""
@@ -345,31 +334,28 @@ def apply_staged_update(self):
345334 log_message ("ERROR" , f"Failed to apply staged update: { e } " )
346335 return False
347336
348- def _background_check_loop (self ):
349- """Background thread that periodically checks for updates"""
350- while not self ._stop_event .is_set ():
351- try :
352- if self .should_check_for_updates ():
353- latest_version , update_available = self .check_for_updates ()
354-
355- if update_available :
356- log_message ("INFO" , f"Update available: { latest_version } " )
357- # Stage the update in background
358- if self .stage_update (latest_version ):
359- log_message ("INFO" , f"Update { latest_version } staged for next restart" )
360-
361- # Update last check time
362- state = self ._load_state ()
363- state ['last_check' ] = time .time ()
364- self ._save_state (state )
365-
366- except Exception as e :
367- log_message ("ERROR" , f"Error in background update check: { e } " )
337+ def _background_check_once (self ):
338+ """Background thread that checks for updates once on startup"""
339+ try :
340+ log_message ("INFO" , f"Checking for updates (current: { self .current_version } , method: { self .get_update_method ()} )" )
341+ latest_version , update_available = self .check_for_updates ()
342+
343+ if latest_version :
344+ if update_available :
345+ log_message ("INFO" , f"Update available: { self .current_version } -> { latest_version } " )
346+ # Stage the update in background
347+ if self .stage_update (latest_version ):
348+ log_message ("INFO" , f"Update { latest_version } staged for next restart" )
349+ else :
350+ log_message ("INFO" , f"Up to date (current: { self .current_version } , latest: { latest_version } )" )
368351
369- # Sleep for a while, but check stop event regularly
370- for _ in range (60 ): # Check every minute
371- if self ._stop_event .wait (60 ):
372- break
352+ # Update last check time
353+ state = self ._load_state ()
354+ state ['last_check' ] = time .time ()
355+ self ._save_state (state )
356+
357+ except Exception as e :
358+ log_message ("ERROR" , f"Error in background update check: { e } " )
373359
374360 def start_background_updates (self ):
375361 """Start background update checking"""
@@ -379,7 +365,7 @@ def start_background_updates(self):
379365
380366 if self ._background_thread is None or not self ._background_thread .is_alive ():
381367 self ._background_thread = threading .Thread (
382- target = self ._background_check_loop ,
368+ target = self ._background_check_once ,
383369 daemon = True ,
384370 name = "TalkitoUpdateChecker"
385371 )
@@ -406,6 +392,25 @@ def check_and_apply_staged_update():
406392 return False
407393
408394
395+ def check_for_updates_now ():
396+ """Do an immediate update check and log the result"""
397+ try :
398+ updater = TalkitoUpdater ()
399+ log_message ("INFO" , f"Immediate update check (current: { updater .current_version } , method: { updater .get_update_method ()} )" )
400+ latest_version , update_available = updater .check_for_updates ()
401+
402+ if latest_version :
403+ if update_available :
404+ log_message ("INFO" , f"Update available: { updater .current_version } -> { latest_version } " )
405+ else :
406+ log_message ("INFO" , f"Up to date (current: { updater .current_version } , latest: { latest_version } )" )
407+
408+ return latest_version , update_available
409+ except Exception as e :
410+ log_message ("ERROR" , f"Failed immediate update check: { e } " )
411+ return None , False
412+
413+
409414def start_background_update_checker ():
410415 """Start the background update checker (called on startup)"""
411416 try :
0 commit comments