Skip to content
Merged
Show file tree
Hide file tree
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
49 changes: 23 additions & 26 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const ipc = electron.ipcMain;

var path = require('path');
var ghReleases = require('electron-gh-releases');
var Positioner = require('electron-positioner');

require('crash-reporter').start();

Expand All @@ -22,21 +23,18 @@ var autoStart = new AutoLaunch({
});

app.on('ready', function() {
var cachedBounds;
var appIcon = new Tray(iconIdle);

var options = {
x: null,
y: null
};
var windowPosition = (process.platform === 'win32') ? 'trayBottomCenter' : 'trayCenter';

initWindow();

appIcon.on('click', function (e, bounds) {
if (appIcon.window && appIcon.window.isVisible()) {
return hideWindow();
} else {
showWindow(bounds);
}
if (e.altKey || e.shiftKey || e.ctrlKey || e.metaKey) return hideWindow();
if (appIcon.window && appIcon.window.isVisible()) return hideWindow();
bounds = bounds || cachedBounds;
cachedBounds = bounds;
showWindow(cachedBounds);
});

function initWindow () {
Expand All @@ -46,10 +44,13 @@ app.on('ready', function() {
show: false,
frame: false,
resizable: false,
'standard-window': false
webPreferences: {
overlayScrollbars: true
}
};

appIcon.window = new BrowserWindow(defaults);
appIcon.positioner = new Positioner(appIcon.window);
appIcon.window.loadURL('file://' + __dirname + '/index.html');
appIcon.window.on('blur', hideWindow);
appIcon.window.setVisibleOnAllWorkspaces(true);
Expand All @@ -58,20 +59,16 @@ app.on('ready', function() {
checkAutoUpdate(false);
}

function showWindow (bounds) {
if (options.x) {
appIcon.window.show();
} else {
if (bounds) {
options.x = bounds.x - 200 + (bounds.width / 2);
options.y = bounds.y;
appIcon.window.setPosition(options.x, options.y);
} else {
var electronScreen = require('screen');
var defaultSize = electronScreen.getPrimaryDisplay().workAreaSize;
appIcon.window.setPosition(defaultSize.width - 525, 15);
}
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';
}

var position = appIcon.positioner.calculate(noBoundsPosition || windowPosition, trayPos);
appIcon.window.setPosition(position.x, position.y);
appIcon.window.show();
}

Expand Down Expand Up @@ -102,7 +99,7 @@ app.on('ready', function() {
}

function hideWindow () {
if (!appIcon.window) { return; }
if (!appIcon.window) return;
appIcon.window.hide();
}

Expand Down Expand Up @@ -163,7 +160,7 @@ app.on('ready', function() {
}

ipc.on('reopen-window', function() {
showWindow();
showWindow(cachedBounds);
});

ipc.on('update-icon', function(event, arg) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"auto-launch": "=1.0.1",
"bootstrap": "=3.3.6",
"electron-gh-releases": "=2.0.2",
"electron-positioner": "=2.0.2",
"font-awesome": "=4.5.0",
"history": "=1.14.0",
"octicons": "=3.1.0",
Expand Down