@dimensional-innovations/electron-background 2.0.9 → 2.2.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 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, VueElectronSettings, init, KioskBrowserWindow, PrivilegedSchemes, StaticFileDir, TouchEvents, VueElectronVersion } from '@dimensional-innovations/electron-background';
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, VueElectronSettings, init, KioskBrowserWindow, PrivilegedSchemes, TouchEvents, VueElectronVersion } from '@dimensional-innovations/electron-background';
45
- import { app } from 'electron';
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/vue-electron-background';
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') }
@@ -82,6 +72,20 @@ init({
82
72
  });
83
73
  ```
84
74
 
75
+ ### AutoStart
76
+ Registers the application as a login item so it launches automatically at system startup. On Windows, boot-initiated launches are detected via a `--autostart` argument, allowing an optional delay before window creation. On macOS/Linux the delay is skipped since boot detection is not reliable.
77
+
78
+ ```typescript
79
+ // Default: 30-second delay on boot launches
80
+ new AutoStart()
81
+
82
+ // Custom delay (in seconds)
83
+ new AutoStart(true, { startupDelay: 60 })
84
+
85
+ // No delay on boot launches
86
+ new AutoStart(true, { startupDelay: 0 })
87
+ ```
88
+
85
89
  ### AutoUpdater
86
90
  Starts the auto update process, checking for updates every 3 minutes and automatically installing the update once one is found.
87
91
 
@@ -93,8 +97,8 @@ Installs dev tools extensions and opens the devTools panel.
93
97
  ### KioskBrowserWindow
94
98
  Enables kiosk mode in the BrowserWindow when the application is packaged.
95
99
 
96
- ### BetterUptimeHeartbeat
97
- Starts a heartbeat, which reports uptime to betteruptime.com. Requires that "heartbeatApiKey" is set in the settings.
100
+ ### BetterStackHeartbeat
101
+ Starts a heartbeat, which reports uptime to betteruptime.com. Requires `heartbeatApiKey` in options.
98
102
 
99
103
  ### PrivilegedSchemes
100
104
  Registers schemes as privileged.
@@ -0,0 +1,25 @@
1
+ import { InitPlugin, NonBrowserWindowInitContext } from './init';
2
+ export interface AutoStartOptions {
3
+ /** Delay in seconds before window creation on boot launches (0 = no delay). Default: 30 */
4
+ startupDelay?: number;
5
+ }
6
+ /**
7
+ * Registers the application as a login item for automatic startup and optionally
8
+ * delays window creation. The delay only applies when the app was auto-started at
9
+ * system boot (detected via the `--autostart` process argument on Windows).
10
+ *
11
+ * On macOS/Linux, boot detection is not reliably possible, so the delay is always
12
+ * skipped — the app launches instantly regardless of how it was started.
13
+ */
14
+ export declare class AutoStart implements InitPlugin {
15
+ private readonly enabled;
16
+ private readonly startupDelay;
17
+ /**
18
+ * @param enabled - Whether auto-start is active. Defaults to `app.isPackaged`.
19
+ * @param options - Configuration options for startup behavior.
20
+ */
21
+ constructor(enabled?: boolean, options?: AutoStartOptions);
22
+ /** Returns true when the app was launched by the OS login item (Windows only). */
23
+ private isAutoStartLaunch;
24
+ afterReady(context: NonBrowserWindowInitContext): Promise<void>;
25
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AutoStart = void 0;
13
+ const electron_1 = require("electron");
14
+ /** Argument passed to the login item so boot launches can be detected. */
15
+ const AUTOSTART_ARG = '--autostart';
16
+ /**
17
+ * Registers the application as a login item for automatic startup and optionally
18
+ * delays window creation. The delay only applies when the app was auto-started at
19
+ * system boot (detected via the `--autostart` process argument on Windows).
20
+ *
21
+ * On macOS/Linux, boot detection is not reliably possible, so the delay is always
22
+ * skipped — the app launches instantly regardless of how it was started.
23
+ */
24
+ class AutoStart {
25
+ /**
26
+ * @param enabled - Whether auto-start is active. Defaults to `app.isPackaged`.
27
+ * @param options - Configuration options for startup behavior.
28
+ */
29
+ constructor(enabled, options = {}) {
30
+ var _a;
31
+ this.enabled = enabled !== null && enabled !== void 0 ? enabled : electron_1.app.isPackaged;
32
+ this.startupDelay = (_a = options.startupDelay) !== null && _a !== void 0 ? _a : 30;
33
+ }
34
+ /** Returns true when the app was launched by the OS login item (Windows only). */
35
+ isAutoStartLaunch() {
36
+ return process.platform === 'win32' && process.argv.includes(AUTOSTART_ARG);
37
+ }
38
+ afterReady(context) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ if (!this.enabled) {
41
+ context.log.info('[AutoStart] Disabled (not packaged)');
42
+ return;
43
+ }
44
+ // On Windows, include the autostart arg so boot launches can be distinguished
45
+ // from manual launches. On other platforms, no args needed.
46
+ try {
47
+ if (process.platform === 'win32') {
48
+ electron_1.app.setLoginItemSettings({ openAtLogin: true, args: [AUTOSTART_ARG] });
49
+ }
50
+ else {
51
+ electron_1.app.setLoginItemSettings({ openAtLogin: true });
52
+ }
53
+ context.log.info('[AutoStart] Registered as login item');
54
+ }
55
+ catch (err) {
56
+ context.log.error('[AutoStart] Failed to register login item:', err);
57
+ }
58
+ if (this.startupDelay > 0 && this.isAutoStartLaunch()) {
59
+ context.log.info(`[AutoStart] Boot launch detected — delaying ${this.startupDelay}s before window creation`);
60
+ yield new Promise(resolve => {
61
+ setTimeout(resolve, this.startupDelay * 1000);
62
+ });
63
+ }
64
+ else if (this.startupDelay > 0) {
65
+ context.log.info('[AutoStart] Manual launch — skipping startup delay');
66
+ }
67
+ });
68
+ }
69
+ }
70
+ exports.AutoStart = AutoStart;
@@ -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({ config, log }: BrowserWindowInitContext): Promise<void>;
26
+ constructor(enabled?: boolean, options?: AutoUpdaterOptions);
27
+ afterLoad({ log }: BrowserWindowInitContext): Promise<void>;
17
28
  private startAutoUpdater;
18
29
  }
@@ -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({ config, log }) {
35
+ afterLoad({ log }) {
35
36
  return __awaiter(this, void 0, void 0, function* () {
36
- const { autoUpdaterChannel } = config;
37
- if (this.enabled && autoUpdaterChannel) {
38
- this.startAutoUpdater(autoUpdaterChannel);
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('autoUpdaterChannel was not set in the settings. AutoUpdater was not started.');
42
+ log.warn('channel was not set in the passed in options. AutoUpdater was not started.');
42
43
  }
43
44
  });
44
45
  }
@@ -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.
@@ -53,7 +53,7 @@ class DefaultBrowserWindow {
53
53
  }
54
54
  afterReady(context) {
55
55
  return __awaiter(this, void 0, void 0, function* () {
56
- context.browserWindowOptions = (0, lodash_merge_1.default)({}, this.getDefaultWindowOptions(), this.getWindowOptionsFromConfig(context.config), context.browserWindowOptions, this.options, { closable: true });
56
+ context.browserWindowOptions = (0, lodash_merge_1.default)({}, this.getDefaultWindowOptions(), context.browserWindowOptions, this.options, { closable: true });
57
57
  });
58
58
  }
59
59
  getDefaultWindowOptions() {
@@ -65,19 +65,6 @@ class DefaultBrowserWindow {
65
65
  }
66
66
  };
67
67
  }
68
- getWindowOptionsFromConfig({ appHeight, appWidth, backgroundColor }) {
69
- const options = {};
70
- if (appHeight !== undefined && typeof appHeight === 'number') {
71
- options.height = appHeight;
72
- }
73
- if (appWidth !== undefined && typeof appWidth === 'number') {
74
- options.width = appWidth;
75
- }
76
- if (backgroundColor !== undefined && typeof backgroundColor === 'string') {
77
- options.backgroundColor = backgroundColor;
78
- }
79
- return options;
80
- }
81
68
  }
82
69
  exports.DefaultBrowserWindow = DefaultBrowserWindow;
83
70
  /**
@@ -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 = context.config.heartbeatApiKey || this.options.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/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './AutoStart';
1
2
  export * from './AutoUpdater';
2
3
  export * from './BrowserWindow';
3
4
  export * from './DevTools';
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ 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("./AutoStart"), exports);
17
18
  __exportStar(require("./AutoUpdater"), exports);
18
19
  __exportStar(require("./BrowserWindow"), exports);
19
20
  __exportStar(require("./DevTools"), exports);
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, config, plugins, }: InitOptions): Promise<InitContext>;
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' }, config = {}, plugins = [], }) {
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, config, browserWindowOptions, electron_log_1.default);
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.9",
3
+ "version": "2.2.0",
4
4
  "description": "the background script for electron apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",