Skip to content

Commit

Permalink
Fix issues found in electron testing. #7494
Browse files Browse the repository at this point in the history
  • Loading branch information
adityatoshniwal committed Jul 16, 2024
1 parent 64d7c2c commit 8e16e00
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
15 changes: 14 additions & 1 deletion runtime/src/js/pgadmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,22 @@ let docsURLSubStrings = ['www.enterprisedb.com', 'www.postgresql.org', 'www.pgad
process.env['ELECTRON_ENABLE_SECURITY_WARNINGS'] = false;

// Paths to the rest of the app

let [pythonPath, pgadminFile] = misc.getAppPaths(__dirname);

// Do not allow a second instance of pgAdmin to run.
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
app.on('second-instance', () => {
// Someone tried to run a second instance, we should focus our window.
if (pgAdminMainScreen) {
if (pgAdminMainScreen.isMinimized()) pgAdminMainScreen.restore();
pgAdminMainScreen.focus();
}
});
}

// Override the paths above, if a developer needs to
if (fs.existsSync('dev_config.json')) {
try {
Expand Down
2 changes: 1 addition & 1 deletion web/pgadmin/static/js/custom_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export function useForceUpdate() {
return React.useReducer(() => ({}), {})[1];
}

export function useBeforeUnload({enabled, isNewTab, beforeClose, closePanel }) {
export function useBeforeUnload({ enabled, isNewTab, beforeClose, closePanel }) {
const onBeforeUnload = useCallback((e)=>{
e.preventDefault();
e.returnValue = 'prevent';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import React from 'react';
import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import { useBeforeUnload } from '../../../../../../static/js/custom_hooks';

export default function BeforeUnload({enabled, isNewTab, beforeClose, closePanel}) {
useBeforeUnload(
export default function BeforeUnload({onInit, enabled, isNewTab, beforeClose, closePanel}) {
const init = useBeforeUnload(
{enabled, isNewTab, beforeClose, closePanel}
);

useEffect(()=>{
onInit?.(init);
}, [init]);

return <></>;
}

BeforeUnload.propTypes = {
onInit: PropTypes.func,
enabled: PropTypes.bool,
isNewTab: PropTypes.bool,
beforeClose: PropTypes.func,
closePanel: PropTypes.func,
getForceClose: PropTypes.func,
closePanel: PropTypes.func
};
11 changes: 5 additions & 6 deletions web/pgadmin/tools/erd/static/js/erd_tool/components/ERDTool.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export default class ERDTool extends React.Component {
}
}

confirmBeforeClose(forceClose) {
confirmBeforeClose() {
let bodyObj = this;
if(this.state.dirty) {
this.closeOnSave = false;
Expand All @@ -366,7 +366,7 @@ export default class ERDTool extends React.Component {
closeModal={closeModal}
text={gettext('The diagram has changed. Do you want to save changes?')}
onDontSave={()=>{
forceClose();
this.forceClose();
}}
onSave={()=>{
bodyObj.onSaveDiagram(false, true);
Expand All @@ -375,7 +375,7 @@ export default class ERDTool extends React.Component {
));
return false;
} else {
forceClose();
this.forceClose();
}
}

Expand Down Expand Up @@ -886,11 +886,10 @@ export default class ERDTool extends React.Component {
return (
<StyledBox ref={this.containerRef} height="100%" display="flex" flexDirection="column">
<BeforeUnload
onInit={({forceClose})=>{this.forceClose = forceClose;}}
enabled={this.state.is_close_tab_warning}
isNewTab={this.state.is_new_tab}
beforeClose={(forceClose)=>{
this.confirmBeforeClose(forceClose);
}}
beforeClose={this.confirmBeforeClose}
closePanel={this.closePanel}
/>
<ConnectionBar status={this.state.conn_status} bgcolor={this.props.params.bgcolor}
Expand Down

0 comments on commit 8e16e00

Please sign in to comment.