enforce min width and height for windows (#88)

This commit is contained in:
Lynn 2017-05-11 11:11:42 -07:00 committed by GitHub
parent c2d8d8ea70
commit 515ee36fe1
2 changed files with 12 additions and 5 deletions

View File

@ -144,7 +144,7 @@
var openWinButton = document.getElementById('open-win'); var openWinButton = document.getElementById('open-win');
openWinButton.addEventListener('click', function() { openWinButton.addEventListener('click', function() {
win = window.open('win.html?x=100&y=100', 'test-window', 'height=100,width=100'); win = window.open('win.html?x=100&y=100', 'test-window', 'height=800,width=400');
}); });
var front = document.getElementById('bring-to-front'); var front = document.getElementById('bring-to-front');

View File

@ -37,6 +37,9 @@ let boundsChangeWindow;
// note: this file is built using browserify in prebuild step. // note: this file is built using browserify in prebuild step.
const preloadMainScript = path.join(__dirname, 'preload/_preloadMain.js'); const preloadMainScript = path.join(__dirname, 'preload/_preloadMain.js');
const MIN_WIDTH = 300;
const MIN_HEIGHT = 600;
function addWindowKey(key, browserWin) { function addWindowKey(key, browserWin) {
windows[key] = browserWin; windows[key] = browserWin;
} }
@ -69,6 +72,8 @@ function doCreateMainWindow(initialUrl, initialBounds) {
let newWinOpts = { let newWinOpts = {
title: 'Symphony', title: 'Symphony',
show: true, show: true,
minWidth: MIN_WIDTH,
minHeight: MIN_HEIGHT,
webPreferences: { webPreferences: {
sandbox: true, sandbox: true,
nodeIntegration: false, nodeIntegration: false,
@ -198,8 +203,8 @@ function doCreateMainWindow(initialUrl, initialBounds) {
let x = 0; let x = 0;
let y = 0; let y = 0;
let width = newWinOptions.width || 300; let width = newWinOptions.width || MIN_WIDTH;
let height = newWinOptions.height || 600; let height = newWinOptions.height || MIN_HEIGHT;
// try getting x and y position from query parameters // try getting x and y position from query parameters
var query = newWinParsedUrl && querystring.parse(newWinParsedUrl.query); var query = newWinParsedUrl && querystring.parse(newWinParsedUrl.query);
@ -228,8 +233,10 @@ function doCreateMainWindow(initialUrl, initialBounds) {
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
newWinOptions.x = x; newWinOptions.x = x;
newWinOptions.y = y; newWinOptions.y = y;
newWinOptions.width = width; newWinOptions.width = Math.max(width, MIN_WIDTH);
newWinOptions.height = height; newWinOptions.height = Math.max(height, MIN_HEIGHT);
newWinOptions.minWidth = MIN_WIDTH;
newWinOptions.minHeight = MIN_HEIGHT;
let newWinKey = getGuid(); let newWinKey = getGuid();