From 57d757d4dea5046a0909971c4337ad10550a00ca Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Wed, 26 Mar 2025 09:21:53 +0530 Subject: [PATCH] Fixed an issue where pgAdmin should fallback to main screen if the last opened screen is disconnected. #8362 --- runtime/src/js/pgadmin.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/runtime/src/js/pgadmin.js b/runtime/src/js/pgadmin.js index 5355ea62c..04014420e 100644 --- a/runtime/src/js/pgadmin.js +++ b/runtime/src/js/pgadmin.js @@ -6,7 +6,7 @@ // This software is released under the PostgreSQL Licence // ////////////////////////////////////////////////////////////// -import { app, BrowserWindow, dialog, ipcMain, Menu, shell } from 'electron'; +import { app, BrowserWindow, dialog, ipcMain, Menu, shell, screen } from 'electron'; import axios from 'axios'; import Store from 'electron-store'; import fs from 'fs'; @@ -79,6 +79,23 @@ contextMenu({ Menu.setApplicationMenu(null); +// Check if the given position is within the display bounds. +// pgAdmin tried to open the window on the display where the it +// was last closed. +function isWithinDisplayBounds(pos) { + const displays = screen.getAllDisplays() + return displays.reduce((result, display) => { + const area = display.workArea + return ( + result || + (pos.x >= area.x && + pos.y >= area.y && + pos.x < area.x + area.width && + pos.y < area.y + area.height) + ) + }, false) +} + function openConfigure() { if (configureWindow === null){ configureWindow = new BrowserWindow({ @@ -332,7 +349,12 @@ function launchPgAdminWindow() { }); pgAdminMainScreen.loadURL(startPageUrl); - pgAdminMainScreen.setBounds(configStore.get('bounds')); + + const bounds = configStore.get('bounds'); + + (bounds && isWithinDisplayBounds({x: bounds.x, y: bounds.y})) ? pgAdminMainScreen.setBounds(bounds) : + pgAdminMainScreen.setBounds({x: 0, y: 0, width: 1024, height: 768}); + pgAdminMainScreen.show(); pgAdminMainScreen.webContents.setWindowOpenHandler(({url})=>{