Skip to content

Commit

Permalink
Merge pull request #144 from AlphaStyle/multiple-displays
Browse files Browse the repository at this point in the history
Center tourWindow & dialog on primary display
  • Loading branch information
hql287 authored Jan 18, 2018
2 parents 4dd14e9 + ad2c3eb commit 282e615
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
24 changes: 20 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const omit = require('lodash').omit;
// Electron Libs
const { app, BrowserWindow, ipcMain } = require('electron');

// Place a BrowserWindow in center of primary display
const centerOnPrimaryDisplay = require('./app/helpers/center-on-primary-display');

// Prevent Linux GPU Bug
// https://github.com/electron/electron/issues/4322
if (process.platform == 'linux') {
Expand All @@ -27,10 +30,18 @@ let mainWindow = null;
let previewWindow = null;

function createTourWindow() {
const width = 700;
const height = 600;

// Get X and Y coordinations on primary display
const winPOS = centerOnPrimaryDisplay(width, height);

// Creating a New Window
tourWindow = new BrowserWindow({
width: 700,
height: 600,
x: winPOS.x,
y: winPOS.y,
width,
height,
show: false,
frame: false,
resizable: false,
Expand Down Expand Up @@ -248,8 +259,13 @@ function migrateData() {
},
});
// Omit old keys
return omit(migratedConfigs, ['info', 'appSettings', 'printOptions', 'test']);
}
return omit(migratedConfigs, [
'info',
'appSettings',
'printOptions',
'test',
]);
},
};
// Get the current Config
const configs = appConfig.getAll();
Expand Down
18 changes: 18 additions & 0 deletions app/helpers/center-on-primary-display.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const electron = require('electron');

const centerOnPrimaryDisplay = (winWidth, winHeight) => {
// Get primary display (screen / monitor) bounds
const primaryDisplay = electron.screen.getPrimaryDisplay();
const { x, y, width, height } = primaryDisplay.bounds;

// Calculate X and Y coordinates to make rectangular center on primary display
const winX = x + (width - winWidth) / 2;
const winY = y + (height - winHeight) / 2;

return {
x: winX,
y: winY,
};
};

module.exports = centerOnPrimaryDisplay;
14 changes: 12 additions & 2 deletions app/renderers/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@ const { BrowserWindow } = require('electron').remote;
// Custom Libs
const sounds = require('../../libs/sounds.js');

const centerOnPrimaryDisplay = require('../helpers/center-on-primary-display');

function showModalWindow(dialogOptions, returnChannel = '', ...rest) {
const width = 450;
const height = 220;

// Get X and Y coordinations on primary display
const winPOS = centerOnPrimaryDisplay(width, height);

let modalWin = new BrowserWindow({
width: 450,
height: 220,
x: winPOS.x,
y: winPOS.y,
width,
height,
backgroundColor: '#282828',
frame: false,
show: false,
Expand Down

0 comments on commit 282e615

Please sign in to comment.