Skip to content

Commit e652466

Browse files
committed
Fixed an issue where the 'Check for Updates' button did not appear after application restart if the /upgrade_check API had already been called earlier that day.
1 parent 81b1195 commit e652466

File tree

6 files changed

+136
-115
lines changed

6 files changed

+136
-115
lines changed

runtime/src/js/pgadmin.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -440,18 +440,26 @@ let splashWindow;
440440
// Helper to notify update installed after restart
441441
function notifyUpdateInstalled() {
442442
if (configStore.get('update_installed')) {
443-
// Reset the flag
444-
configStore.set('update_installed', false);
445-
// Notify renderer
446-
if (pgAdminMainScreen) {
447-
misc.writeServerLog('[Auto-Updater]: Update installed successfully...');
448-
pgAdminMainScreen.webContents.send('notifyAppAutoUpdate', {update_installed: true});
449-
} else {
450-
// If main screen not ready, wait and send after it's created
451-
app.once('browser-window-created', (event, window) => {
443+
try {
444+
// Notify renderer
445+
if (pgAdminMainScreen) {
452446
misc.writeServerLog('[Auto-Updater]: Update installed successfully...');
453-
window.webContents.send('notifyAppAutoUpdate', {update_installed: true});
454-
});
447+
setTimeout(() => {
448+
pgAdminMainScreen.webContents.send('notifyAppAutoUpdate', {update_installed: true});
449+
}, 10000);
450+
} else {
451+
// If main screen not ready, wait and send after it's created
452+
app.once('browser-window-created', (event, window) => {
453+
misc.writeServerLog('[Auto-Updater]: Update installed successfully...');
454+
setTimeout(() => {
455+
pgAdminMainScreen.webContents.send('notifyAppAutoUpdate', {update_installed: true});
456+
}, 10000);
457+
});
458+
}
459+
// Reset the flag
460+
configStore.set('update_installed', false);
461+
} catch (err) {
462+
misc.writeServerLog(`[Auto-Updater]: ${err}`);
455463
}
456464
}
457465
}

web/pgadmin/browser/static/js/browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ define('pgadmin.browser', [
280280
'check_for_updates': data.check_for_auto_updates,
281281
});
282282
const isDesktopWithAutoUpdate = pgAdmin.server_mode == 'False' && data.check_for_auto_updates && data.auto_update_url !== '';
283-
const isUpdateAvailable = data.upgrade_version_int > data.current_version_int;
283+
const isUpdateAvailable = data.outdated && data.upgrade_version_int > data.current_version_int;
284284
const noUpdateMessage = 'No update available...';
285285
// This is for desktop installers whose auto_update_url is mentioned in https://www.pgadmin.org/versions.json
286286
if (isDesktopWithAutoUpdate) {

web/pgadmin/misc/__init__.py

Lines changed: 111 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -355,114 +355,125 @@ def upgrade_check():
355355
if config.UPGRADE_CHECK_ENABLED:
356356
last_check = get_setting('LastUpdateCheck', default='0')
357357
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-
)
385358

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+
)
393382

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:
394392
if sys.platform == 'darwin':
395393
platform = 'macos'
396394
elif sys.platform == 'win32':
397395
platform = 'windows'
398396

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
426475
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
466477

467478
store_setting('LastUpdateCheck', today)
468479
return make_json_response(data=ret)

web/pgadmin/static/js/BrowserComponent.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export default function BrowserComponent({pgAdmin}) {
205205
} else if (data.error) {
206206
appAutoUpdateNotifier(`${data.errMsg}`, 'error');
207207
} else if (data.update_installed) {
208+
console.warn('in browsercomp------','Update installed');
208209
const UPDATE_INSTALLED_MESSAGE = gettext('Update installed successfully!');
209210
appAutoUpdateNotifier(UPDATE_INSTALLED_MESSAGE, 'success');
210211
}

web/pgadmin/static/js/helpers/appAutoUpdateNotifier.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function appAutoUpdateNotifier(desc, type, onClick, hideDuration=null, ti
9797

9898
// Mark this warning as active
9999
activeWarningKeys.add(uniqueKey);
100-
100+
console.warn('before if',desc,type);
101101
if (type == 'warning') {
102102
pgAdmin.Browser.notifier.notify(
103103
<UpdateWarningNotifier
@@ -113,6 +113,7 @@ export function appAutoUpdateNotifier(desc, type, onClick, hideDuration=null, ti
113113
/>, null
114114
);
115115
} else if(type == 'success') {
116+
console.warn('inside if',desc,type);
116117
pgAdmin.Browser.notifier.success(desc, hideDuration);
117118
} else if(type == 'info') {
118119
pgAdmin.Browser.notifier.info(desc, hideDuration);

web/version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# Application version number components
2020
APP_RELEASE = 9
21-
APP_REVISION = 5
21+
APP_REVISION = 6
2222

2323
# Application version suffix, e.g. 'beta1', 'dev'. Usually an empty string
2424
# for GA releases.
@@ -27,7 +27,7 @@
2727
# Numeric application version for upgrade checks. Should be in the format:
2828
# [X]XYYZZ, where X is the release version, Y is the revision, with a leading
2929
# zero if needed, and Z represents the suffix, with a leading zero if needed
30-
APP_VERSION_INT = 90500
30+
APP_VERSION_INT = 90600
3131

3232
# DO NOT CHANGE!
3333
# The application version string, constructed from the components

0 commit comments

Comments
 (0)