@@ -344,14 +344,18 @@ def validate_binary_path():
344
344
methods = ['GET' ])
345
345
@pga_login_required
346
346
def 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
347
353
trigger_update_check = (request .args .get ('trigger_update_check' , 'false' )
348
354
.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
+
351
356
platform = None
352
- ret = {
353
- "outdated" : False ,
354
- }
357
+ ret = {"outdated" : False }
358
+
355
359
if config .UPGRADE_CHECK_ENABLED :
356
360
last_check = get_setting ('LastUpdateCheck' , default = '0' )
357
361
today = time .strftime ('%Y%m%d' )
@@ -360,6 +364,8 @@ def upgrade_check():
360
364
url = '%s?version=%s' % (
361
365
config .UPGRADE_CHECK_URL , config .APP_VERSION )
362
366
current_app .logger .debug ('Checking version data at: %s' % url )
367
+
368
+ # Attempt to fetch upgrade data from remote URL
363
369
try :
364
370
# Do not wait for more than 5 seconds.
365
371
# It stuck on rendering the browser.html, while working in the
@@ -388,62 +394,39 @@ def upgrade_check():
388
394
'Exception when checking for update' )
389
395
return internal_server_error ('Failed to check for update' )
390
396
391
- if data is not None :
397
+ if data :
398
+ # Determine platform
392
399
if sys .platform == 'darwin' :
393
400
platform = 'macos'
394
401
elif sys .platform == 'win32' :
395
402
platform = 'windows'
396
403
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 = {
416
410
"check_for_auto_updates" : True ,
417
411
"auto_update_url" : data [config .UPGRADE_CHECK_KEY ][
418
412
'auto_update_url' ][platform ],
419
413
"platform" : platform ,
420
414
"installer_type" : config .UPGRADE_CHECK_KEY ,
421
415
"current_version" : config .APP_VERSION ,
422
- "upgrade_version" : data [config .UPGRADE_CHECK_KEY ][
423
- 'version' ],
416
+ "upgrade_version" : data [config .UPGRADE_CHECK_KEY ]['version' ],
424
417
"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 ,
427
419
"product_name" : config .APP_NAME ,
428
- "download_url" : data [config .UPGRADE_CHECK_KEY ][
429
- 'download_url' ]
430
420
}
421
+
431
422
# Check for updates if the last check was before today(daily check)
432
423
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 }
443
428
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
447
430
ret = {
448
431
"outdated" : True ,
449
432
"check_for_auto_updates" : False ,
@@ -454,26 +437,21 @@ def upgrade_check():
454
437
"download_url" : data [config .UPGRADE_CHECK_KEY ][
455
438
'download_url' ]
456
439
}
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 ):
470
448
# Check for updates when triggered by user
471
449
# 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 }
475
453
else :
476
- ret = auto_update_supported_no_update_res
454
+ ret = { ** auto_update_common_res , "outdated" : False }
477
455
478
456
store_setting ('LastUpdateCheck' , today )
479
457
return make_json_response (data = ret )
0 commit comments