Skip to content

Commit 57d757d

Browse files
Fixed an issue where pgAdmin should fallback to main screen if the last opened screen is disconnected. #8362
1 parent 7edaac1 commit 57d757d

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

runtime/src/js/pgadmin.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// This software is released under the PostgreSQL Licence
77
//
88
//////////////////////////////////////////////////////////////
9-
import { app, BrowserWindow, dialog, ipcMain, Menu, shell } from 'electron';
9+
import { app, BrowserWindow, dialog, ipcMain, Menu, shell, screen } from 'electron';
1010
import axios from 'axios';
1111
import Store from 'electron-store';
1212
import fs from 'fs';
@@ -79,6 +79,23 @@ contextMenu({
7979

8080
Menu.setApplicationMenu(null);
8181

82+
// Check if the given position is within the display bounds.
83+
// pgAdmin tried to open the window on the display where the it
84+
// was last closed.
85+
function isWithinDisplayBounds(pos) {
86+
const displays = screen.getAllDisplays()
87+
return displays.reduce((result, display) => {
88+
const area = display.workArea
89+
return (
90+
result ||
91+
(pos.x >= area.x &&
92+
pos.y >= area.y &&
93+
pos.x < area.x + area.width &&
94+
pos.y < area.y + area.height)
95+
)
96+
}, false)
97+
}
98+
8299
function openConfigure() {
83100
if (configureWindow === null){
84101
configureWindow = new BrowserWindow({
@@ -332,7 +349,12 @@ function launchPgAdminWindow() {
332349
});
333350

334351
pgAdminMainScreen.loadURL(startPageUrl);
335-
pgAdminMainScreen.setBounds(configStore.get('bounds'));
352+
353+
const bounds = configStore.get('bounds');
354+
355+
(bounds && isWithinDisplayBounds({x: bounds.x, y: bounds.y})) ? pgAdminMainScreen.setBounds(bounds) :
356+
pgAdminMainScreen.setBounds({x: 0, y: 0, width: 1024, height: 768});
357+
336358
pgAdminMainScreen.show();
337359

338360
pgAdminMainScreen.webContents.setWindowOpenHandler(({url})=>{

0 commit comments

Comments
 (0)