@dimensional-innovations/electron-background 2.2.1 → 2.2.3
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/dist/AutoStart.d.ts +6 -4
- package/dist/AutoStart.js +6 -4
- package/dist/init.js +30 -19
- package/package.json +1 -1
package/dist/AutoStart.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { BrowserWindowInitContext,
|
|
1
|
+
import { BrowserWindowInitContext, NonBrowserWindowInitContext, InitPlugin } from './init';
|
|
2
2
|
export interface AutoStartOptions {
|
|
3
3
|
/** Delay in seconds before initialization on boot launches (0 = no delay). Default: 30 */
|
|
4
4
|
startupDelay?: number;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* Registers the application as a login item for automatic startup and optionally
|
|
8
|
-
* delays
|
|
9
|
-
*
|
|
8
|
+
* delays window creation on boot. The delay runs in `afterReady` — before the
|
|
9
|
+
* BrowserWindow is created — giving the GPU and display time to initialize after
|
|
10
|
+
* a system reboot. The delay only applies when the app was auto-started at system
|
|
11
|
+
* boot (detected via the `--autostart` process argument on Windows).
|
|
10
12
|
*
|
|
11
13
|
* On macOS/Linux, boot detection is not reliably possible, so the delay is always
|
|
12
14
|
* skipped — the app launches instantly regardless of how it was started.
|
|
@@ -21,6 +23,6 @@ export declare class AutoStart implements InitPlugin {
|
|
|
21
23
|
constructor(enabled?: boolean, options?: AutoStartOptions);
|
|
22
24
|
/** Returns true when the app was launched by the OS login item (Windows only). */
|
|
23
25
|
private isAutoStartLaunch;
|
|
24
|
-
|
|
26
|
+
afterReady(context: NonBrowserWindowInitContext): Promise<void>;
|
|
25
27
|
afterLoad(context: BrowserWindowInitContext): Promise<void>;
|
|
26
28
|
}
|
package/dist/AutoStart.js
CHANGED
|
@@ -15,8 +15,10 @@ const electron_1 = require("electron");
|
|
|
15
15
|
const AUTOSTART_ARG = '--autostart';
|
|
16
16
|
/**
|
|
17
17
|
* Registers the application as a login item for automatic startup and optionally
|
|
18
|
-
* delays
|
|
19
|
-
*
|
|
18
|
+
* delays window creation on boot. The delay runs in `afterReady` — before the
|
|
19
|
+
* BrowserWindow is created — giving the GPU and display time to initialize after
|
|
20
|
+
* a system reboot. The delay only applies when the app was auto-started at system
|
|
21
|
+
* boot (detected via the `--autostart` process argument on Windows).
|
|
20
22
|
*
|
|
21
23
|
* On macOS/Linux, boot detection is not reliably possible, so the delay is always
|
|
22
24
|
* skipped — the app launches instantly regardless of how it was started.
|
|
@@ -35,12 +37,12 @@ class AutoStart {
|
|
|
35
37
|
isAutoStartLaunch() {
|
|
36
38
|
return process.platform === 'win32' && process.argv.includes(AUTOSTART_ARG);
|
|
37
39
|
}
|
|
38
|
-
|
|
40
|
+
afterReady(context) {
|
|
39
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
42
|
if (!this.enabled)
|
|
41
43
|
return;
|
|
42
44
|
if (this.startupDelay > 0 && this.isAutoStartLaunch()) {
|
|
43
|
-
context.log.info(`[AutoStart] Boot launch detected — delaying ${this.startupDelay}s before
|
|
45
|
+
context.log.info(`[AutoStart] Boot launch detected — delaying ${this.startupDelay}s before window creation`);
|
|
44
46
|
yield new Promise(resolve => setTimeout(resolve, this.startupDelay * 1000));
|
|
45
47
|
}
|
|
46
48
|
else if (this.startupDelay > 0) {
|
package/dist/init.js
CHANGED
|
@@ -39,6 +39,25 @@ class InitContext {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
exports.InitContext = InitContext;
|
|
42
|
+
function getPluginName(plugin) {
|
|
43
|
+
var _a;
|
|
44
|
+
return ((_a = plugin.constructor) === null || _a === void 0 ? void 0 : _a.name) || 'UnknownPlugin';
|
|
45
|
+
}
|
|
46
|
+
function runPluginPhase(plugins, phase, context, logger) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
for (const plugin of plugins) {
|
|
49
|
+
const method = plugin[phase];
|
|
50
|
+
if (method) {
|
|
51
|
+
try {
|
|
52
|
+
yield method.call(plugin, context);
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
logger.error(`[init] Plugin "${getPluginName(plugin)}" threw during ${phase}:`, err);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
42
61
|
/**
|
|
43
62
|
* Initializes the application, creating a browser window, and loads the provided app url.
|
|
44
63
|
*
|
|
@@ -55,29 +74,21 @@ function init({ appUrl, browserWindowOptions = { height: 1920, width: 1080, back
|
|
|
55
74
|
});
|
|
56
75
|
process.on('SIGTERM', electron_1.app.quit);
|
|
57
76
|
const context = new InitContext(appUrl, browserWindowOptions, electron_log_1.default);
|
|
58
|
-
|
|
59
|
-
if (plugin.beforeReady) {
|
|
60
|
-
yield plugin.beforeReady(context);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
77
|
+
yield runPluginPhase(plugins, 'beforeReady', context, electron_log_1.default);
|
|
63
78
|
yield electron_1.app.whenReady();
|
|
64
|
-
|
|
65
|
-
if (plugin.afterReady) {
|
|
66
|
-
yield plugin.afterReady(context);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
79
|
+
yield runPluginPhase(plugins, 'afterReady', context, electron_log_1.default);
|
|
69
80
|
context.browserWindow = new electron_1.BrowserWindow(context.browserWindowOptions);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
81
|
+
yield runPluginPhase(plugins, 'beforeLoad', context, electron_log_1.default);
|
|
82
|
+
try {
|
|
83
|
+
yield context.browserWindow.loadURL(context.appUrl);
|
|
74
84
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
catch (err) {
|
|
86
|
+
electron_log_1.default.error('[init] Failed to load app URL:', err);
|
|
87
|
+
}
|
|
88
|
+
if (context.browserWindow && !context.browserWindow.isDestroyed() && !context.browserWindow.isVisible()) {
|
|
89
|
+
context.browserWindow.show();
|
|
80
90
|
}
|
|
91
|
+
yield runPluginPhase(plugins, 'afterLoad', context, electron_log_1.default);
|
|
81
92
|
context.browserWindow.on('closed', () => context.browserWindow = undefined);
|
|
82
93
|
return context;
|
|
83
94
|
});
|