@@ -344,14 +344,18 @@ def validate_binary_path():
344344 methods = ['GET' ])
345345@pga_login_required
346346def upgrade_check ():
347+ """
348+ Check for application updates and return update metadata to the client.
349+ - Compares current version with remote version data.
350+ - Supports auto-update in desktop mode.
351+ """
352+ # Determine if this check was manually triggered by the user
347353 trigger_update_check = (request .args .get ('trigger_update_check' , 'false' )
348354 .lower () == 'true' )
349- # Get the current version info from the website, and flash a message if
350- # the user is out of date, and the check is enabled.
355+
351356 platform = None
352- ret = {
353- "outdated" : False ,
354- }
357+ ret = {"outdated" : False }
358+
355359 if config .UPGRADE_CHECK_ENABLED :
356360 last_check = get_setting ('LastUpdateCheck' , default = '0' )
357361 today = time .strftime ('%Y%m%d' )
@@ -360,6 +364,8 @@ def upgrade_check():
360364 url = '%s?version=%s' % (
361365 config .UPGRADE_CHECK_URL , config .APP_VERSION )
362366 current_app .logger .debug ('Checking version data at: %s' % url )
367+
368+ # Attempt to fetch upgrade data from remote URL
363369 try :
364370 # Do not wait for more than 5 seconds.
365371 # It stuck on rendering the browser.html, while working in the
@@ -388,62 +394,39 @@ def upgrade_check():
388394 'Exception when checking for update' )
389395 return internal_server_error ('Failed to check for update' )
390396
391- if data is not None :
397+ if data :
398+ # Determine platform
392399 if sys .platform == 'darwin' :
393400 platform = 'macos'
394401 elif sys .platform == 'win32' :
395402 platform = 'windows'
396403
397- auto_update_supported_update_res = {
398- "outdated" : True ,
399- "check_for_auto_updates" : True ,
400- "auto_update_url" : data [config .UPGRADE_CHECK_KEY ][
401- 'auto_update_url' ][platform ],
402- "platform" : platform ,
403- "installer_type" : config .UPGRADE_CHECK_KEY ,
404- "current_version" : config .APP_VERSION ,
405- "upgrade_version" : data [config .UPGRADE_CHECK_KEY ][
406- 'version' ],
407- "current_version_int" : config .APP_VERSION_INT ,
408- "upgrade_version_int" : data [config .UPGRADE_CHECK_KEY ][
409- 'version_int' ],
410- "product_name" : config .APP_NAME ,
411- "download_url" : data [config .UPGRADE_CHECK_KEY ][
412- 'download_url' ]
413- }
414- auto_update_supported_no_update_res = {
415- "outdated" : False ,
404+ upgrade_version_int = data [config .UPGRADE_CHECK_KEY ]['version_int' ]
405+ auto_update_url_exists = data [config .UPGRADE_CHECK_KEY ][
406+ 'auto_update_url' ][platform ] != ''
407+
408+ # Construct common response dicts for auto-update support
409+ auto_update_common_res = {
416410 "check_for_auto_updates" : True ,
417411 "auto_update_url" : data [config .UPGRADE_CHECK_KEY ][
418412 'auto_update_url' ][platform ],
419413 "platform" : platform ,
420414 "installer_type" : config .UPGRADE_CHECK_KEY ,
421415 "current_version" : config .APP_VERSION ,
422- "upgrade_version" : data [config .UPGRADE_CHECK_KEY ][
423- 'version' ],
416+ "upgrade_version" : data [config .UPGRADE_CHECK_KEY ]['version' ],
424417 "current_version_int" : config .APP_VERSION_INT ,
425- "upgrade_version_int" : data [config .UPGRADE_CHECK_KEY ][
426- 'version_int' ],
418+ "upgrade_version_int" : upgrade_version_int ,
427419 "product_name" : config .APP_NAME ,
428- "download_url" : data [config .UPGRADE_CHECK_KEY ][
429- 'download_url' ]
430420 }
421+
431422 # Check for updates if the last check was before today(daily check)
432423 if int (last_check ) < int (today ):
433- # Check if the fetched data is valid and if the latest
434- # version is newer than the current version.
435- if data [config .UPGRADE_CHECK_KEY ]['version_int' ] > \
436- config .APP_VERSION_INT :
437- # In desktop mode with a valid URL, enable
438- # auto-update in the client response.
439- if (not config .SERVER_MODE and
440- data [config .UPGRADE_CHECK_KEY ][
441- 'auto_update_url' ][platform ] != '' ):
442- ret = auto_update_supported_update_res
424+ # App is outdated
425+ if upgrade_version_int > config .APP_VERSION_INT :
426+ if not config .SERVER_MODE and auto_update_url_exists :
427+ ret = {** auto_update_common_res , "outdated" : True }
443428 else :
444- # For server mode or unsupported auto-update,
445- # show update but disable auto-update and
446- # provide download link.
429+ # Auto-update unsupported
447430 ret = {
448431 "outdated" : True ,
449432 "check_for_auto_updates" : False ,
@@ -454,26 +437,21 @@ def upgrade_check():
454437 "download_url" : data [config .UPGRADE_CHECK_KEY ][
455438 'download_url' ]
456439 }
457- # In desktop mode, app is up-to-date but inform client
458- # about auto-update support.
459- elif (data [config .UPGRADE_CHECK_KEY ]['version_int' ] ==
460- config .APP_VERSION_INT and
461- not config .SERVER_MODE and
462- data [config .UPGRADE_CHECK_KEY ]['auto_update_url' ][
463- platform ] != '' ):
464- ret = auto_update_supported_no_update_res
465- # If checked today, in desktop mode, and auto-update URL exists,
466- # inform client about auto-update support.
467- elif (int (last_check ) == int (today ) and not config .SERVER_MODE and
468- data [config .UPGRADE_CHECK_KEY ][
469- 'auto_update_url' ][platform ] != '' ):
440+ # App is up-to-date, but auto-update should be enabled
441+ elif (upgrade_version_int == config .APP_VERSION_INT and
442+ not config .SERVER_MODE and auto_update_url_exists ):
443+ ret = {** auto_update_common_res , "outdated" : False }
444+ # If already checked today,
445+ # return auto-update info only if supported
446+ elif (int (last_check ) == int (today ) and
447+ not config .SERVER_MODE and auto_update_url_exists ):
470448 # Check for updates when triggered by user
471449 # and new version is available
472- if data [ config . UPGRADE_CHECK_KEY ][ 'version_int' ] > \
473- config . APP_VERSION_INT and trigger_update_check :
474- ret = auto_update_supported_update_res
450+ if ( upgrade_version_int > config . APP_VERSION_INT and
451+ trigger_update_check ) :
452+ ret = { ** auto_update_common_res , "outdated" : True }
475453 else :
476- ret = auto_update_supported_no_update_res
454+ ret = { ** auto_update_common_res , "outdated" : False }
477455
478456 store_setting ('LastUpdateCheck' , today )
479457 return make_json_response (data = ret )
0 commit comments