Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ var dialog = require('dialog');
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({
name: 'Gitify',
path: process.execPath.match(/.*?\.app/)[0]
Expand All @@ -25,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();

Expand Down Expand Up @@ -60,11 +65,30 @@ 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 noBoundsPosition;
if (trayPos === undefined || trayPos.x === 0) {
noBoundsPosition = (process.platform === 'win32') ? 'bottomRight' : '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 if (trayPos === undefined) {
noBoundsPosition = (isWindows) ? 'bottomRight' : 'topRight';
}

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