Helps to position a electron window as a custom tray menu window.
On Windows and OSX the tray bar location is calculated and the window is
positioned based on the tray bar location.
On linux the position is calculated based on the current cursor position, because Tray.getBounds()
always returns a Rectangle
with all values set to zero.
npm install --save electron-traywindow-positioner
const positioner = require('electron-traywindow-positioner');
positioner.position(trayWindow, trayBounds);
trayWindow
must be an instance of aBrowserWindow
.trayBounds
must be an instance ofRectangle
returned fromtray.getBounds()
const positioner = require('electron-traywindow-positioner');
positioner.calculate(windowBounds, trayBounds);
windowBounds
must be an instance ofRectangle
returned fromBrowserWindow.getBounds()
.trayBounds
must be an instance ofRectangle
returned fromtray.getBounds()
const alignment = {x: 'left', y: 'up'};
const positioner = require('electron-traywindow-positioner');
positioner.position(trayWindow, trayBounds, alignment);
// or
positioner.calculate(windowBounds, trayBounds, alignment);
-
alignmet.x
alignment on x axis relative to tray icon when tray bar is top or bottom. The value can be one ofleft
,center
orright
, default iscenter
. -
alignmet.y
alignment on y axis relative to tray icon when tray bar is left or right. The value can be one ofup
,center
ordown
, default isdown
.