({
pgAdminMainScreen,
configStore,
menuCallbacks,
baseUrl,
UUID,
forceQuitAndInstallUpdate,
})
| 60 | |
| 61 | // Handles 'sendDataForAppUpdate' IPC event: updates config, refreshes menus, triggers update check, or installs update if requested. |
| 62 | function handleSendDataForAppUpdate({ |
| 63 | pgAdminMainScreen, |
| 64 | configStore, |
| 65 | menuCallbacks, |
| 66 | baseUrl, |
| 67 | UUID, |
| 68 | forceQuitAndInstallUpdate, |
| 69 | }) { |
| 70 | return (_, data) => { |
| 71 | // Only update the auto-update enabled flag and refresh menus if the value has changed or is not set |
| 72 | if (typeof data.check_for_updates !== 'undefined') { |
| 73 | const currentFlag = configStore.get('auto_update_enabled'); |
| 74 | if (typeof currentFlag === 'undefined' || currentFlag !== data.check_for_updates) { |
| 75 | configStore.set('auto_update_enabled', data.check_for_updates); |
| 76 | refreshMenus(pgAdminMainScreen, configStore, menuCallbacks); |
| 77 | } |
| 78 | } |
| 79 | // If auto-update is enabled, proceed with the update check |
| 80 | if ( |
| 81 | data.auto_update_url && |
| 82 | data.upgrade_version && |
| 83 | data.upgrade_version_int && |
| 84 | data.current_version_int && |
| 85 | data.product_name |
| 86 | ) { |
| 87 | const ftpUrl = encodeURIComponent( |
| 88 | `${data.auto_update_url}/pgadmin4-${data.upgrade_version}-${process.arch}.zip`, |
| 89 | ); |
| 90 | let serverUrl = `${baseUrl}/misc/auto_update/${data.current_version_int}/${data.upgrade_version}/${data.upgrade_version_int}/${data.product_name}/${ftpUrl}/?key=${UUID}`; |
| 91 | |
| 92 | try { |
| 93 | autoUpdater.setFeedURL({ url: serverUrl }); |
| 94 | misc.writeServerLog('[Auto-Updater]: Initiating update check.'); |
| 95 | autoUpdater.checkForUpdates(); |
| 96 | } catch (err) { |
| 97 | misc.writeServerLog('[Auto-Updater]: Error setting autoUpdater feed URL: ' + err.message); |
| 98 | if (pgAdminMainScreen) { |
| 99 | pgAdminMainScreen.webContents.send('notifyAppAutoUpdate', { |
| 100 | error: true, |
| 101 | errMsg: 'Failed to check for updates. Please try again later.', |
| 102 | }); |
| 103 | } |
| 104 | return; |
| 105 | } |
| 106 | } |
| 107 | // If the user has requested to install the update immediately |
| 108 | if (data.install_update_now) { |
| 109 | forceQuitAndInstallUpdate(); |
| 110 | } |
| 111 | }; |
| 112 | } |
| 113 | |
| 114 | export function setupAutoUpdater({ |
| 115 | pgAdminMainScreen, |
no test coverage detected