@@ -17,6 +17,11 @@ var dialog = require('dialog');
17
17
var iconIdle = path . join ( __dirname , 'images' , 'tray-idleTemplate.png' ) ;
18
18
var iconActive = path . join ( __dirname , 'images' , 'tray-active.png' ) ;
19
19
20
+ // Utilities
21
+ var isDarwin = ( process . platform === 'darwin' ) ;
22
+ var isLinux = ( process . platform === 'linux' ) ;
23
+ var isWindows = ( process . platform === 'win32' ) ;
24
+
20
25
var autoStart = new AutoLaunch ( {
21
26
name : 'Gitify' ,
22
27
path : process . execPath . match ( / .* ?\. a p p / ) [ 0 ]
@@ -25,7 +30,7 @@ var autoStart = new AutoLaunch({
25
30
app . on ( 'ready' , function ( ) {
26
31
var cachedBounds ;
27
32
var appIcon = new Tray ( iconIdle ) ;
28
- var windowPosition = ( process . platform === 'win32' ) ? 'trayBottomCenter' : 'trayCenter' ;
33
+ var windowPosition = ( isWindows ) ? 'trayBottomCenter' : 'trayCenter' ;
29
34
30
35
initWindow ( ) ;
31
36
@@ -60,11 +65,30 @@ app.on('ready', function() {
60
65
}
61
66
62
67
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.
65
68
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' ;
68
92
}
69
93
70
94
var position = appIcon . positioner . calculate ( noBoundsPosition || windowPosition , trayPos ) ;
0 commit comments