Skip to content

Commit 8474ee3

Browse files
Merge pull request #137 from mrmlnc/cross-positioning
Cross Positioning
2 parents 4ca64d1 + 45e9a1f commit 8474ee3

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

main.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ var dialog = require('dialog');
1717
var iconIdle = path.join(__dirname, 'images', 'tray-idleTemplate.png');
1818
var iconActive = path.join(__dirname, 'images', 'tray-active.png');
1919

20+
// Utilities
21+
var isDarwin = (process.platform === 'darwin');
22+
var isLinux = (process.platform === 'linux');
23+
var isWindows = (process.platform === 'win32');
24+
2025
var autoStart = new AutoLaunch({
2126
name: 'Gitify',
2227
path: process.execPath.match(/.*?\.app/)[0]
@@ -25,7 +30,7 @@ var autoStart = new AutoLaunch({
2530
app.on('ready', function() {
2631
var cachedBounds;
2732
var appIcon = new Tray(iconIdle);
28-
var windowPosition = (process.platform === 'win32') ? 'trayBottomCenter' : 'trayCenter';
33+
var windowPosition = (isWindows) ? 'trayBottomCenter' : 'trayCenter';
2934

3035
initWindow();
3136

@@ -60,11 +65,30 @@ app.on('ready', function() {
6065
}
6166

6267
function showWindow (trayPos) {
63-
// Thanks to https://github.com/maxogden/menubar/
64-
// Default the window to the right if `trayPos` bounds are undefined or null.
6568
var noBoundsPosition;
66-
if (trayPos === undefined || trayPos.x === 0) {
67-
noBoundsPosition = (process.platform === 'win32') ? 'bottomRight' : 'topRight';
69+
if (!isDarwin && trayPos !== undefined) {
70+
var displaySize = electron.screen.getPrimaryDisplay().workAreaSize;
71+
var trayPosX = trayPos.x;
72+
var trayPosY = trayPos.y;
73+
74+
if (isLinux) {
75+
var cursorPointer = electron.screen.getCursorScreenPoint();
76+
trayPosX = cursorPointer.x;
77+
trayPosY = cursorPointer.y;
78+
}
79+
80+
var x = (trayPosX < (displaySize.width / 2)) ? 'left' : 'right';
81+
var y = (trayPosY < (displaySize.height / 2)) ? 'top' : 'bottom';
82+
83+
if (x === 'right' && y === 'bottom') {
84+
noBoundsPosition = (isWindows) ? 'trayBottomCenter' : 'bottomRight';
85+
} else if (x === 'left' && y === 'bottom') {
86+
noBoundsPosition = 'bottomLeft';
87+
} else if (y === 'top') {
88+
noBoundsPosition = (isWindows) ? 'trayCenter' : 'topRight';
89+
}
90+
} else if (trayPos === undefined) {
91+
noBoundsPosition = (isWindows) ? 'bottomRight' : 'topRight';
6892
}
6993

7094
var position = appIcon.positioner.calculate(noBoundsPosition || windowPosition, trayPos);

0 commit comments

Comments
 (0)