Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Center tourWindow & dialog on primary display #144

Merged
merged 18 commits into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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