@@ -355,114 +355,125 @@ def upgrade_check():
355
355
if config .UPGRADE_CHECK_ENABLED :
356
356
last_check = get_setting ('LastUpdateCheck' , default = '0' )
357
357
today = time .strftime ('%Y%m%d' )
358
- # Check for updates if either:
359
- # - The last check was before today (daily check), or
360
- # - The user manually triggered an update check
361
- if int (last_check ) < int (today ) or trigger_update_check :
362
- data = None
363
- url = '%s?version=%s' % (
364
- config .UPGRADE_CHECK_URL , config .APP_VERSION )
365
- current_app .logger .debug ('Checking version data at: %s' % url )
366
- try :
367
- # Do not wait for more than 5 seconds.
368
- # It stuck on rendering the browser.html, while working in the
369
- # broken network.
370
- if os .path .exists (config .CA_FILE ) and sys .version_info >= (
371
- 3 , 13 ):
372
- # Use SSL context for Python 3.13+
373
- context = ssl .create_default_context (cafile = config .CA_FILE )
374
- response = urlopen (url , data = data , timeout = 5 ,
375
- context = context )
376
- elif os .path .exists (config .CA_FILE ):
377
- # Use cafile parameter for older versions
378
- response = urlopen (url , data = data , timeout = 5 ,
379
- cafile = config .CA_FILE )
380
- else :
381
- response = urlopen (url , data , 5 )
382
- current_app .logger .debug (
383
- 'Version check HTTP response code: %d' % response .getcode ()
384
- )
385
358
386
- if response .getcode () == 200 :
387
- data = json .loads (response .read ().decode ('utf-8' ))
388
- current_app .logger .debug ('Response data: %s' % data )
389
- except Exception :
390
- current_app .logger .exception (
391
- 'Exception when checking for update' )
392
- return internal_server_error ('Failed to check for update' )
359
+ data = None
360
+ url = '%s?version=%s' % (
361
+ config .UPGRADE_CHECK_URL , config .APP_VERSION )
362
+ current_app .logger .debug ('Checking version data at: %s' % url )
363
+ try :
364
+ # Do not wait for more than 5 seconds.
365
+ # It stuck on rendering the browser.html, while working in the
366
+ # broken network.
367
+ if os .path .exists (config .CA_FILE ) and sys .version_info >= (
368
+ 3 , 13 ):
369
+ # Use SSL context for Python 3.13+
370
+ context = ssl .create_default_context (cafile = config .CA_FILE )
371
+ response = urlopen (url , data = data , timeout = 5 ,
372
+ context = context )
373
+ elif os .path .exists (config .CA_FILE ):
374
+ # Use cafile parameter for older versions
375
+ response = urlopen (url , data = data , timeout = 5 ,
376
+ cafile = config .CA_FILE )
377
+ else :
378
+ response = urlopen (url , data , 5 )
379
+ current_app .logger .debug (
380
+ 'Version check HTTP response code: %d' % response .getcode ()
381
+ )
393
382
383
+ if response .getcode () == 200 :
384
+ data = json .loads (response .read ().decode ('utf-8' ))
385
+ current_app .logger .debug ('Response data: %s' % data )
386
+ except Exception :
387
+ current_app .logger .exception (
388
+ 'Exception when checking for update' )
389
+ return internal_server_error ('Failed to check for update' )
390
+
391
+ if data is not None :
394
392
if sys .platform == 'darwin' :
395
393
platform = 'macos'
396
394
elif sys .platform == 'win32' :
397
395
platform = 'windows'
398
396
399
- # Check if the fetched data is valid and if the latest
400
- # version is newer than the current version.
401
- if data is not None and \
402
- data [config .UPGRADE_CHECK_KEY ]['version_int' ] > \
403
- config .APP_VERSION_INT :
404
- # If running in desktop mode with a valid auto-update
405
- # URL for the current platform, prepare a response that
406
- # enables the auto-update feature in the client.
407
- if not config .SERVER_MODE and data [config .UPGRADE_CHECK_KEY ][
408
- 'auto_update_url' ][platform ] != '' :
409
- ret = {
410
- "outdated" : True ,
411
- "check_for_auto_updates" : True ,
412
- "auto_update_url" : data [config .UPGRADE_CHECK_KEY ][
413
- 'auto_update_url' ][platform ],
414
- "platform" : platform ,
415
- "installer_type" : config .UPGRADE_CHECK_KEY ,
416
- "current_version" : config .APP_VERSION ,
417
- "upgrade_version" : data [config .UPGRADE_CHECK_KEY ][
418
- 'version' ],
419
- "current_version_int" : config .APP_VERSION_INT ,
420
- "upgrade_version_int" : data [config .UPGRADE_CHECK_KEY ][
421
- 'version_int' ],
422
- "product_name" : config .APP_NAME ,
423
- "download_url" : data [config .UPGRADE_CHECK_KEY ][
424
- 'download_url' ]
425
- }
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 ,
416
+ "check_for_auto_updates" : True ,
417
+ "auto_update_url" : data [config .UPGRADE_CHECK_KEY ][
418
+ 'auto_update_url' ][platform ],
419
+ "platform" : platform ,
420
+ "installer_type" : config .UPGRADE_CHECK_KEY ,
421
+ "current_version" : config .APP_VERSION ,
422
+ "upgrade_version" : data [config .UPGRADE_CHECK_KEY ][
423
+ 'version' ],
424
+ "current_version_int" : config .APP_VERSION_INT ,
425
+ "upgrade_version_int" : data [config .UPGRADE_CHECK_KEY ][
426
+ 'version_int' ],
427
+ "product_name" : config .APP_NAME ,
428
+ "download_url" : data [config .UPGRADE_CHECK_KEY ][
429
+ 'download_url' ]
430
+ }
431
+ # Check for updates if the last check was before today(daily check)
432
+ 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
443
+ else :
444
+ # For server mode or unsupported auto-update,
445
+ # show update but disable auto-update and
446
+ # provide download link.
447
+ ret = {
448
+ "outdated" : True ,
449
+ "check_for_auto_updates" : False ,
450
+ "current_version" : config .APP_VERSION ,
451
+ "upgrade_version" : data [config .UPGRADE_CHECK_KEY ][
452
+ 'version' ],
453
+ "product_name" : config .APP_NAME ,
454
+ "download_url" : data [config .UPGRADE_CHECK_KEY ][
455
+ 'download_url' ]
456
+ }
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 ] != '' ):
470
+ # Check for updates when triggered by user
471
+ # 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
426
475
else :
427
- # For server mode or if auto-update is not supported,
428
- # indicate an update is available but disable
429
- # the auto-update feature. The user will be
430
- # directed to the download URL.
431
- ret = {
432
- "outdated" : True ,
433
- "check_for_auto_updates" : False ,
434
- "current_version" : config .APP_VERSION ,
435
- "upgrade_version" : data [config .UPGRADE_CHECK_KEY ][
436
- 'version' ],
437
- "product_name" : config .APP_NAME ,
438
- "download_url" : data [config .UPGRADE_CHECK_KEY ][
439
- 'download_url' ]
440
- }
441
- # This handles a specific desktop mode case: the current version
442
- # is up-to-date, but we still need to inform the client
443
- # about the auto-update capability.
444
- elif (data [config .UPGRADE_CHECK_KEY ]['version_int' ] ==
445
- config .APP_VERSION_INT and
446
- not config .SERVER_MODE and
447
- data [config .UPGRADE_CHECK_KEY ]['auto_update_url' ][
448
- platform ] != '' ):
449
- ret = {
450
- "outdated" : False ,
451
- "check_for_auto_updates" : True ,
452
- "auto_update_url" : data [config .UPGRADE_CHECK_KEY ][
453
- 'auto_update_url' ][platform ],
454
- "platform" : platform ,
455
- "installer_type" : config .UPGRADE_CHECK_KEY ,
456
- "current_version" : config .APP_VERSION ,
457
- "upgrade_version" : data [config .UPGRADE_CHECK_KEY ][
458
- 'version' ],
459
- "current_version_int" : config .APP_VERSION_INT ,
460
- "upgrade_version_int" : data [config .UPGRADE_CHECK_KEY ][
461
- 'version_int' ],
462
- "product_name" : config .APP_NAME ,
463
- "download_url" : data [config .UPGRADE_CHECK_KEY ][
464
- 'download_url' ]
465
- }
476
+ ret = auto_update_supported_no_update_res
466
477
467
478
store_setting ('LastUpdateCheck' , today )
468
479
return make_json_response (data = ret )
0 commit comments