From 100f59f78bf141355f272a21c33413d001c71dd3 Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Wed, 18 Sep 2024 16:43:57 +0530 Subject: [PATCH] Fixed an issue where "Quit App" confirmation modal in desktop app is not respecting "Confirm on close or refresh?". #7890 --- docs/en_US/release_notes_8_12.rst | 3 ++- runtime/src/js/menu.js | 2 +- runtime/src/js/pgadmin.js | 15 ++++++++++++++- runtime/src/js/pgadmin_preload.js | 1 + .../js/components/PreferencesComponent.jsx | 17 ++++++++++++++--- web/pgadmin/static/js/custom_hooks.js | 6 +++++- 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/docs/en_US/release_notes_8_12.rst b/docs/en_US/release_notes_8_12.rst index 1e650c131..48f800296 100644 --- a/docs/en_US/release_notes_8_12.rst +++ b/docs/en_US/release_notes_8_12.rst @@ -31,10 +31,11 @@ Housekeeping Bug fixes ********* - | `Issue #6502 `_ - Fix the query tool restore connection issue on the server disconnection from the left side object explorer. + | `Issue #6502 `_ - Fix the query tool restore connection issue on the server disconnection from the left side object explorer. | `Issue #7076 `_ - Revamp the current password saving implementation to a keyring and reduce repeated OS user password prompts. | `Issue #7571 `_ - Fixed an issue where users could not use pgAdmin if they did not have access to the management database. | `Issue #7811 `_ - Fixed an issue where servers listed in the servers.json file were being reimported upon container restart. | `Issue #7839 `_ - Added support for OIDC based OAuth2 authentication. | `Issue #7878 `_ - Fixed an issue where cursor moves to end of line when editing input fields. + | `Issue #7890 `_ - Fixed an issue where "Quit App" confirmation modal in desktop app is not respecting "Confirm on close or refresh?". | `Issue #7895 `_ - Fixed an issue where different client backend shows all SQL are same. \ No newline at end of file diff --git a/runtime/src/js/menu.js b/runtime/src/js/menu.js index d32801e12..6609d3445 100644 --- a/runtime/src/js/menu.js +++ b/runtime/src/js/menu.js @@ -75,7 +75,7 @@ function buildMenu(pgadminMenus, pgAdminMainScreen, callbacks) { { label: 'View', submenu: [ - { label: 'Reload', click: ()=>BrowserWindow.getFocusedWindow().webContents.reload()}, + { label: 'Reload', click: callbacks['reloadApp']}, { label: 'Toggle Developer Tools', click: ()=>BrowserWindow.getFocusedWindow().webContents.openDevTools({ mode: 'bottom' })}, { type: 'separator' }, { role: 'resetZoom' }, diff --git a/runtime/src/js/pgadmin.js b/runtime/src/js/pgadmin.js index 2ffe091a7..02aeb3a46 100644 --- a/runtime/src/js/pgadmin.js +++ b/runtime/src/js/pgadmin.js @@ -115,6 +115,17 @@ function showErrorDialog(intervalID) { }).loadFile('./src/html/server_error.html'); } +function reloadApp() { + const currWin = BrowserWindow.getFocusedWindow(); + + const preventUnload = (event) => { + event.preventDefault(); + currWin.webContents.off('will-prevent-unload', preventUnload); + }; + currWin.webContents.on('will-prevent-unload', preventUnload) + currWin.webContents.reload(); +} + // This functions is used to start the pgAdmin4 server by spawning a // separate process. function startDesktopMode() { @@ -287,6 +298,7 @@ function launchPgAdminWindow() { }); }, 'configure': openConfigure, + 'reloadApp': reloadApp, }); pgAdminMainScreen.loadURL(startPageUrl); @@ -353,9 +365,10 @@ ipcMain.on('restartApp', ()=>{ app.relaunch(); app.exit(0); }); -ipcMain.handle('log', (text) => ()=>{ +ipcMain.on('log', (text) => ()=>{ misc.writeServerLog(text); }); +ipcMain.on('reloadApp', reloadApp); ipcMain.handle('checkPortAvailable', async (_e, fixedPort)=>{ try { await misc.getAvailablePort(fixedPort); diff --git a/runtime/src/js/pgadmin_preload.js b/runtime/src/js/pgadmin_preload.js index 471c47921..7aedb77d3 100644 --- a/runtime/src/js/pgadmin_preload.js +++ b/runtime/src/js/pgadmin_preload.js @@ -23,4 +23,5 @@ contextBridge.exposeInMainWorld('electronUI', { showOpenDialog: (options) => ipcRenderer.invoke('showOpenDialog', options), showSaveDialog: (options) => ipcRenderer.invoke('showSaveDialog', options), log: (text)=> ipcRenderer.send('log', text), + reloadApp: ()=>{ipcRenderer.send('reloadApp');}, }); \ No newline at end of file diff --git a/web/pgadmin/preferences/static/js/components/PreferencesComponent.jsx b/web/pgadmin/preferences/static/js/components/PreferencesComponent.jsx index 5e4f384d9..0521908b2 100644 --- a/web/pgadmin/preferences/static/js/components/PreferencesComponent.jsx +++ b/web/pgadmin/preferences/static/js/components/PreferencesComponent.jsx @@ -26,6 +26,7 @@ import { DefaultButton, PgIconButton, PrimaryButton } from '../../../../static/j import BaseUISchema from 'sources/SchemaView/base_schema.ui'; import { getBinaryPathSchema } from '../../../../browser/server_groups/servers/static/js/binary_path.ui'; import usePreferences from '../store'; +import { getBrowser } from '../../../../static/js/utils'; const StyledBox = styled(Box)(({theme}) => ({ @@ -110,6 +111,16 @@ class PreferencesSchema extends BaseUISchema { } } +async function reloadPgAdmin() { + let {name: browser} = getBrowser(); + if(browser == 'Electron') { + await window.electronUI.log('test'); + await window.electronUI.reloadApp(); + } else { + location.reload(); + } +} + function RightPanel({ schema, refreshKey, ...props }) { const schemaViewRef = React.useRef(null); @@ -583,7 +594,7 @@ export default function PreferencesComponent({ ...props }) { gettext('A page refresh is required to apply the theme. Do you wish to refresh the page now?'), function () { /* If user clicks Yes */ - location.reload(); + reloadPgAdmin(); return true; }, function () { props.closeModal();}, @@ -630,7 +641,7 @@ export default function PreferencesComponent({ ...props }) { onclick: () => { resetPrefsToDefault(false); closeModal(); - } + } } ]; } @@ -643,7 +654,7 @@ export default function PreferencesComponent({ ...props }) { method: 'DELETE' }).then(()=>{ if (refresh){ - location.reload(); + reloadPgAdmin(); return true; } preferencesStore.cache(); diff --git a/web/pgadmin/static/js/custom_hooks.js b/web/pgadmin/static/js/custom_hooks.js index ac80abb11..23060ebe7 100644 --- a/web/pgadmin/static/js/custom_hooks.js +++ b/web/pgadmin/static/js/custom_hooks.js @@ -236,7 +236,11 @@ export function useBeforeUnload({ enabled, isNewTab, beforeClose, closePanel }) useEffect(()=>{ if(getBrowser().name == 'Electron' && isNewTab) { - window.addEventListener('beforeunload', onBeforeUnloadElectron); + if(enabled) { + window.addEventListener('beforeunload', onBeforeUnloadElectron); + } else { + window.removeEventListener('beforeunload', onBeforeUnloadElectron); + } } else if(getBrowser().name != 'Electron') { if(enabled){ window.addEventListener('beforeunload', onBeforeUnload);