Skip to content

Commit 1d7b0a9

Browse files
authored
Merge pull request #33 from sentialx/docs
docs: separate docs to files and describe breaking changes
2 parents 1b2aa11 + 6c8cca1 commit 1d7b0a9

File tree

6 files changed

+250
-199
lines changed

6 files changed

+250
-199
lines changed

README.md

Lines changed: 8 additions & 199 deletions
Original file line numberDiff line numberDiff line change
@@ -17,210 +17,19 @@ The following example shows how to get the currently focused window's title and
1717
```javascript
1818
const { windowManager } = require("node-window-manager");
1919

20-
windowManager.requestAccessibility(); // required on macOS
21-
2220
const window = windowManager.getActiveWindow();
2321

24-
// Prints the currently focused window title.
25-
console.log(window.getTitle());
22+
// Prints the currently focused window bounds.
23+
console.log(window.getBounds());
24+
25+
// This method has to be called on macOS before changing the window's bounds, otherwise it will throw an error.
26+
// It will prompt an accessibility permission request dialog, if needed.
27+
windowManager.requestAccessibility();
2628

27-
// Moves the window.
29+
// Sets the active window's bounds.
2830
window.setBounds({ x: 0, y: 0 });
2931
```
3032

3133
# Documentation
3234

33-
## Object `Rectangle`
34-
35-
- `x` number
36-
- `y` number
37-
- `width` number
38-
- `height` number
39-
40-
## Object `WindowInfo`
41-
42-
- `title` string
43-
- `processId` string
44-
- `path` string - path to executable associated with the window
45-
- `bounds` [`Rectangle`](#object-rectangle)
46-
- `opacity` number (`Windows`)
47-
- `owner` [`Window`](#class-window) (`Windows`) - owner window of the current window
48-
49-
## Object `MonitorInfo`
50-
51-
- `isPrimary` boolean
52-
- `bounds` [`Rectangle`](#object-rectangle) - the monitor position and bounds
53-
- `workArea` [`Rectangle`](#object-rectangle) - the monitor working area bounds
54-
55-
## Class `WindowManager`
56-
57-
### Instance methods
58-
59-
#### windowManager.requestAccessibility() `macOS`
60-
Required before any action on macOS.
61-
- Returns `boolean`
62-
63-
#### windowManager.getActiveWindow() `Windows` `macOS`
64-
65-
- Returns [`Window`](#class-window)
66-
67-
#### windowManager.getWindows() `Windows` `macOS`
68-
69-
- Returns [`Window[]`](#class-window)
70-
71-
#### windowManager.getMonitors() `Windows`
72-
73-
- Returns [`Monitor[]`](#class-monitor)
74-
75-
#### windowManager.getPrimaryMonitor() `Windows`
76-
77-
- Returns [`Monitor`](#class-monitor)
78-
79-
### Events
80-
81-
#### Event 'window-activated' `Windows` `macOS`
82-
83-
Returns:
84-
85-
- [`Window`](#class-window)
86-
87-
Emitted when a window has been activated.
88-
89-
## Class `Window`
90-
91-
We try to keep this class similar to Electron's known [`BrowserWindow`](https://electronjs.org/docs/api/browser-window) class, to keep it simple to use.
92-
93-
### new Window(id: number)
94-
95-
- `id` number
96-
97-
### Instance properties
98-
99-
- `id` number
100-
- `processId` number - process id associated with the window
101-
- `path` string - path to executable associated with the window
102-
103-
### Instance methods
104-
105-
#### win.getBounds() `Windows` `macOS`
106-
107-
- Returns [`Rectangle`](#object-rectangle)
108-
109-
#### win.setBounds(bounds: Rectangle) `Windows` `macOS`
110-
111-
Resizes and moves the window to the supplied bounds. Any properties that are not supplied will default to their current values.
112-
113-
```javascript
114-
window.setBounds({ height: 50 });
115-
```
116-
117-
#### win.getInfo() `Windows` `macOS`
118-
119-
Returns [`WindowInfo`](#object-windowinfo)
120-
121-
#### win.getTitle() `Windows` `macOS`
122-
123-
- Returns `string`
124-
125-
#### win.show() `Windows`
126-
127-
Shows the window.
128-
129-
#### win.hide() `Windows`
130-
131-
Hides the window.
132-
133-
#### win.minimize() `Windows` `macOS`
134-
135-
Minimizes the window.
136-
137-
#### win.restore() `Windows` `macOS`
138-
139-
Restores the window.
140-
141-
#### win.maximize() `Windows` `macOS`
142-
143-
Maximizes the window.
144-
145-
#### win.bringToTop() `Windows` `macOS`
146-
147-
Brings the window to top and focuses it.
148-
149-
#### win.setOpacity(opacity: number) `Windows`
150-
151-
- `opacity` - a value between 0 and 1.
152-
153-
Sets the window opacity.
154-
155-
#### win.getOpacity() `Windows`
156-
157-
Gets the window opacity
158-
159-
Returns `number` between 0 and 1.
160-
161-
#### win.getMonitor() `Windows`
162-
163-
Gets monitor which the window belongs to.
164-
165-
Returns [`Monitor`](#class-monitor)
166-
167-
#### win.isWindow() `Windows` `macOS`
168-
169-
Returns `boolean` - whether the window is a valid window.
170-
171-
#### win.isVisible() `Windows`
172-
Returns `boolean` - whether the window is visible or not.
173-
174-
#### win.getOwner() `Windows`
175-
176-
Returns [`Window`](#class-window)
177-
178-
#### win.setOwner(win: [`Window`](#class-window) | number | null) `Windows`
179-
180-
- `win` [Window](#class-window) | number | null
181-
- pass null to unset window owner.
182-
183-
#### win.getIcon(size: number) `Windows` `macOS`
184-
185-
- `size` number - can be only `16`, `32`, `64`, `256`. By default it's `64`.
186-
187-
Returns a png Buffer
188-
189-
190-
## Class `Monitor` `Windows`
191-
192-
### new Monitor(id: number)
193-
194-
- `id` number - the monitor handle
195-
196-
### Instance properties
197-
198-
- `id` number
199-
200-
### Instance methods
201-
202-
#### monitor.getBounds() `Windows`
203-
204-
- Returns [`Rectangle`](#object-rectangle)
205-
206-
#### monitor.getWorkArea() `Windows`
207-
208-
Gets monitor working area bounds.
209-
210-
- Returns [`Rectangle`](#object-rectangle)
211-
212-
#### monitor.getInfo() `Windows`
213-
214-
Returns [`MonitorInfo`](#object-monitorinfo)
215-
216-
#### monitor.isPrimary() `Windows`
217-
218-
Whether the monitor is primary.
219-
220-
- Returns `boolean`
221-
222-
#### monitor.getScaleFactor() `Windows`
223-
224-
Gets monitor scale factor (DPI).
225-
226-
- Returns `number`
35+
The documentation and API references are located in the [`docs`](docs) directory.

docs/breaking-changes.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Breaking changes
2+
3+
List of breaking changes between major versions.
4+
5+
## Planned Breaking API Changes (2.0)
6+
7+
### `windowManager.getScaleFactor(monitor: number)`
8+
9+
```typescript
10+
// Deprecated
11+
windowManager.getScaleFactor(windowManager.getActiveWindow().getMonitor());
12+
// Replace with
13+
windowManager.getActiveWindow().getMonitor().getScaleFactor();
14+
```
15+
16+
### `windowManager.requestAccessibility()` `macOS`
17+
18+
The `windowManager.requestAccessibility` method won't be required before each operation on windows anymore. Only on:
19+
20+
- `window.setBounds`
21+
- `window.maximize`
22+
- `window.minimize`
23+
- `window.restore`
24+
- `window.bringToTop`
25+
- `window.getTitle`
26+
27+
### `window.getMonitor(): number`
28+
29+
Now the `window.getMonitor` method returns [`Monitor`](monitor.md) object.
30+
31+
### `window.getInfo()`
32+
33+
`window.getInfo` method has been removed.
34+
35+
```typescript
36+
// Deprecated
37+
const { title } = window.getInfo();
38+
// Replace with
39+
const title = window.getTitle();
40+
```

docs/monitor.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## Class `Monitor` `Windows`
2+
3+
Control monitors.
4+
5+
```typescript
6+
import { windowManager } from 'node-window-manager';
7+
8+
// Gets height of the primary window working area.
9+
const { height } = windowManager.getPrimaryWindow().getWorkArea();
10+
```
11+
12+
### new Monitor(id: number)
13+
14+
- `id` number - the monitor handle
15+
16+
### Instance properties
17+
18+
- `id` number
19+
20+
### Instance methods
21+
22+
#### monitor.getBounds() `Windows`
23+
24+
- Returns [`Rectangle`](rectangle.md)
25+
26+
#### monitor.getWorkArea() `Windows`
27+
28+
Gets monitor working area bounds.
29+
30+
- Returns [`Rectangle`](rectangle.md)
31+
32+
#### monitor.isPrimary() `Windows`
33+
34+
Whether the monitor is primary.
35+
36+
- Returns `boolean`
37+
38+
#### monitor.getScaleFactor() `Windows`
39+
40+
Gets monitor scale factor (DPI).
41+
42+
- Returns `number`

docs/rectangle.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Object `Rectangle`
2+
3+
- `x` number
4+
- `y` number
5+
- `width` number
6+
- `height` number

docs/window-manager.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## `windowManager`
2+
3+
Get monitors and opened windows.
4+
5+
```typescript
6+
import { windowManager } from 'node-window-manager';
7+
8+
windowManager.requestAccessibility();
9+
10+
const window = windowManager.getActiveWindow();
11+
12+
// Prints the currently focused window title.
13+
console.log(window.getTitle());
14+
```
15+
16+
### Instance methods
17+
18+
#### windowManager.requestAccessibility() `macOS`
19+
20+
If the accessibility permission is not granted on `macOS`, it opens an accessibility permission request dialog.
21+
22+
The method is required to call before calling the following methods:
23+
24+
- `window.setBounds`
25+
- `window.maximize`
26+
- `window.minimize`
27+
- `window.restore`
28+
- `window.bringToTop`
29+
- `window.getTitle`
30+
31+
- Returns `boolean`
32+
33+
#### windowManager.getActiveWindow() `Windows` `macOS`
34+
35+
- Returns [`Window`](window.md)
36+
37+
#### windowManager.getWindows() `Windows` `macOS`
38+
39+
- Returns [`Window[]`](window.md)
40+
41+
#### windowManager.getMonitors() `Windows`
42+
43+
- Returns [`Monitor[]`](monitor.md)
44+
45+
#### windowManager.getPrimaryMonitor() `Windows`
46+
47+
- Returns [`Monitor`](monitor.md)
48+
49+
### Events
50+
51+
#### Event 'window-activated' `Windows` `macOS`
52+
53+
Returns:
54+
55+
- [`Window`](window.md)
56+
57+
Emitted when a window has been activated.

0 commit comments

Comments
 (0)