Skip to content

Commit d153117

Browse files
committed
Code cleaned, removed consoles
1 parent e652466 commit d153117

File tree

6 files changed

+42
-67
lines changed

6 files changed

+42
-67
lines changed

docs/en_US/desktop_deployment.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Technical Architecture
177177

178178
Handles core update functionality:
179179

180-
File: runtime/src/js/pgadmin.js
180+
File: runtime/src/js/autoUpdaterHandler.js
181181

182182
.. code-block:: javascript
183183

runtime/src/js/pgadmin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import path from 'path';
1414
import * as misc from './misc.js';
1515
import { spawn } from 'child_process';
1616
import { fileURLToPath } from 'url';
17-
import { setupMenu, refreshMenus } from './menu.js';
17+
import { setupMenu } from './menu.js';
1818
import contextMenu from 'electron-context-menu';
1919
import { setupDownloader } from './downloader.js';
2020
import { setupAutoUpdater, updateConfigAndMenus } from './autoUpdaterHandler.js';

runtime/src/js/pgadmin_preload.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ contextBridge.exposeInMainWorld('electronUI', {
3232
downloadStreamSaveEnd: (...args) => ipcRenderer.send('download-stream-save-end', ...args),
3333
downloadBase64UrlData: (...args) => ipcRenderer.invoke('download-base64-url-data', ...args),
3434
downloadTextData: (...args) => ipcRenderer.invoke('download-text-data', ...args),
35+
//Auto-updater related functions
3536
sendDataForAppUpdate: (data) => ipcRenderer.send('sendDataForAppUpdate', data),
3637
notifyAppAutoUpdate: (callback) => {
3738
ipcRenderer.removeAllListeners('notifyAppAutoUpdate'); // Clean up previous listeners

web/pgadmin/misc/__init__.py

Lines changed: 39 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,18 @@ def validate_binary_path():
344344
methods=['GET'])
345345
@pga_login_required
346346
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
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)

web/pgadmin/static/js/BrowserComponent.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ 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');
209208
const UPDATE_INSTALLED_MESSAGE = gettext('Update installed successfully!');
210209
appAutoUpdateNotifier(UPDATE_INSTALLED_MESSAGE, 'success');
211210
}

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

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

9898
// Mark this warning as active
9999
activeWarningKeys.add(uniqueKey);
100-
console.warn('before if',desc,type);
101100
if (type == 'warning') {
102101
pgAdmin.Browser.notifier.notify(
103102
<UpdateWarningNotifier
@@ -113,12 +112,10 @@ export function appAutoUpdateNotifier(desc, type, onClick, hideDuration=null, ti
113112
/>, null
114113
);
115114
} else if(type == 'success') {
116-
console.warn('inside if',desc,type);
117115
pgAdmin.Browser.notifier.success(desc, hideDuration);
118116
} else if(type == 'info') {
119117
pgAdmin.Browser.notifier.info(desc, hideDuration);
120118
} else if(type == 'error') {
121-
console.warn('desc',desc);
122119
pgAdmin.Browser.notifier.error(desc, hideDuration);
123120
}
124121

0 commit comments

Comments
 (0)