Skip to content

Commit

Permalink
remove unnecessary if/else statement
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaStyle committed Jan 15, 2018
1 parent 430e812 commit 2c71827
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions app/helpers/center-on-primary-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,14 @@ const centerOnPrimaryDisplay = (width, height) => {
// Get Primary Display (screen / monitor)
const primaryDisplay = electron.screen.getPrimaryDisplay();

let x, y;

// TODO: how to do error handling in electron?
if (!width || !height) {
throw new Error('missing width and / or height!');
}

// If monitor 1 is primary display
if (primaryDisplay.bounds.x === 0 && primaryDisplay.bounds.y === 0) {
x = primaryDisplay.bounds.width / 2 - width / 2;
y = primaryDisplay.bounds.height / 2 - height / 2;
} else {
// if monitor 2 and higher is primary display
x = primaryDisplay.bounds.width / 2 - width / 2 + primaryDisplay.bounds.x;
y = primaryDisplay.bounds.height / 2 - height / 2 + primaryDisplay.bounds.y;
}
// X and Y coordinates to make rectangular center of primary display
const x = primaryDisplay.bounds.width / 2 - width / 2 + primaryDisplay.bounds.x;
const y = primaryDisplay.bounds.height / 2 - height / 2 + primaryDisplay.bounds.y;

return { x, y };
};
Expand Down

0 comments on commit 2c71827

Please sign in to comment.