@dimensional-innovations/electron-background 2.3.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +340 -49
- package/dist/InitContext.d.ts +40 -0
- package/dist/InitContext.js +23 -0
- package/dist/InitPlugin.d.ts +39 -0
- package/dist/InitPlugin.js +2 -0
- package/dist/index.d.ts +12 -8
- package/dist/index.js +12 -8
- package/dist/init.d.ts +10 -92
- package/dist/init.js +47 -60
- package/dist/{AutoUpdater.d.ts → plugins/AutoUpdater.d.ts} +8 -5
- package/dist/{AutoUpdater.js → plugins/AutoUpdater.js} +5 -5
- package/dist/{DevTools.d.ts → plugins/DevTools.d.ts} +4 -3
- package/dist/{DevTools.js → plugins/DevTools.js} +2 -2
- package/dist/{NodeHeartbeat.d.ts → plugins/NodeHeartbeat.d.ts} +8 -5
- package/dist/{NodeHeartbeat.js → plugins/NodeHeartbeat.js} +3 -3
- package/dist/{PrivilegedSchemes.d.ts → plugins/PrivilegedSchemes.d.ts} +2 -2
- package/dist/plugins/PrivilegedSchemes.js +27 -0
- package/dist/{SingleInstance.d.ts → plugins/SingleInstance.d.ts} +3 -2
- package/dist/{SingleInstance.js → plugins/SingleInstance.js} +3 -4
- package/dist/plugins/StaticFileDir.d.ts +16 -0
- package/dist/{StaticFileDir.js → plugins/StaticFileDir.js} +1 -2
- package/dist/{TouchEvents.d.ts → plugins/TouchEvents.d.ts} +2 -2
- package/dist/plugins/TouchEvents.js +14 -0
- package/dist/windows/AppBrowserWindow.d.ts +28 -0
- package/dist/{TouchEvents.js → windows/AppBrowserWindow.js} +16 -6
- package/dist/windows/FullScreenBrowserWindow.d.ts +17 -0
- package/dist/windows/FullScreenBrowserWindow.js +55 -0
- package/dist/windows/KioskBrowserWindow.d.ts +15 -0
- package/dist/windows/KioskBrowserWindow.js +32 -0
- package/dist/windows/util.d.ts +11 -0
- package/dist/windows/util.js +25 -0
- package/package.json +1 -1
- package/dist/BrowserWindow.d.ts +0 -47
- package/dist/BrowserWindow.js +0 -129
- package/dist/PrivilegedSchemes.js +0 -37
- package/dist/StaticFileDir.d.ts +0 -26
package/README.md
CHANGED
|
@@ -1,99 +1,390 @@
|
|
|
1
1
|
# @dimensional-innovations/electron-background
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A TypeScript library that simplifies Electron app initialization through a plugin-based architecture.
|
|
4
4
|
|
|
5
5
|
## Getting Started
|
|
6
6
|
|
|
7
|
-
###
|
|
8
|
-
Add the package using npm or yarn:
|
|
9
|
-
```bash
|
|
10
|
-
npm install @dimensional-innovations/electron-background
|
|
11
|
-
```
|
|
7
|
+
### Installation
|
|
12
8
|
|
|
13
9
|
```bash
|
|
14
|
-
|
|
10
|
+
npm install @dimensional-innovations/electron-background
|
|
15
11
|
```
|
|
16
12
|
|
|
17
13
|
### Setup for Vue CLI / Webpack
|
|
18
14
|
|
|
19
|
-
If you are using the Vue CLI, add the following to your main or background file.
|
|
15
|
+
If you are using the Vue CLI, add the following to your main or background file.
|
|
16
|
+
|
|
20
17
|
```typescript
|
|
21
|
-
import
|
|
18
|
+
import path from 'path';
|
|
19
|
+
import {
|
|
20
|
+
init,
|
|
21
|
+
KioskBrowserWindow,
|
|
22
|
+
PrivilegedSchemes,
|
|
23
|
+
StaticFileDir,
|
|
24
|
+
AutoUpdater,
|
|
25
|
+
DevTools,
|
|
26
|
+
DevToolExtensions,
|
|
27
|
+
} from '@dimensional-innovations/electron-background';
|
|
22
28
|
|
|
23
29
|
init({
|
|
24
|
-
|
|
30
|
+
windows: [
|
|
31
|
+
() => new KioskBrowserWindow({
|
|
32
|
+
appUrl: process.env.WEBPACK_DEV_URL ? process.env.WEBPACK_DEV_URL : 'app://index.html'
|
|
33
|
+
}),
|
|
34
|
+
],
|
|
25
35
|
plugins: [
|
|
26
|
-
new AutoUpdater({ channel: 'stable' }),
|
|
27
|
-
new DevTools(),
|
|
28
|
-
new KioskBrowserWindow(),
|
|
29
36
|
new PrivilegedSchemes(['app']),
|
|
30
|
-
new StaticFileDir('app', __dirname),
|
|
31
|
-
new
|
|
32
|
-
|
|
37
|
+
new StaticFileDir('app', path.join(__dirname, '../renderer')),
|
|
38
|
+
new AutoUpdater({ channel: 'stable' }),
|
|
39
|
+
new DevTools([DevToolExtensions.VUEJS_DEVTOOLS]),
|
|
40
|
+
],
|
|
33
41
|
});
|
|
34
42
|
```
|
|
35
43
|
|
|
36
44
|
### Setup for Vite
|
|
37
45
|
|
|
38
|
-
If you are using Vite, add the following to your main or background file.
|
|
46
|
+
If you are using Vite, add the following to your main or background file.
|
|
47
|
+
|
|
39
48
|
```typescript
|
|
40
|
-
import
|
|
41
|
-
import {
|
|
49
|
+
import path from 'path';
|
|
50
|
+
import {
|
|
51
|
+
init,
|
|
52
|
+
KioskBrowserWindow,
|
|
53
|
+
PrivilegedSchemes,
|
|
54
|
+
StaticFileDir,
|
|
55
|
+
AutoUpdater,
|
|
56
|
+
DevTools,
|
|
57
|
+
DevToolExtensions,
|
|
58
|
+
} from '@dimensional-innovations/electron-background';
|
|
42
59
|
|
|
43
60
|
init({
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
61
|
+
windows: [
|
|
62
|
+
() => new KioskBrowserWindow({
|
|
63
|
+
appUrl: process.env['ELECTRON_RENDERER_URL']
|
|
64
|
+
? process.env['ELECTRON_RENDERER_URL']
|
|
65
|
+
: `file://${path.join(__dirname, '../renderer/index.html')`,
|
|
66
|
+
}),
|
|
67
|
+
],
|
|
47
68
|
plugins: [
|
|
48
69
|
new AutoUpdater({ channel: 'stable' }),
|
|
49
70
|
new DevTools(),
|
|
50
71
|
new KioskBrowserWindow(),
|
|
51
|
-
new TouchEvents(),
|
|
52
72
|
]
|
|
53
73
|
});
|
|
54
74
|
```
|
|
55
75
|
|
|
56
|
-
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Windows
|
|
79
|
+
|
|
80
|
+
Windows are defined as factory functions in the `windows` array. Each factory is called after `app.whenReady()` resolves, satisfying Electron's requirement that `BrowserWindow` instances are not created before the app is ready.
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
init({
|
|
84
|
+
windows: [
|
|
85
|
+
() => new KioskBrowserWindow({ appUrl: '...' }),
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### AppBrowserWindow
|
|
91
|
+
|
|
92
|
+
The base window class. All built-in window classes extend it. Extends Electron's `BrowserWindow` with an `appUrl` constructor option and a `loadApp()` method.
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
() => new AppBrowserWindow({
|
|
96
|
+
appUrl: 'app://index.html',
|
|
97
|
+
width: 1280,
|
|
98
|
+
height: 720,
|
|
99
|
+
})
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
All standard `BrowserWindowConstructorOptions` are supported in addition to `appUrl`.
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
### KioskBrowserWindow
|
|
107
|
+
|
|
108
|
+
Runs the window in kiosk mode when the application is packaged. In development it behaves as a normal window, making it easy to inspect and resize.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
() => new KioskBrowserWindow({ appUrl: 'app://index.html' })
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Options:**
|
|
115
|
+
|
|
116
|
+
| Option | Type | Default | Description |
|
|
117
|
+
|--------|------|---------|-------------|
|
|
118
|
+
| `appUrl` | `string` | — | The URL to load. |
|
|
119
|
+
| `screen` | `'primary' \| 'secondary' \| number` | `'primary'` | The display to run kiosk mode on. Use `'secondary'` for the first non-primary display, or a zero-based index for a specific display. |
|
|
120
|
+
| `...BrowserWindowConstructorOptions` | | | All standard Electron options are supported. |
|
|
121
|
+
|
|
122
|
+
**Second parameter:**
|
|
123
|
+
|
|
124
|
+
| Parameter | Type | Default | Description |
|
|
125
|
+
|-----------|------|---------|-------------|
|
|
126
|
+
| `enabled` | `boolean` | `app.isPackaged` | Set to `true` to force kiosk behavior in development. |
|
|
57
127
|
|
|
58
|
-
|
|
128
|
+
**Examples:**
|
|
59
129
|
|
|
60
|
-
If a feature you need isn't listed below, you can still add it to the init script by defining the plugin in your application. For example, if we wanted to customize the autoplay policy flag in electron, we would add the following to our init method.
|
|
61
130
|
```typescript
|
|
62
|
-
|
|
63
|
-
|
|
131
|
+
// Default — kiosk on the primary display when packaged
|
|
132
|
+
() => new KioskBrowserWindow({ appUrl: 'app://index.html' })
|
|
64
133
|
|
|
134
|
+
// Kiosk on the secondary display
|
|
135
|
+
() => new KioskBrowserWindow({ appUrl: 'app://index.html', screen: 'secondary' })
|
|
136
|
+
|
|
137
|
+
// Kiosk on the display at index 2
|
|
138
|
+
() => new KioskBrowserWindow({ appUrl: 'app://index.html', screen: 2 })
|
|
139
|
+
|
|
140
|
+
// Force kiosk behavior in development
|
|
141
|
+
() => new KioskBrowserWindow({ appUrl: 'app://index.html' }, true)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
### FullScreenBrowserWindow
|
|
147
|
+
|
|
148
|
+
Ensures the window always occupies the full bounds of a display. When packaged, the window snaps to the target display on `ready-to-show` and automatically re-snaps when display configuration changes (display added, removed, or resized). In development it behaves as a normal window.
|
|
149
|
+
|
|
150
|
+
Prefer `FullScreenBrowserWindow` over `KioskBrowserWindow` when:
|
|
151
|
+
- Running multiple windows across different displays
|
|
152
|
+
- A window needs to span multiple displays (see [spanning multiple displays](#example-window-spanning-multiple-displays))
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
() => new FullScreenBrowserWindow({ appUrl: 'app://index.html' })
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Options:**
|
|
159
|
+
|
|
160
|
+
| Option | Type | Default | Description |
|
|
161
|
+
|--------|------|---------|-------------|
|
|
162
|
+
| `appUrl` | `string` | — | The URL to load. |
|
|
163
|
+
| `screen` | `'primary' \| 'secondary' \| number` | `'primary'` | The display to occupy. Use `'secondary'` for the first non-primary display, or a zero-based index for a specific display. |
|
|
164
|
+
| `...BrowserWindowConstructorOptions` | | | All standard Electron options are supported. |
|
|
165
|
+
|
|
166
|
+
**Second parameter:**
|
|
167
|
+
|
|
168
|
+
| Parameter | Type | Default | Description |
|
|
169
|
+
|-----------|------|---------|-------------|
|
|
170
|
+
| `enabled` | `boolean` | `app.isPackaged` | Set to `true` to force fullscreen behavior in development. |
|
|
171
|
+
|
|
172
|
+
**Example — multiple windows, one per display:**
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
65
175
|
init({
|
|
66
|
-
|
|
176
|
+
windows: [
|
|
177
|
+
() => new FullScreenBrowserWindow({ appUrl: 'app://index.html', screen: 'primary' }),
|
|
178
|
+
() => new FullScreenBrowserWindow({ appUrl: 'app://index.html', screen: 'secondary' }),
|
|
179
|
+
],
|
|
67
180
|
plugins: [
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
]
|
|
181
|
+
new PrivilegedSchemes(['app']),
|
|
182
|
+
new StaticFileDir('app', path.join(__dirname, '../renderer')),
|
|
183
|
+
new AutoUpdater({ channel: 'stable' }),
|
|
184
|
+
],
|
|
72
185
|
});
|
|
73
186
|
```
|
|
74
187
|
|
|
75
|
-
|
|
76
|
-
Starts the auto update process, checking for updates every 3 minutes and automatically installing the update once one is found.
|
|
188
|
+
Each window independently tracks its target display and re-snaps when the display configuration changes.
|
|
77
189
|
|
|
78
|
-
|
|
190
|
+
---
|
|
79
191
|
|
|
80
|
-
|
|
81
|
-
Installs dev tools extensions and opens the devTools panel.
|
|
192
|
+
## Plugins
|
|
82
193
|
|
|
83
|
-
|
|
84
|
-
|
|
194
|
+
Plugins implement the `InitPlugin` interface and hook into one or more phases of the initialization lifecycle.
|
|
195
|
+
|
|
196
|
+
### Lifecycle
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
beforeReady → app.whenReady() → afterReady → [per window] beforeLoad → loadApp() → afterLoad
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
| Phase | Context | Typical use |
|
|
203
|
+
|-------|---------|-------------|
|
|
204
|
+
| `beforeReady` | No window | Registering privileged schemes |
|
|
205
|
+
| `afterReady` | No window | App-level setup after Electron is ready |
|
|
206
|
+
| `beforeLoad` | Window available | Installing extensions, attaching window event handlers |
|
|
207
|
+
| `afterLoad` | Window available | Starting background services, adjusting window state after load |
|
|
85
208
|
|
|
86
|
-
|
|
87
|
-
|
|
209
|
+
The context object passed to each phase contains:
|
|
210
|
+
- `log` — an `electron-log` instance. Use this instead of `console` so output is captured in log files.
|
|
211
|
+
- `browserWindow` — the `AppBrowserWindow` instance. Only available in `beforeLoad` and `afterLoad`.
|
|
88
212
|
|
|
89
|
-
|
|
90
|
-
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
### Built-in Plugins
|
|
216
|
+
|
|
217
|
+
#### AutoUpdater
|
|
218
|
+
|
|
219
|
+
Checks for and automatically installs updates every 3 minutes using `electron-updater`. Only runs when packaged by default.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
new AutoUpdater({ channel: 'stable' })
|
|
223
|
+
|
|
224
|
+
// Custom channel
|
|
225
|
+
new AutoUpdater({ channel: 'beta' })
|
|
226
|
+
|
|
227
|
+
// Force-enable in development
|
|
228
|
+
new AutoUpdater({ channel: 'stable' }, true)
|
|
229
|
+
```
|
|
91
230
|
|
|
92
|
-
|
|
93
|
-
Registers a custom scheme to serve static files.
|
|
231
|
+
#### DevTools
|
|
94
232
|
|
|
95
|
-
|
|
96
|
-
|
|
233
|
+
Installs browser extensions and opens DevTools. Only runs in development by default.
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
import { DevTools, DevToolExtensions } from '@dimensional-innovations/electron-background';
|
|
237
|
+
|
|
238
|
+
new DevTools([DevToolExtensions.VUEJS_DEVTOOLS])
|
|
239
|
+
new DevTools([DevToolExtensions.REACT_DEVELOPER_TOOLS, DevToolExtensions.REDUX_DEVTOOLS])
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Available extensions: `VUEJS_DEVTOOLS`, `REACT_DEVELOPER_TOOLS`, `REDUX_DEVTOOLS`, `MOBX_DEVTOOLS`, `EMBER_INSPECTOR`, `BACKBONE_DEBUGGER`, `JQUERY_DEBUGGER`.
|
|
243
|
+
|
|
244
|
+
#### SingleInstance
|
|
245
|
+
|
|
246
|
+
Ensures only one instance of the app runs at a time. If a second instance is launched, it quits immediately and the first instance is focused.
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
new SingleInstance()
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
#### PrivilegedSchemes
|
|
253
|
+
|
|
254
|
+
Registers custom URL schemes as privileged (secure, standard, with Fetch API support). Runs in `beforeReady`. Pair with `StaticFileDir` to serve local files via a custom scheme.
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
new PrivilegedSchemes(['app'])
|
|
258
|
+
|
|
259
|
+
// Multiple schemes
|
|
260
|
+
new PrivilegedSchemes(['app', 'media'])
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
#### StaticFileDir
|
|
264
|
+
|
|
265
|
+
Registers a custom scheme to serve static files from a local directory. Runs in `afterReady`.
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
new StaticFileDir('app', path.join(__dirname, '../renderer'))
|
|
269
|
+
|
|
270
|
+
// A separate scheme for media assets
|
|
271
|
+
new StaticFileDir('media', path.join(__dirname, '../assets'))
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
#### TouchEvents
|
|
275
|
+
|
|
276
|
+
Enables touch event support via Chromium's `--touch-events` command-line switch.
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
new TouchEvents()
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
#### Heartbeat
|
|
283
|
+
|
|
284
|
+
Sends periodic HTTP HEAD requests to a URL for uptime monitoring. Only runs when packaged by default.
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
import { Heartbeat } from '@dimensional-innovations/electron-background';
|
|
288
|
+
|
|
289
|
+
new Heartbeat({ url: 'https://your-monitor.example.com/ping', pollInterval: 30_000 })
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
#### BetterStackHeartbeat
|
|
293
|
+
|
|
294
|
+
Sends periodic heartbeats to [BetterStack](https://betterstack.com) uptime monitoring. Only runs when packaged by default.
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
import { BetterStackHeartbeat } from '@dimensional-innovations/electron-background';
|
|
298
|
+
|
|
299
|
+
new BetterStackHeartbeat({ heartbeatApiKey: 'your-api-key' })
|
|
300
|
+
|
|
301
|
+
// Custom poll interval (default is 30 seconds)
|
|
302
|
+
new BetterStackHeartbeat({ heartbeatApiKey: 'your-api-key', pollInterval: 60_000 })
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## Custom Plugins
|
|
308
|
+
|
|
309
|
+
Implement the `InitPlugin` interface and define whichever lifecycle methods your plugin needs. Omitting a method means that phase is skipped for your plugin.
|
|
310
|
+
|
|
311
|
+
```typescript
|
|
312
|
+
import {
|
|
313
|
+
InitPlugin,
|
|
314
|
+
NonBrowserWindowInitContext,
|
|
315
|
+
BrowserWindowInitContext,
|
|
316
|
+
} from '@dimensional-innovations/electron-background';
|
|
317
|
+
|
|
318
|
+
class MyPlugin implements InitPlugin {
|
|
319
|
+
async afterReady({ log }: NonBrowserWindowInitContext): Promise<void> {
|
|
320
|
+
log.info('App is ready');
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
async afterLoad({ browserWindow, log }: BrowserWindowInitContext): Promise<void> {
|
|
324
|
+
log.info('Window loaded:', browserWindow.id);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Pass the plugin directly in the `plugins` array:
|
|
330
|
+
|
|
331
|
+
```typescript
|
|
332
|
+
init({
|
|
333
|
+
windows: [...],
|
|
334
|
+
plugins: [new MyPlugin()],
|
|
335
|
+
});
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
### Example: Window Spanning Multiple Displays
|
|
341
|
+
|
|
342
|
+
For setups where a single window must stretch across several displays, use a custom plugin to compute the combined bounds of all displays and apply them via `setBounds` in `afterLoad`. `FullScreenBrowserWindow` is used as the base window because it removes the frame and disables user resizing and movement — the plugin then overrides the bounds to cover all displays.
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
import { screen } from 'electron';
|
|
346
|
+
import path from 'path';
|
|
347
|
+
import {
|
|
348
|
+
init,
|
|
349
|
+
InitPlugin,
|
|
350
|
+
BrowserWindowInitContext,
|
|
351
|
+
FullScreenBrowserWindow,
|
|
352
|
+
PrivilegedSchemes,
|
|
353
|
+
StaticFileDir,
|
|
354
|
+
} from '@dimensional-innovations/electron-background';
|
|
355
|
+
|
|
356
|
+
class SpanAllDisplays implements InitPlugin {
|
|
357
|
+
async afterLoad({ browserWindow }: BrowserWindowInitContext): Promise<void> {
|
|
358
|
+
const displays = screen.getAllDisplays();
|
|
359
|
+
|
|
360
|
+
const left = Math.min(...displays.map(d => d.bounds.x));
|
|
361
|
+
const top = Math.min(...displays.map(d => d.bounds.y));
|
|
362
|
+
const right = Math.max(...displays.map(d => d.bounds.x + d.bounds.width));
|
|
363
|
+
const bottom = Math.max(...displays.map(d => d.bounds.y + d.bounds.height));
|
|
364
|
+
|
|
365
|
+
browserWindow.setBounds({
|
|
366
|
+
x: left,
|
|
367
|
+
y: top,
|
|
368
|
+
width: right - left,
|
|
369
|
+
height: bottom - top,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
init({
|
|
375
|
+
windows: [
|
|
376
|
+
() => new FullScreenBrowserWindow({ appUrl: 'app://index.html' }),
|
|
377
|
+
],
|
|
378
|
+
plugins: [
|
|
379
|
+
new PrivilegedSchemes(['app']),
|
|
380
|
+
new StaticFileDir('app', path.join(__dirname, '../renderer')),
|
|
381
|
+
new SpanAllDisplays(),
|
|
382
|
+
],
|
|
383
|
+
});
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
---
|
|
97
387
|
|
|
98
388
|
## API Reference
|
|
99
|
-
|
|
389
|
+
|
|
390
|
+
For the complete API exported by this package, see [API.md](./API.md).
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AppBrowserWindow } from "./windows/AppBrowserWindow";
|
|
2
|
+
/**
|
|
3
|
+
* The context object passed to each plugin during the init process.
|
|
4
|
+
*/
|
|
5
|
+
export declare class InitContext<T = unknown> {
|
|
6
|
+
/**
|
|
7
|
+
* The log instance. This should be used over `console` in plugin implementations.
|
|
8
|
+
*/
|
|
9
|
+
log: Pick<Console, 'error' | 'warn' | 'info' | 'debug'>;
|
|
10
|
+
config?: T | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* The browser window that the app is loaded into. This is available in the context
|
|
13
|
+
* in the `beforeLoad` and `afterLoad` methods.
|
|
14
|
+
*/
|
|
15
|
+
browserWindow?: AppBrowserWindow | undefined;
|
|
16
|
+
constructor(
|
|
17
|
+
/**
|
|
18
|
+
* The log instance. This should be used over `console` in plugin implementations.
|
|
19
|
+
*/
|
|
20
|
+
log: Pick<Console, 'error' | 'warn' | 'info' | 'debug'>, config?: T | undefined,
|
|
21
|
+
/**
|
|
22
|
+
* The browser window that the app is loaded into. This is available in the context
|
|
23
|
+
* in the `beforeLoad` and `afterLoad` methods.
|
|
24
|
+
*/
|
|
25
|
+
browserWindow?: AppBrowserWindow | undefined);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Represents the InitContext during the beforeReady phase.
|
|
29
|
+
*/
|
|
30
|
+
export type BeforeReadyInitContext<T> = Omit<InitContext<T>, 'config' | 'browserWindow'>;
|
|
31
|
+
/**
|
|
32
|
+
* Represents the InitContext before the BrowserWindow has been set. Used in the
|
|
33
|
+
* "beforeReady" and "afterReady" methods.
|
|
34
|
+
*/
|
|
35
|
+
export type NonBrowserWindowInitContext<T> = Omit<InitContext<T>, 'config' | 'browserWindow'> & Required<Pick<InitContext<T>, 'config'>>;
|
|
36
|
+
/**
|
|
37
|
+
* Represents the InitContext after the BrowserWindow has been set. Used in the
|
|
38
|
+
* "beforeLoad" and "afterLoad" methods.
|
|
39
|
+
*/
|
|
40
|
+
export type BrowserWindowInitContext<T> = Omit<InitContext<T>, 'config' | 'browserWindow'> & Required<Pick<InitContext<T>, 'config' | 'browserWindow'>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InitContext = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The context object passed to each plugin during the init process.
|
|
6
|
+
*/
|
|
7
|
+
class InitContext {
|
|
8
|
+
constructor(
|
|
9
|
+
/**
|
|
10
|
+
* The log instance. This should be used over `console` in plugin implementations.
|
|
11
|
+
*/
|
|
12
|
+
log, config,
|
|
13
|
+
/**
|
|
14
|
+
* The browser window that the app is loaded into. This is available in the context
|
|
15
|
+
* in the `beforeLoad` and `afterLoad` methods.
|
|
16
|
+
*/
|
|
17
|
+
browserWindow) {
|
|
18
|
+
this.log = log;
|
|
19
|
+
this.config = config;
|
|
20
|
+
this.browserWindow = browserWindow;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.InitContext = InitContext;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BeforeReadyInitContext, NonBrowserWindowInitContext, BrowserWindowInitContext } from "./InitContext";
|
|
2
|
+
/**
|
|
3
|
+
* A plugin is used to execute logic at various stages during the init process.
|
|
4
|
+
*
|
|
5
|
+
* Implementations can define one or more of the optional methods to customize
|
|
6
|
+
* application instance.
|
|
7
|
+
*/
|
|
8
|
+
export interface InitPlugin<T = unknown> {
|
|
9
|
+
/**
|
|
10
|
+
* beforeReady is executed before the `app.whenReady()` promise resolves.
|
|
11
|
+
* beforeReady method must be synchronous so that all methods complete before the
|
|
12
|
+
* app.whenReady promise resolves.
|
|
13
|
+
*
|
|
14
|
+
* @param context - The current InitContext instance.
|
|
15
|
+
*/
|
|
16
|
+
beforeReady?(context: BeforeReadyInitContext<T>): false;
|
|
17
|
+
/**
|
|
18
|
+
* afterReady is executed after the `app.whenReady()` promise resolves, but before the
|
|
19
|
+
* BrowserWindow is created.
|
|
20
|
+
*
|
|
21
|
+
* @param context - The current InitContext instance.
|
|
22
|
+
*/
|
|
23
|
+
afterReady?(context: NonBrowserWindowInitContext<T>): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* beforeLoad is executed after the browserWindow is created, but before the application
|
|
26
|
+
* has been loaded into the window. This runs for each BrowserWindow created during init
|
|
27
|
+
* process.
|
|
28
|
+
*
|
|
29
|
+
* @param context - The current InitContext instance.
|
|
30
|
+
*/
|
|
31
|
+
beforeLoad?(context: BrowserWindowInitContext<T>): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* afterLoad is executed after the application has been loaded into the browserWindow.
|
|
34
|
+
* This runs for each BrowserWindow created during the init process.
|
|
35
|
+
*
|
|
36
|
+
* @param context - The current InitContext instance.
|
|
37
|
+
*/
|
|
38
|
+
afterLoad?(context: BrowserWindowInitContext<T>): Promise<void>;
|
|
39
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
export * from './AutoUpdater';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
1
|
+
export * from './plugins/AutoUpdater';
|
|
2
|
+
export * from './plugins/DevTools';
|
|
3
|
+
export * from './plugins/NodeHeartbeat';
|
|
4
|
+
export * from './plugins/PrivilegedSchemes';
|
|
5
|
+
export * from './plugins/SingleInstance';
|
|
6
|
+
export * from './plugins/StaticFileDir';
|
|
7
|
+
export * from './plugins/TouchEvents';
|
|
8
|
+
export * from './windows/AppBrowserWindow';
|
|
9
|
+
export * from './windows/FullScreenBrowserWindow';
|
|
10
|
+
export * from './windows/KioskBrowserWindow';
|
|
9
11
|
export * from './init';
|
|
12
|
+
export * from './InitContext';
|
|
13
|
+
export * from './InitPlugin';
|
package/dist/index.js
CHANGED
|
@@ -14,12 +14,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./AutoUpdater"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
__exportStar(require("./
|
|
21
|
-
__exportStar(require("./
|
|
22
|
-
__exportStar(require("./
|
|
23
|
-
__exportStar(require("./
|
|
24
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./plugins/AutoUpdater"), exports);
|
|
18
|
+
__exportStar(require("./plugins/DevTools"), exports);
|
|
19
|
+
__exportStar(require("./plugins/NodeHeartbeat"), exports);
|
|
20
|
+
__exportStar(require("./plugins/PrivilegedSchemes"), exports);
|
|
21
|
+
__exportStar(require("./plugins/SingleInstance"), exports);
|
|
22
|
+
__exportStar(require("./plugins/StaticFileDir"), exports);
|
|
23
|
+
__exportStar(require("./plugins/TouchEvents"), exports);
|
|
24
|
+
__exportStar(require("./windows/AppBrowserWindow"), exports);
|
|
25
|
+
__exportStar(require("./windows/FullScreenBrowserWindow"), exports);
|
|
26
|
+
__exportStar(require("./windows/KioskBrowserWindow"), exports);
|
|
25
27
|
__exportStar(require("./init"), exports);
|
|
28
|
+
__exportStar(require("./InitContext"), exports);
|
|
29
|
+
__exportStar(require("./InitPlugin"), exports);
|