This repository was archived by the owner on Aug 31, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +53
-1
lines changed
Expand file tree Collapse file tree 1 file changed +53
-1
lines changed Original file line number Diff line number Diff line change 33> Easy and intuitive window positioning for electron browser windows.
44>
55
6- Where to open an ...
6+ When opening an Electron BrowserWindow one have to define an position or use the default, which centers the
7+ window over all screens.
8+ On some systems the default centering won't open the window on your current screen, e.g. the window could open on a monitor
9+ which is switched off.
10+
11+ This package detects on which screen the users mouse is and centers the window on that screen. Or opens it in the top
12+ left corner of that screen.
13+
14+ ## Installation
15+ ```
16+ npm install electron-window-position --save
17+ ```
718
819## Usage
20+ ``` node
21+ const electron = require (' electron' );
22+ const WindowPosition = require ( ' electron-window-position' );
23+
24+ // Open window on electron.app.ready
25+ new WindowPosition ( function ( pos ){
26+ mainWindow = new electron.BrowserWindow ({
27+ x: pos .x ,
28+ y: pos .y ,
29+ width: 300 ,
30+ height: 300 ,
31+ show: true ,
32+ resizable: false
33+ });
34+ });
35+ ```
36+
37+ ``` node
38+ const electron = require (' electron' );
39+ const WindowPosition = require ( ' electron-window-position' );
40+
41+ // Get position for centered window
42+ var position = new WindowPosition ();
43+ try {
44+ var pos = position .getActiveScreenCenter (300 ,300 );
45+
46+ mainWindow = new electron.BrowserWindow ({
47+ x: pos .x ,
48+ y: pos .y ,
49+ width: 300 ,
50+ height: 300 ,
51+ show: true ,
52+ resizable: false
53+ });
54+ } catch (e) {
55+ // electron.app not ready
56+ }
57+
58+ ```
59+
60+ See also JSDoc at [ GitHub Pages] ( https://kimbtech.github.io/electron-window-position/WindowPosition.html )
961
You can’t perform that action at this time.
0 commit comments