Fixed an issue where "Quit App" confirmation modal in desktop app is not respecting "Confirm on close or refresh?". #7890

This commit is contained in:
Aditya Toshniwal 2024-09-18 16:43:57 +05:30
parent 23ea201325
commit 100f59f78b
6 changed files with 37 additions and 7 deletions

View File

@ -31,10 +31,11 @@ Housekeeping
Bug fixes
*********
| `Issue #6502 <https://github.com/pgadmin-org/pgadmin4/issues/6502>`_ - Fix the query tool restore connection issue on the server disconnection from the left side object explorer.
| `Issue #6502 <https://github.com/pgadmin-org/pgadmin4/issues/6502>`_ - Fix the query tool restore connection issue on the server disconnection from the left side object explorer.
| `Issue #7076 <https://github.com/pgadmin-org/pgadmin4/issues/7076>`_ - Revamp the current password saving implementation to a keyring and reduce repeated OS user password prompts.
| `Issue #7571 <https://github.com/pgadmin-org/pgadmin4/issues/7571>`_ - Fixed an issue where users could not use pgAdmin if they did not have access to the management database.
| `Issue #7811 <https://github.com/pgadmin-org/pgadmin4/issues/7811>`_ - Fixed an issue where servers listed in the servers.json file were being reimported upon container restart.
| `Issue #7839 <https://github.com/pgadmin-org/pgadmin4/issues/7839>`_ - Added support for OIDC based OAuth2 authentication.
| `Issue #7878 <https://github.com/pgadmin-org/pgadmin4/issues/7878>`_ - Fixed an issue where cursor moves to end of line when editing input fields.
| `Issue #7890 <https://github.com/pgadmin-org/pgadmin4/issues/7890>`_ - Fixed an issue where "Quit App" confirmation modal in desktop app is not respecting "Confirm on close or refresh?".
| `Issue #7895 <https://github.com/pgadmin-org/pgadmin4/issues/7895>`_ - Fixed an issue where different client backend shows all SQL are same.

View File

@ -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' },

View File

@ -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);

View File

@ -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');},
});

View File

@ -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();

View File

@ -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);