|
6 | 6 | // This software is released under the PostgreSQL Licence
|
7 | 7 | //
|
8 | 8 | //////////////////////////////////////////////////////////////
|
9 |
| -import { app, BrowserWindow, dialog, ipcMain, Menu, shell } from 'electron'; |
| 9 | +import { app, BrowserWindow, dialog, ipcMain, Menu, shell, screen } from 'electron'; |
10 | 10 | import axios from 'axios';
|
11 | 11 | import Store from 'electron-store';
|
12 | 12 | import fs from 'fs';
|
@@ -79,6 +79,23 @@ contextMenu({
|
79 | 79 |
|
80 | 80 | Menu.setApplicationMenu(null);
|
81 | 81 |
|
| 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 | + |
82 | 99 | function openConfigure() {
|
83 | 100 | if (configureWindow === null){
|
84 | 101 | configureWindow = new BrowserWindow({
|
@@ -332,7 +349,12 @@ function launchPgAdminWindow() {
|
332 | 349 | });
|
333 | 350 |
|
334 | 351 | 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 | + |
336 | 358 | pgAdminMainScreen.show();
|
337 | 359 |
|
338 | 360 | pgAdminMainScreen.webContents.setWindowOpenHandler(({url})=>{
|
|
0 commit comments