1.2.1 • Published 1 year ago
electron-traywindow-positioner v1.2.1
electron-traywindow-positioner
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.
Installation
npm install --save electron-traywindow-positionerUsage
const positioner = require('electron-traywindow-positioner');
positioner.position(trayWindow, trayBounds);trayWindowmust be an instance of aBrowserWindow.trayBoundsmust be an instance ofRectanglereturned fromtray.getBounds()
Only calculate the postion without positioning the window
const positioner = require('electron-traywindow-positioner');
positioner.calculate(windowBounds, trayBounds);windowBoundsmust be an instance ofRectanglereturned fromBrowserWindow.getBounds().trayBoundsmust be an instance ofRectanglereturned fromtray.getBounds()
Custom alignment
const alignment = {x: 'left', y: 'up'};
const positioner = require('electron-traywindow-positioner');
positioner.position(trayWindow, trayBounds, alignment);
// or
positioner.calculate(windowBounds, trayBounds, alignment);alignmet.xalignment on x axis relative to tray icon when tray bar is top or bottom. The value can be one ofleft,centerorright, default iscenter.alignmet.yalignment on y axis relative to tray icon when tray bar is left or right. The value can be one ofup,centerordown, default isdown.