Skip to content

Commit

Permalink
prevent app window from opening offscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
PalmerAL committed Feb 16, 2020
1 parent 5826215 commit c60ef3b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const webContents = electron.webContents
const session = electron.session
const ipc = electron.ipcMain

function clamp(n, min, max) {
return Math.max(Math.min(n, max), min);
}

if (process.platform === 'win32') {
(async function () {
var squirrelCommand = process.argv[1];
Expand Down Expand Up @@ -108,14 +112,26 @@ function createWindow (cb) {
}
if (e || !data || !bounds) { // there was an error, probably because the file doesn't exist
var size = electron.screen.getPrimaryDisplay().workAreaSize
var bounds = {
bounds = {
x: 0,
y: 0,
width: size.width,
height: size.height
}
}

//make the bounds fit inside a currently-active screen
//(since the screen Min was previously open on could have been removed)
//see: https://github.com/minbrowser/min/issues/904
var containingRect = electron.screen.getDisplayMatching(bounds).workArea;

bounds = {
x: clamp(bounds.x, containingRect.x, (containingRect.x + containingRect.width) - bounds.width),
y: clamp(bounds.y, containingRect.y, (containingRect.y + containingRect.height) - bounds.height),
width: clamp(bounds.width, 0, containingRect.width),
height: clamp(bounds.height, 0, containingRect.height),
}

// maximizes the window frame in windows 10
// fixes https://github.com/minbrowser/min/issues/214
// should be removed once https://github.com/electron/electron/issues/4045 is fixed
Expand Down

0 comments on commit c60ef3b

Please sign in to comment.