mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fix issues found in electron testing. #7494
This commit is contained in:
parent
64d7c2c62d
commit
8e16e000c3
@ -38,9 +38,22 @@ let docsURLSubStrings = ['www.enterprisedb.com', 'www.postgresql.org', 'www.pgad
|
|||||||
process.env['ELECTRON_ENABLE_SECURITY_WARNINGS'] = false;
|
process.env['ELECTRON_ENABLE_SECURITY_WARNINGS'] = false;
|
||||||
|
|
||||||
// Paths to the rest of the app
|
// Paths to the rest of the app
|
||||||
|
|
||||||
let [pythonPath, pgadminFile] = misc.getAppPaths(__dirname);
|
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
|
// Override the paths above, if a developer needs to
|
||||||
if (fs.existsSync('dev_config.json')) {
|
if (fs.existsSync('dev_config.json')) {
|
||||||
try {
|
try {
|
||||||
|
@ -211,7 +211,7 @@ export function useForceUpdate() {
|
|||||||
return React.useReducer(() => ({}), {})[1];
|
return React.useReducer(() => ({}), {})[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useBeforeUnload({enabled, isNewTab, beforeClose, closePanel }) {
|
export function useBeforeUnload({ enabled, isNewTab, beforeClose, closePanel }) {
|
||||||
const onBeforeUnload = useCallback((e)=>{
|
const onBeforeUnload = useCallback((e)=>{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.returnValue = 'prevent';
|
e.returnValue = 'prevent';
|
||||||
|
@ -1,19 +1,23 @@
|
|||||||
import React from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { useBeforeUnload } from '../../../../../../static/js/custom_hooks';
|
import { useBeforeUnload } from '../../../../../../static/js/custom_hooks';
|
||||||
|
|
||||||
export default function BeforeUnload({enabled, isNewTab, beforeClose, closePanel}) {
|
export default function BeforeUnload({onInit, enabled, isNewTab, beforeClose, closePanel}) {
|
||||||
useBeforeUnload(
|
const init = useBeforeUnload(
|
||||||
{enabled, isNewTab, beforeClose, closePanel}
|
{enabled, isNewTab, beforeClose, closePanel}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
onInit?.(init);
|
||||||
|
}, [init]);
|
||||||
|
|
||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
|
|
||||||
BeforeUnload.propTypes = {
|
BeforeUnload.propTypes = {
|
||||||
|
onInit: PropTypes.func,
|
||||||
enabled: PropTypes.bool,
|
enabled: PropTypes.bool,
|
||||||
isNewTab: PropTypes.bool,
|
isNewTab: PropTypes.bool,
|
||||||
beforeClose: PropTypes.func,
|
beforeClose: PropTypes.func,
|
||||||
closePanel: PropTypes.func,
|
closePanel: PropTypes.func
|
||||||
getForceClose: PropTypes.func,
|
|
||||||
};
|
};
|
||||||
|
@ -357,7 +357,7 @@ export default class ERDTool extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
confirmBeforeClose(forceClose) {
|
confirmBeforeClose() {
|
||||||
let bodyObj = this;
|
let bodyObj = this;
|
||||||
if(this.state.dirty) {
|
if(this.state.dirty) {
|
||||||
this.closeOnSave = false;
|
this.closeOnSave = false;
|
||||||
@ -366,7 +366,7 @@ export default class ERDTool extends React.Component {
|
|||||||
closeModal={closeModal}
|
closeModal={closeModal}
|
||||||
text={gettext('The diagram has changed. Do you want to save changes?')}
|
text={gettext('The diagram has changed. Do you want to save changes?')}
|
||||||
onDontSave={()=>{
|
onDontSave={()=>{
|
||||||
forceClose();
|
this.forceClose();
|
||||||
}}
|
}}
|
||||||
onSave={()=>{
|
onSave={()=>{
|
||||||
bodyObj.onSaveDiagram(false, true);
|
bodyObj.onSaveDiagram(false, true);
|
||||||
@ -375,7 +375,7 @@ export default class ERDTool extends React.Component {
|
|||||||
));
|
));
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
forceClose();
|
this.forceClose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -886,11 +886,10 @@ export default class ERDTool extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<StyledBox ref={this.containerRef} height="100%" display="flex" flexDirection="column">
|
<StyledBox ref={this.containerRef} height="100%" display="flex" flexDirection="column">
|
||||||
<BeforeUnload
|
<BeforeUnload
|
||||||
|
onInit={({forceClose})=>{this.forceClose = forceClose;}}
|
||||||
enabled={this.state.is_close_tab_warning}
|
enabled={this.state.is_close_tab_warning}
|
||||||
isNewTab={this.state.is_new_tab}
|
isNewTab={this.state.is_new_tab}
|
||||||
beforeClose={(forceClose)=>{
|
beforeClose={this.confirmBeforeClose}
|
||||||
this.confirmBeforeClose(forceClose);
|
|
||||||
}}
|
|
||||||
closePanel={this.closePanel}
|
closePanel={this.closePanel}
|
||||||
/>
|
/>
|
||||||
<ConnectionBar status={this.state.conn_status} bgcolor={this.props.params.bgcolor}
|
<ConnectionBar status={this.state.conn_status} bgcolor={this.props.params.bgcolor}
|
||||||
|
Loading…
Reference in New Issue
Block a user