From f93a79886ab1408fa49281363e10d1d802148b21 Mon Sep 17 00:00:00 2001 From: Denis Malinochkin Date: Thu, 10 Dec 2015 02:40:56 +0300 Subject: [PATCH 1/5] fix positioning for Windows and Linux --- main.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index 62576b1b2..331b9a80e 100644 --- a/main.js +++ b/main.js @@ -60,11 +60,19 @@ app.on('ready', function() { } function showWindow (trayPos) { - // Thanks to https://github.com/maxogden/menubar/ - // Default the window to the right if `trayPos` bounds are undefined or null. + var screen = require('screen'); + var cursorPointer = screen.getCursorScreenPoint(); + var displaySize = screen.getPrimaryDisplay().workAreaSize; + var x = (cursorPointer.x < (displaySize.width / 2)) ? 'left' : 'right'; + var y = (cursorPointer.y < (displaySize.height / 2)) ? 'top': 'bottom'; + var noBoundsPosition; - if (trayPos === undefined || trayPos.x === 0) { - noBoundsPosition = (process.platform === 'win32') ? 'bottomRight' : 'topRight'; + if (x === 'right' && y === 'bottom') { + noBoundsPosition = (isWindows) ? 'trayBottomCenter' : 'bottomRight'; + } else if (x === 'left' && y === 'bottom') { + noBoundsPosition = 'bottomLeft'; + } else if (y === 'top') { + noBoundsPosition = (isWindows) ? 'trayCenter' : 'topRight'; } var position = appIcon.positioner.calculate(noBoundsPosition || windowPosition, trayPos); From 4d6a2cc4d29f4043d323ca83dffe79b6fff72aa6 Mon Sep 17 00:00:00 2001 From: Denis Malinochkin Date: Thu, 10 Dec 2015 02:44:50 +0300 Subject: [PATCH 2/5] Electron API 0.35.x --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index 331b9a80e..faf959789 100644 --- a/main.js +++ b/main.js @@ -60,7 +60,7 @@ app.on('ready', function() { } function showWindow (trayPos) { - var screen = require('screen'); + var screen = electron.screen; var cursorPointer = screen.getCursorScreenPoint(); var displaySize = screen.getPrimaryDisplay().workAreaSize; var x = (cursorPointer.x < (displaySize.width / 2)) ? 'left' : 'right'; From 498ef1594d25bb115ac50e517d4f8e641f9bca48 Mon Sep 17 00:00:00 2001 From: Denis Malinochkin Date: Thu, 10 Dec 2015 12:30:02 +0300 Subject: [PATCH 3/5] Add missing utilities --- main.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index faf959789..b9191152f 100644 --- a/main.js +++ b/main.js @@ -17,6 +17,9 @@ var dialog = require('dialog'); var iconIdle = path.join(__dirname, 'images', 'tray-idleTemplate.png'); var iconActive = path.join(__dirname, 'images', 'tray-active.png'); +// Utilities +var isWindows = (process.platform === 'win32'); + var autoStart = new AutoLaunch({ name: 'Gitify', path: process.execPath.match(/.*?\.app/)[0] @@ -64,7 +67,7 @@ app.on('ready', function() { var cursorPointer = screen.getCursorScreenPoint(); var displaySize = screen.getPrimaryDisplay().workAreaSize; var x = (cursorPointer.x < (displaySize.width / 2)) ? 'left' : 'right'; - var y = (cursorPointer.y < (displaySize.height / 2)) ? 'top': 'bottom'; + var y = (cursorPointer.y < (displaySize.height / 2)) ? 'top' : 'bottom'; var noBoundsPosition; if (x === 'right' && y === 'bottom') { From 01174c22cc11101aecd48c537e4a23bae3e39e8c Mon Sep 17 00:00:00 2001 From: Denis Malinochkin Date: Thu, 10 Dec 2015 18:26:40 +0300 Subject: [PATCH 4/5] Attempt to fix the problem of positioning the window --- main.js | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/main.js b/main.js index b9191152f..817f10662 100644 --- a/main.js +++ b/main.js @@ -18,6 +18,8 @@ var iconIdle = path.join(__dirname, 'images', 'tray-idleTemplate.png'); var iconActive = path.join(__dirname, 'images', 'tray-active.png'); // Utilities +var isDarwin = (process.platform === 'darwin'); +var isLinux = (process.platform === 'linux'); var isWindows = (process.platform === 'win32'); var autoStart = new AutoLaunch({ @@ -28,7 +30,7 @@ var autoStart = new AutoLaunch({ app.on('ready', function() { var cachedBounds; var appIcon = new Tray(iconIdle); - var windowPosition = (process.platform === 'win32') ? 'trayBottomCenter' : 'trayCenter'; + var windowPosition = (isWindows) ? 'trayBottomCenter' : 'trayCenter'; initWindow(); @@ -63,19 +65,30 @@ app.on('ready', function() { } function showWindow (trayPos) { - var screen = electron.screen; - var cursorPointer = screen.getCursorScreenPoint(); - var displaySize = screen.getPrimaryDisplay().workAreaSize; - var x = (cursorPointer.x < (displaySize.width / 2)) ? 'left' : 'right'; - var y = (cursorPointer.y < (displaySize.height / 2)) ? 'top' : 'bottom'; - var noBoundsPosition; - if (x === 'right' && y === 'bottom') { - noBoundsPosition = (isWindows) ? 'trayBottomCenter' : 'bottomRight'; - } else if (x === 'left' && y === 'bottom') { - noBoundsPosition = 'bottomLeft'; - } else if (y === 'top') { - noBoundsPosition = (isWindows) ? 'trayCenter' : 'topRight'; + if (!isDarwin && trayPos !== undefined) { + var displaySize = electron.screen.getPrimaryDisplay().workAreaSize; + var trayPosX = trayPos.x; + var trayPosY = trayPos.y; + + if (isLinux) { + var cursorPointer = electron.screen.getCursorScreenPoint(); + trayPosX = cursorPointer.x; + trayPosY = cursorPointer.y; + } + + var x = (trayPosX < (displaySize.width / 2)) ? 'left' : 'right'; + var y = (trayPosY < (displaySize.height / 2)) ? 'top' : 'bottom'; + + if (x === 'right' && y === 'bottom') { + noBoundsPosition = (isWindows) ? 'trayBottomCenter' : 'bottomRight'; + } else if (x === 'left' && y === 'bottom') { + noBoundsPosition = 'bottomLeft'; + } else if (y === 'top') { + noBoundsPosition = (isWindows) ? 'trayCenter' : 'topRight'; + } + } else { + noBoundsPosition = (isWindows) ? 'bottomRight' : 'topRight'; } var position = appIcon.positioner.calculate(noBoundsPosition || windowPosition, trayPos); From 74bca3308b935c22a6565ff4f2ef85b13371d613 Mon Sep 17 00:00:00 2001 From: Denis Malinochkin Date: Fri, 11 Dec 2015 16:47:36 +0300 Subject: [PATCH 5/5] update condition for OS X and Linux --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index 817f10662..59cf35378 100644 --- a/main.js +++ b/main.js @@ -87,7 +87,7 @@ app.on('ready', function() { } else if (y === 'top') { noBoundsPosition = (isWindows) ? 'trayCenter' : 'topRight'; } - } else { + } else if (trayPos === undefined) { noBoundsPosition = (isWindows) ? 'bottomRight' : 'topRight'; }