@dimensional-innovations/electron-background 2.0.8 → 2.1.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 +8 -18
- package/dist/AutoUpdater.d.ts +13 -2
- package/dist/AutoUpdater.js +7 -6
- package/dist/BrowserWindow.d.ts +0 -1
- package/dist/BrowserWindow.js +5 -14
- package/dist/NodeHeartbeat.js +1 -1
- package/dist/init.d.ts +1 -13
- package/dist/init.js +2 -7
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -18,21 +18,17 @@ yarn add @dimensional-innovations/electron-background
|
|
|
18
18
|
|
|
19
19
|
If you are using the Vue CLI, add the following to your main or background file.
|
|
20
20
|
```typescript
|
|
21
|
-
import { AutoUpdater, DevTools,
|
|
22
|
-
import { config } from '../package';
|
|
21
|
+
import { AutoUpdater, DevTools, init, KioskBrowserWindow, PrivilegedSchemes, StaticFileDir, TouchEvents } from '@dimensional-innovations/electron-background';
|
|
23
22
|
|
|
24
23
|
init({
|
|
25
24
|
appUrl: process.env.WEBPACK_DEV_URL ? process.env.WEBPACK_DEV_URL : 'app://index.html',
|
|
26
|
-
config,
|
|
27
25
|
plugins: [
|
|
28
|
-
new AutoUpdater(),
|
|
26
|
+
new AutoUpdater({ channel: 'stable' }),
|
|
29
27
|
new DevTools(),
|
|
30
28
|
new KioskBrowserWindow(),
|
|
31
29
|
new PrivilegedSchemes(['app']),
|
|
32
30
|
new StaticFileDir('app', __dirname),
|
|
33
31
|
new TouchEvents(),
|
|
34
|
-
new VueElectronSettings(),
|
|
35
|
-
new VueElectronVersion()
|
|
36
32
|
]
|
|
37
33
|
});
|
|
38
34
|
```
|
|
@@ -41,22 +37,18 @@ init({
|
|
|
41
37
|
|
|
42
38
|
If you are using Vite, add the following to your main or background file.
|
|
43
39
|
```typescript
|
|
44
|
-
import { AutoUpdater, DevTools,
|
|
45
|
-
import {
|
|
46
|
-
import { config } from '../package';
|
|
40
|
+
import { AutoUpdater, DevTools, init, KioskBrowserWindow, TouchEvents } from '@dimensional-innovations/electron-background';
|
|
41
|
+
import { join } from 'path';
|
|
47
42
|
|
|
48
43
|
init({
|
|
49
44
|
appUrl: process.env['ELECTRON_RENDERER_URL']
|
|
50
45
|
? process.env['ELECTRON_RENDERER_URL']
|
|
51
46
|
: `file://${join(__dirname, '../renderer/index.html')}`,
|
|
52
|
-
config,
|
|
53
47
|
plugins: [
|
|
54
|
-
new AutoUpdater(),
|
|
48
|
+
new AutoUpdater({ channel: 'stable' }),
|
|
55
49
|
new DevTools(),
|
|
56
50
|
new KioskBrowserWindow(),
|
|
57
51
|
new TouchEvents(),
|
|
58
|
-
new VueElectronSettings(),
|
|
59
|
-
new VueElectronVersion()
|
|
60
52
|
]
|
|
61
53
|
});
|
|
62
54
|
```
|
|
@@ -67,13 +59,11 @@ By default, the init method creates a BrowserWindow and loads the specified appl
|
|
|
67
59
|
|
|
68
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.
|
|
69
61
|
```typescript
|
|
70
|
-
import { init } from '@dimensional-innovations/
|
|
62
|
+
import { init } from '@dimensional-innovations/electron-background';
|
|
71
63
|
import { app } from 'electron';
|
|
72
|
-
import { config } from '../package';
|
|
73
64
|
|
|
74
65
|
init({
|
|
75
66
|
appUrl: ...,
|
|
76
|
-
config,
|
|
77
67
|
plugins: [
|
|
78
68
|
...,
|
|
79
69
|
{ beforeReady: () => app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required') }
|
|
@@ -93,8 +83,8 @@ Installs dev tools extensions and opens the devTools panel.
|
|
|
93
83
|
### KioskBrowserWindow
|
|
94
84
|
Enables kiosk mode in the BrowserWindow when the application is packaged.
|
|
95
85
|
|
|
96
|
-
###
|
|
97
|
-
Starts a heartbeat, which reports uptime to betteruptime.com. Requires
|
|
86
|
+
### BetterStackHeartbeat
|
|
87
|
+
Starts a heartbeat, which reports uptime to betteruptime.com. Requires `heartbeatApiKey` in options.
|
|
98
88
|
|
|
99
89
|
### PrivilegedSchemes
|
|
100
90
|
Registers schemes as privileged.
|
package/dist/AutoUpdater.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { BrowserWindowInitContext, InitPlugin } from './init';
|
|
2
|
+
/**
|
|
3
|
+
* Options for configuring the AutoUpdater plugin.
|
|
4
|
+
*/
|
|
5
|
+
export interface AutoUpdaterOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The update channel to use (e.g., 'stable', 'beta', 'alpha').
|
|
8
|
+
* This determines which release channel the app will receive updates from.
|
|
9
|
+
*/
|
|
10
|
+
channel?: string;
|
|
11
|
+
}
|
|
2
12
|
/**
|
|
3
13
|
* Starts the auto update process, checking for updates every 3 minutes
|
|
4
14
|
* and automatically installing the update once one is found.
|
|
@@ -7,12 +17,13 @@ import { BrowserWindowInitContext, InitPlugin } from './init';
|
|
|
7
17
|
*/
|
|
8
18
|
export declare class AutoUpdater implements InitPlugin {
|
|
9
19
|
private readonly enabled;
|
|
20
|
+
private readonly options;
|
|
10
21
|
/**
|
|
11
22
|
* @constructor
|
|
12
23
|
*
|
|
13
24
|
* @param enabled - Indicates if the plugin is enabled. Used to disable the plugin in development. Defaults to `app.isPackaged`.
|
|
14
25
|
*/
|
|
15
|
-
constructor(enabled?: boolean);
|
|
16
|
-
afterLoad({
|
|
26
|
+
constructor(enabled?: boolean, options?: AutoUpdaterOptions);
|
|
27
|
+
afterLoad({ log }: BrowserWindowInitContext): Promise<void>;
|
|
17
28
|
private startAutoUpdater;
|
|
18
29
|
}
|
package/dist/AutoUpdater.js
CHANGED
|
@@ -28,17 +28,18 @@ class AutoUpdater {
|
|
|
28
28
|
*
|
|
29
29
|
* @param enabled - Indicates if the plugin is enabled. Used to disable the plugin in development. Defaults to `app.isPackaged`.
|
|
30
30
|
*/
|
|
31
|
-
constructor(enabled = electron_1.app.isPackaged) {
|
|
31
|
+
constructor(enabled = electron_1.app.isPackaged, options = {}) {
|
|
32
32
|
this.enabled = enabled;
|
|
33
|
+
this.options = options;
|
|
33
34
|
}
|
|
34
|
-
afterLoad({
|
|
35
|
+
afterLoad({ log }) {
|
|
35
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
const {
|
|
37
|
-
if (this.enabled &&
|
|
38
|
-
this.startAutoUpdater(
|
|
37
|
+
const { channel } = this.options;
|
|
38
|
+
if (this.enabled && channel) {
|
|
39
|
+
this.startAutoUpdater(channel);
|
|
39
40
|
}
|
|
40
41
|
else if (this.enabled) {
|
|
41
|
-
log.warn('
|
|
42
|
+
log.warn('channel was not set in the passed in options. AutoUpdater was not started.');
|
|
42
43
|
}
|
|
43
44
|
});
|
|
44
45
|
}
|
package/dist/BrowserWindow.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export declare class DefaultBrowserWindow implements InitPlugin {
|
|
|
14
14
|
constructor(options?: BrowserWindowConstructorOptions);
|
|
15
15
|
afterReady(context: InitContext): Promise<void>;
|
|
16
16
|
protected getDefaultWindowOptions(): BrowserWindowConstructorOptions;
|
|
17
|
-
protected getWindowOptionsFromConfig({ appHeight, appWidth, backgroundColor }: Record<string, string | number | boolean>): BrowserWindowConstructorOptions;
|
|
18
17
|
}
|
|
19
18
|
/**
|
|
20
19
|
* Enables kiosk mode in the BrowserWindow when the application is packaged.
|
package/dist/BrowserWindow.js
CHANGED
|
@@ -31,9 +31,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
34
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
38
|
exports.FullScreenBrowserWindow = exports.KioskBrowserWindow = exports.DefaultBrowserWindow = void 0;
|
|
36
39
|
const electron_1 = require("electron");
|
|
40
|
+
const lodash_merge_1 = __importDefault(require("lodash.merge"));
|
|
37
41
|
/**
|
|
38
42
|
* Applies default options to the browser window. If `appHeight`, `appWidth`, or `backgroundColor` are included in
|
|
39
43
|
* app config, they will be added to the window options as well.
|
|
@@ -49,7 +53,7 @@ class DefaultBrowserWindow {
|
|
|
49
53
|
}
|
|
50
54
|
afterReady(context) {
|
|
51
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
context.browserWindowOptions =
|
|
56
|
+
context.browserWindowOptions = (0, lodash_merge_1.default)({}, this.getDefaultWindowOptions(), context.browserWindowOptions, this.options, { closable: true });
|
|
53
57
|
});
|
|
54
58
|
}
|
|
55
59
|
getDefaultWindowOptions() {
|
|
@@ -61,19 +65,6 @@ class DefaultBrowserWindow {
|
|
|
61
65
|
}
|
|
62
66
|
};
|
|
63
67
|
}
|
|
64
|
-
getWindowOptionsFromConfig({ appHeight, appWidth, backgroundColor }) {
|
|
65
|
-
const options = {};
|
|
66
|
-
if (appHeight !== undefined && typeof appHeight === 'number') {
|
|
67
|
-
options.height = appHeight;
|
|
68
|
-
}
|
|
69
|
-
if (appWidth !== undefined && typeof appWidth === 'number') {
|
|
70
|
-
options.width = appWidth;
|
|
71
|
-
}
|
|
72
|
-
if (backgroundColor !== undefined && typeof backgroundColor === 'string') {
|
|
73
|
-
options.backgroundColor = backgroundColor;
|
|
74
|
-
}
|
|
75
|
-
return options;
|
|
76
|
-
}
|
|
77
68
|
}
|
|
78
69
|
exports.DefaultBrowserWindow = DefaultBrowserWindow;
|
|
79
70
|
/**
|
package/dist/NodeHeartbeat.js
CHANGED
|
@@ -57,7 +57,7 @@ class BetterStackHeartbeat {
|
|
|
57
57
|
}
|
|
58
58
|
afterLoad(context) {
|
|
59
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
const heartbeatApiKey =
|
|
60
|
+
const heartbeatApiKey = this.options.heartbeatApiKey;
|
|
61
61
|
if (this.enabled && heartbeatApiKey && typeof heartbeatApiKey === 'string') {
|
|
62
62
|
const url = this.options.isBetterStack
|
|
63
63
|
? `https://uptime.betterstack.com/api/v1/heartbeat/${heartbeatApiKey}`
|
package/dist/init.d.ts
CHANGED
|
@@ -7,10 +7,6 @@ export declare class InitContext {
|
|
|
7
7
|
* The url used to load the application.
|
|
8
8
|
*/
|
|
9
9
|
appUrl: string;
|
|
10
|
-
/**
|
|
11
|
-
* Application config used by the app and/or plugins.
|
|
12
|
-
*/
|
|
13
|
-
config: Record<string, string | number | boolean>;
|
|
14
10
|
/**
|
|
15
11
|
* Options used to create the BrowserWindow. These can be modified in `beforeReady` or
|
|
16
12
|
* `beforeLoad` methods to change the created BrowserWindow.
|
|
@@ -25,10 +21,6 @@ export declare class InitContext {
|
|
|
25
21
|
* The url used to load the application.
|
|
26
22
|
*/
|
|
27
23
|
appUrl: string,
|
|
28
|
-
/**
|
|
29
|
-
* Application config used by the app and/or plugins.
|
|
30
|
-
*/
|
|
31
|
-
config: Record<string, string | number | boolean>,
|
|
32
24
|
/**
|
|
33
25
|
* Options used to create the BrowserWindow. These can be modified in `beforeReady` or
|
|
34
26
|
* `beforeLoad` methods to change the created BrowserWindow.
|
|
@@ -97,10 +89,6 @@ export interface InitOptions {
|
|
|
97
89
|
* The default browser window options
|
|
98
90
|
*/
|
|
99
91
|
browserWindowOptions?: BrowserWindowConstructorOptions;
|
|
100
|
-
/**
|
|
101
|
-
* The default application settings.
|
|
102
|
-
*/
|
|
103
|
-
config?: Record<string, string | number | boolean>;
|
|
104
92
|
/**
|
|
105
93
|
* The list of plugins to load with the application.
|
|
106
94
|
*/
|
|
@@ -112,4 +100,4 @@ export interface InitOptions {
|
|
|
112
100
|
* @param options - Options used to define how the application is initialized.
|
|
113
101
|
* @returns - The final state of the init context, including the created browser window for additional setup.
|
|
114
102
|
*/
|
|
115
|
-
export declare function init({ appUrl, browserWindowOptions,
|
|
103
|
+
export declare function init({ appUrl, browserWindowOptions, plugins, }: InitOptions): Promise<InitContext>;
|
package/dist/init.js
CHANGED
|
@@ -24,10 +24,6 @@ class InitContext {
|
|
|
24
24
|
* The url used to load the application.
|
|
25
25
|
*/
|
|
26
26
|
appUrl,
|
|
27
|
-
/**
|
|
28
|
-
* Application config used by the app and/or plugins.
|
|
29
|
-
*/
|
|
30
|
-
config,
|
|
31
27
|
/**
|
|
32
28
|
* Options used to create the BrowserWindow. These can be modified in `beforeReady` or
|
|
33
29
|
* `beforeLoad` methods to change the created BrowserWindow.
|
|
@@ -38,7 +34,6 @@ class InitContext {
|
|
|
38
34
|
*/
|
|
39
35
|
log) {
|
|
40
36
|
this.appUrl = appUrl;
|
|
41
|
-
this.config = config;
|
|
42
37
|
this.browserWindowOptions = browserWindowOptions;
|
|
43
38
|
this.log = log;
|
|
44
39
|
}
|
|
@@ -50,7 +45,7 @@ exports.InitContext = InitContext;
|
|
|
50
45
|
* @param options - Options used to define how the application is initialized.
|
|
51
46
|
* @returns - The final state of the init context, including the created browser window for additional setup.
|
|
52
47
|
*/
|
|
53
|
-
function init({ appUrl, browserWindowOptions = { height: 1920, width: 1080, backgroundColor: '#000' },
|
|
48
|
+
function init({ appUrl, browserWindowOptions = { height: 1920, width: 1080, backgroundColor: '#000' }, plugins = [], }) {
|
|
54
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
50
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true';
|
|
56
51
|
electron_1.app.on('window-all-closed', electron_1.app.quit);
|
|
@@ -59,7 +54,7 @@ function init({ appUrl, browserWindowOptions = { height: 1920, width: 1080, back
|
|
|
59
54
|
electron_1.app.quit();
|
|
60
55
|
});
|
|
61
56
|
process.on('SIGTERM', electron_1.app.quit);
|
|
62
|
-
const context = new InitContext(appUrl,
|
|
57
|
+
const context = new InitContext(appUrl, browserWindowOptions, electron_log_1.default);
|
|
63
58
|
for (const plugin of plugins) {
|
|
64
59
|
if (plugin.beforeReady) {
|
|
65
60
|
yield plugin.beforeReady(context);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dimensional-innovations/electron-background",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "the background script for electron apps",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -33,9 +33,11 @@
|
|
|
33
33
|
"axios": "^1.6.7",
|
|
34
34
|
"electron-devtools-installer": "^4.0.0",
|
|
35
35
|
"electron-log": "^5.1.1",
|
|
36
|
-
"electron-updater": "^6.1.7"
|
|
36
|
+
"electron-updater": "^6.1.7",
|
|
37
|
+
"lodash.merge": "^4.6.2"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
40
|
+
"@types/lodash.merge": "^4.6.9",
|
|
39
41
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
40
42
|
"@typescript-eslint/parser": "^6.21.0",
|
|
41
43
|
"electron": "^28.2.1",
|