Skip to content

Commit 01174c2

Browse files
committed
Attempt to fix the problem of positioning the window
1 parent 498ef15 commit 01174c2

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

main.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ var iconIdle = path.join(__dirname, 'images', 'tray-idleTemplate.png');
1818
var iconActive = path.join(__dirname, 'images', 'tray-active.png');
1919

2020
// Utilities
21+
var isDarwin = (process.platform === 'darwin');
22+
var isLinux = (process.platform === 'linux');
2123
var isWindows = (process.platform === 'win32');
2224

2325
var autoStart = new AutoLaunch({
@@ -28,7 +30,7 @@ var autoStart = new AutoLaunch({
2830
app.on('ready', function() {
2931
var cachedBounds;
3032
var appIcon = new Tray(iconIdle);
31-
var windowPosition = (process.platform === 'win32') ? 'trayBottomCenter' : 'trayCenter';
33+
var windowPosition = (isWindows) ? 'trayBottomCenter' : 'trayCenter';
3234

3335
initWindow();
3436

@@ -63,19 +65,30 @@ app.on('ready', function() {
6365
}
6466

6567
function showWindow (trayPos) {
66-
var screen = electron.screen;
67-
var cursorPointer = screen.getCursorScreenPoint();
68-
var displaySize = screen.getPrimaryDisplay().workAreaSize;
69-
var x = (cursorPointer.x < (displaySize.width / 2)) ? 'left' : 'right';
70-
var y = (cursorPointer.y < (displaySize.height / 2)) ? 'top' : 'bottom';
71-
7268
var noBoundsPosition;
73-
if (x === 'right' && y === 'bottom') {
74-
noBoundsPosition = (isWindows) ? 'trayBottomCenter' : 'bottomRight';
75-
} else if (x === 'left' && y === 'bottom') {
76-
noBoundsPosition = 'bottomLeft';
77-
} else if (y === 'top') {
78-
noBoundsPosition = (isWindows) ? 'trayCenter' : '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 {
91+
noBoundsPosition = (isWindows) ? 'bottomRight' : 'topRight';
7992
}
8093

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

0 commit comments

Comments
 (0)