Skip to content

Commit

Permalink
Fixes wrong window placement when on Linux and more displays
Browse files Browse the repository at this point in the history
fixes #33
  • Loading branch information
hovancik committed Nov 23, 2016
1 parent 3dd640f commit cd90d15
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- strict mode - breaks/microbreaks can't be finished early

### Fixed
- wrong window placement when on Linux and more displays

## [0.4.0] - 2016-11-05
### Fixed
Expand Down
22 changes: 22 additions & 0 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ if (shouldQuit) {
app.quit()
}

function displaysX (width = 800) {
const electron = require('electron')
let bounds = electron.screen.getPrimaryDisplay().bounds
return bounds.x + ((bounds.width - width) / 2)
}

function displaysY (height = 600) {
const electron = require('electron')
let bounds = electron.screen.getPrimaryDisplay().bounds
return bounds.y + ((bounds.height - height) / 2)
}

function createTrayIcon () {
if (process.platform === 'darwin') {
app.dock.hide()
Expand Down Expand Up @@ -79,6 +91,8 @@ function checkVersion () {
function showStartUpWindow () {
const modalPath = path.join('file://', __dirname, 'start.html')
let appStartupWin = new BrowserWindow({
x: displaysX(600),
y: displaysY(170),
frame: false,
alwaysOnTop: true,
title: 'stretchly',
Expand All @@ -102,6 +116,8 @@ function startMicrobreak () {

const modalPath = path.join('file://', __dirname, 'microbreak.html')
microbreakWin = new BrowserWindow({
x: displaysX(),
y: displaysY(),
frame: false,
alwaysOnTop: true,
backgroundColor: settings.get('mainColor'),
Expand All @@ -123,6 +139,8 @@ function startBreak () {
}
const modalPath = path.join('file://', __dirname, 'break.html')
breakWin = new BrowserWindow({
x: displaysX(),
y: displaysY(),
frame: false,
alwaysOnTop: true,
backgroundColor: settings.get('mainColor'),
Expand Down Expand Up @@ -199,6 +217,8 @@ function resumeBreaks () {
function showAboutWindow () {
const modalPath = path.join('file://', __dirname, 'about.html')
aboutWin = new BrowserWindow({
x: displaysX(),
y: displaysY(),
alwaysOnTop: true,
backgroundColor: settings.get('mainColor'),
title: `About stretchly v${app.getVersion()}`
Expand All @@ -209,6 +229,8 @@ function showAboutWindow () {
function showSettingsWindow () {
const modalPath = path.join('file://', __dirname, 'settings.html')
settingsWin = new BrowserWindow({
x: displaysX(),
y: displaysY(),
alwaysOnTop: true,
backgroundColor: settings.get('mainColor'),
title: 'Settings'
Expand Down

0 comments on commit cd90d15

Please sign in to comment.