@chromahq/core 0.0.5 → 0.1.1
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/index.cjs.js +56 -9
- package/dist/index.d.ts +8 -2
- package/dist/index.es.js +56 -9
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -55,14 +55,16 @@ class DefaultErrorHandler {
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
class
|
|
58
|
+
const _BridgeRuntimeManager = class _BridgeRuntimeManager {
|
|
59
59
|
constructor(options) {
|
|
60
|
+
this.keepAliveTimer = null;
|
|
60
61
|
this.isInitialized = false;
|
|
61
62
|
this.container = options.container;
|
|
62
63
|
this.portName = options.portName ?? DEFAULT_PORT_NAME;
|
|
63
64
|
this.enableLogging = options.enableLogging ?? true;
|
|
64
65
|
this.errorHandler = options.errorHandler ?? new DefaultErrorHandler();
|
|
65
66
|
this.logger = new BridgeLogger(this.enableLogging);
|
|
67
|
+
this.keepAlive = options.keepAlive ?? false;
|
|
66
68
|
}
|
|
67
69
|
/**
|
|
68
70
|
* Initialize the bridge runtime and start listening for connections
|
|
@@ -73,6 +75,9 @@ class BridgeRuntimeManager {
|
|
|
73
75
|
return;
|
|
74
76
|
}
|
|
75
77
|
this.setupPortListener();
|
|
78
|
+
if (this.keepAlive) {
|
|
79
|
+
this.startKeepAlive();
|
|
80
|
+
}
|
|
76
81
|
this.isInitialized = true;
|
|
77
82
|
this.logger.success(`\u{1F309} Bridge runtime initialized on port: ${this.portName}`);
|
|
78
83
|
}
|
|
@@ -105,7 +110,14 @@ class BridgeRuntimeManager {
|
|
|
105
110
|
*/
|
|
106
111
|
isValidPort(port) {
|
|
107
112
|
if (port.name !== this.portName) {
|
|
108
|
-
this.logger.warn(
|
|
113
|
+
this.logger.warn(`Ignoring port "${port.name}", expected "${this.portName}"`);
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
const senderId = port.sender?.id;
|
|
117
|
+
if (senderId !== chrome.runtime.id) {
|
|
118
|
+
this.logger.warn(
|
|
119
|
+
`Ignoring port from different extension (senderId: ${senderId}, expected: ${chrome.runtime.id})`
|
|
120
|
+
);
|
|
109
121
|
return false;
|
|
110
122
|
}
|
|
111
123
|
return true;
|
|
@@ -250,7 +262,30 @@ class BridgeRuntimeManager {
|
|
|
250
262
|
initialized: this.isInitialized
|
|
251
263
|
};
|
|
252
264
|
}
|
|
253
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Start keep-alive timer to keep service worker alive
|
|
267
|
+
*/
|
|
268
|
+
startKeepAlive() {
|
|
269
|
+
if (this.keepAliveTimer) return;
|
|
270
|
+
this.logger.info("Starting keep-alive timer to keep service worker alive");
|
|
271
|
+
this.keepAliveTimer = setInterval(() => {
|
|
272
|
+
chrome.runtime.getPlatformInfo(() => {
|
|
273
|
+
});
|
|
274
|
+
}, _BridgeRuntimeManager.KEEP_ALIVE_INTERVAL_MS);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Stop keep-alive timer
|
|
278
|
+
*/
|
|
279
|
+
stopKeepAlive() {
|
|
280
|
+
if (this.keepAliveTimer) {
|
|
281
|
+
clearInterval(this.keepAliveTimer);
|
|
282
|
+
this.keepAliveTimer = null;
|
|
283
|
+
this.logger.info("Stopped keep-alive timer");
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
_BridgeRuntimeManager.KEEP_ALIVE_INTERVAL_MS = 25e3;
|
|
288
|
+
let BridgeRuntimeManager = _BridgeRuntimeManager;
|
|
254
289
|
class BridgeLogger {
|
|
255
290
|
constructor(enabled = true) {
|
|
256
291
|
this.enabled = enabled;
|
|
@@ -1156,7 +1191,10 @@ class ApplicationBootstrap {
|
|
|
1156
1191
|
/**
|
|
1157
1192
|
* Create and initialize a new Chroma application instance
|
|
1158
1193
|
*/
|
|
1159
|
-
async create(
|
|
1194
|
+
async create({
|
|
1195
|
+
keepPortAlive = false,
|
|
1196
|
+
portName
|
|
1197
|
+
}) {
|
|
1160
1198
|
try {
|
|
1161
1199
|
this.logger.info("\u{1F680} Starting Chroma application bootstrap...");
|
|
1162
1200
|
await this.discoverServices();
|
|
@@ -1167,7 +1205,7 @@ class ApplicationBootstrap {
|
|
|
1167
1205
|
await this.registerJobs();
|
|
1168
1206
|
await this.bootMessages();
|
|
1169
1207
|
this.logger.success("\u{1F389} Chroma application initialization complete!");
|
|
1170
|
-
bootstrap$1({ container });
|
|
1208
|
+
bootstrap$1({ container, keepAlive: keepPortAlive, portName });
|
|
1171
1209
|
} catch (error) {
|
|
1172
1210
|
this.logger.error("\u{1F4A5} Application bootstrap failed:", error);
|
|
1173
1211
|
throw error;
|
|
@@ -1531,9 +1569,15 @@ class BootstrapLogger {
|
|
|
1531
1569
|
console.log("=".repeat(50));
|
|
1532
1570
|
}
|
|
1533
1571
|
}
|
|
1534
|
-
async function create(
|
|
1572
|
+
async function create({
|
|
1573
|
+
keepPortAlive = false,
|
|
1574
|
+
portName
|
|
1575
|
+
} = {}) {
|
|
1535
1576
|
const bootstrap2 = new ApplicationBootstrap();
|
|
1536
|
-
await bootstrap2.create(
|
|
1577
|
+
await bootstrap2.create({
|
|
1578
|
+
keepPortAlive,
|
|
1579
|
+
portName
|
|
1580
|
+
});
|
|
1537
1581
|
}
|
|
1538
1582
|
function bootstrap() {
|
|
1539
1583
|
return new BootstrapBuilder();
|
|
@@ -1559,8 +1603,11 @@ class BootstrapBuilder {
|
|
|
1559
1603
|
/**
|
|
1560
1604
|
* Create and start the application
|
|
1561
1605
|
*/
|
|
1562
|
-
async create(
|
|
1563
|
-
|
|
1606
|
+
async create({
|
|
1607
|
+
keepPortAlive = false,
|
|
1608
|
+
portName
|
|
1609
|
+
} = {}) {
|
|
1610
|
+
await this.app.create({ keepPortAlive, portName });
|
|
1564
1611
|
}
|
|
1565
1612
|
}
|
|
1566
1613
|
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,10 @@ declare const bind: <T>(id: symbol | (new (...a: any[]) => T), cls: new (...a: a
|
|
|
10
10
|
declare const resolve: <T>(id: symbol | (new (...a: any[]) => T)) => T;
|
|
11
11
|
declare function isInjectable(target: any): boolean;
|
|
12
12
|
|
|
13
|
-
declare function create(
|
|
13
|
+
declare function create({ keepPortAlive, portName, }?: {
|
|
14
|
+
keepPortAlive?: boolean;
|
|
15
|
+
portName?: string;
|
|
16
|
+
}): Promise<void>;
|
|
14
17
|
declare function bootstrap(): BootstrapBuilder;
|
|
15
18
|
declare class BootstrapBuilder {
|
|
16
19
|
private readonly app;
|
|
@@ -25,7 +28,10 @@ declare class BootstrapBuilder {
|
|
|
25
28
|
/**
|
|
26
29
|
* Create and start the application
|
|
27
30
|
*/
|
|
28
|
-
create(
|
|
31
|
+
create({ keepPortAlive, portName, }?: {
|
|
32
|
+
keepPortAlive?: boolean;
|
|
33
|
+
portName?: string;
|
|
34
|
+
}): Promise<void>;
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
declare abstract class IMessage {
|
package/dist/index.es.js
CHANGED
|
@@ -53,14 +53,16 @@ class DefaultErrorHandler {
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
class
|
|
56
|
+
const _BridgeRuntimeManager = class _BridgeRuntimeManager {
|
|
57
57
|
constructor(options) {
|
|
58
|
+
this.keepAliveTimer = null;
|
|
58
59
|
this.isInitialized = false;
|
|
59
60
|
this.container = options.container;
|
|
60
61
|
this.portName = options.portName ?? DEFAULT_PORT_NAME;
|
|
61
62
|
this.enableLogging = options.enableLogging ?? true;
|
|
62
63
|
this.errorHandler = options.errorHandler ?? new DefaultErrorHandler();
|
|
63
64
|
this.logger = new BridgeLogger(this.enableLogging);
|
|
65
|
+
this.keepAlive = options.keepAlive ?? false;
|
|
64
66
|
}
|
|
65
67
|
/**
|
|
66
68
|
* Initialize the bridge runtime and start listening for connections
|
|
@@ -71,6 +73,9 @@ class BridgeRuntimeManager {
|
|
|
71
73
|
return;
|
|
72
74
|
}
|
|
73
75
|
this.setupPortListener();
|
|
76
|
+
if (this.keepAlive) {
|
|
77
|
+
this.startKeepAlive();
|
|
78
|
+
}
|
|
74
79
|
this.isInitialized = true;
|
|
75
80
|
this.logger.success(`\u{1F309} Bridge runtime initialized on port: ${this.portName}`);
|
|
76
81
|
}
|
|
@@ -103,7 +108,14 @@ class BridgeRuntimeManager {
|
|
|
103
108
|
*/
|
|
104
109
|
isValidPort(port) {
|
|
105
110
|
if (port.name !== this.portName) {
|
|
106
|
-
this.logger.warn(
|
|
111
|
+
this.logger.warn(`Ignoring port "${port.name}", expected "${this.portName}"`);
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
const senderId = port.sender?.id;
|
|
115
|
+
if (senderId !== chrome.runtime.id) {
|
|
116
|
+
this.logger.warn(
|
|
117
|
+
`Ignoring port from different extension (senderId: ${senderId}, expected: ${chrome.runtime.id})`
|
|
118
|
+
);
|
|
107
119
|
return false;
|
|
108
120
|
}
|
|
109
121
|
return true;
|
|
@@ -248,7 +260,30 @@ class BridgeRuntimeManager {
|
|
|
248
260
|
initialized: this.isInitialized
|
|
249
261
|
};
|
|
250
262
|
}
|
|
251
|
-
|
|
263
|
+
/**
|
|
264
|
+
* Start keep-alive timer to keep service worker alive
|
|
265
|
+
*/
|
|
266
|
+
startKeepAlive() {
|
|
267
|
+
if (this.keepAliveTimer) return;
|
|
268
|
+
this.logger.info("Starting keep-alive timer to keep service worker alive");
|
|
269
|
+
this.keepAliveTimer = setInterval(() => {
|
|
270
|
+
chrome.runtime.getPlatformInfo(() => {
|
|
271
|
+
});
|
|
272
|
+
}, _BridgeRuntimeManager.KEEP_ALIVE_INTERVAL_MS);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Stop keep-alive timer
|
|
276
|
+
*/
|
|
277
|
+
stopKeepAlive() {
|
|
278
|
+
if (this.keepAliveTimer) {
|
|
279
|
+
clearInterval(this.keepAliveTimer);
|
|
280
|
+
this.keepAliveTimer = null;
|
|
281
|
+
this.logger.info("Stopped keep-alive timer");
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
_BridgeRuntimeManager.KEEP_ALIVE_INTERVAL_MS = 25e3;
|
|
286
|
+
let BridgeRuntimeManager = _BridgeRuntimeManager;
|
|
252
287
|
class BridgeLogger {
|
|
253
288
|
constructor(enabled = true) {
|
|
254
289
|
this.enabled = enabled;
|
|
@@ -1154,7 +1189,10 @@ class ApplicationBootstrap {
|
|
|
1154
1189
|
/**
|
|
1155
1190
|
* Create and initialize a new Chroma application instance
|
|
1156
1191
|
*/
|
|
1157
|
-
async create(
|
|
1192
|
+
async create({
|
|
1193
|
+
keepPortAlive = false,
|
|
1194
|
+
portName
|
|
1195
|
+
}) {
|
|
1158
1196
|
try {
|
|
1159
1197
|
this.logger.info("\u{1F680} Starting Chroma application bootstrap...");
|
|
1160
1198
|
await this.discoverServices();
|
|
@@ -1165,7 +1203,7 @@ class ApplicationBootstrap {
|
|
|
1165
1203
|
await this.registerJobs();
|
|
1166
1204
|
await this.bootMessages();
|
|
1167
1205
|
this.logger.success("\u{1F389} Chroma application initialization complete!");
|
|
1168
|
-
bootstrap$1({ container });
|
|
1206
|
+
bootstrap$1({ container, keepAlive: keepPortAlive, portName });
|
|
1169
1207
|
} catch (error) {
|
|
1170
1208
|
this.logger.error("\u{1F4A5} Application bootstrap failed:", error);
|
|
1171
1209
|
throw error;
|
|
@@ -1529,9 +1567,15 @@ class BootstrapLogger {
|
|
|
1529
1567
|
console.log("=".repeat(50));
|
|
1530
1568
|
}
|
|
1531
1569
|
}
|
|
1532
|
-
async function create(
|
|
1570
|
+
async function create({
|
|
1571
|
+
keepPortAlive = false,
|
|
1572
|
+
portName
|
|
1573
|
+
} = {}) {
|
|
1533
1574
|
const bootstrap2 = new ApplicationBootstrap();
|
|
1534
|
-
await bootstrap2.create(
|
|
1575
|
+
await bootstrap2.create({
|
|
1576
|
+
keepPortAlive,
|
|
1577
|
+
portName
|
|
1578
|
+
});
|
|
1535
1579
|
}
|
|
1536
1580
|
function bootstrap() {
|
|
1537
1581
|
return new BootstrapBuilder();
|
|
@@ -1557,8 +1601,11 @@ class BootstrapBuilder {
|
|
|
1557
1601
|
/**
|
|
1558
1602
|
* Create and start the application
|
|
1559
1603
|
*/
|
|
1560
|
-
async create(
|
|
1561
|
-
|
|
1604
|
+
async create({
|
|
1605
|
+
keepPortAlive = false,
|
|
1606
|
+
portName
|
|
1607
|
+
} = {}) {
|
|
1608
|
+
await this.app.create({ keepPortAlive, portName });
|
|
1562
1609
|
}
|
|
1563
1610
|
}
|
|
1564
1611
|
|