@chromahq/core 0.0.4 → 0.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/dist/index.cjs.js +46 -8
- package/dist/index.es.js +46 -8
- 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;
|
|
@@ -1179,7 +1217,7 @@ class ApplicationBootstrap {
|
|
|
1179
1217
|
async discoverServices() {
|
|
1180
1218
|
this.logger.info("\u{1F50D} Discovering services...");
|
|
1181
1219
|
const serviceModules = undefined(
|
|
1182
|
-
"/src/app/services
|
|
1220
|
+
"/src/app/services/**/*.service.{ts,js}",
|
|
1183
1221
|
{ eager: true }
|
|
1184
1222
|
);
|
|
1185
1223
|
for (const module of Object.values(serviceModules)) {
|
|
@@ -1422,7 +1460,7 @@ class ApplicationBootstrap {
|
|
|
1422
1460
|
async registerMessages() {
|
|
1423
1461
|
this.logger.info("\u{1F4E8} Registering messages...");
|
|
1424
1462
|
const messageModules = undefined(
|
|
1425
|
-
"/src/app/messages
|
|
1463
|
+
"/src/app/messages/**/*.message.{ts,js}",
|
|
1426
1464
|
{ eager: true }
|
|
1427
1465
|
);
|
|
1428
1466
|
for (const module of Object.values(messageModules)) {
|
|
@@ -1458,7 +1496,7 @@ class ApplicationBootstrap {
|
|
|
1458
1496
|
async bootMessages() {
|
|
1459
1497
|
this.logger.info("\u{1F680} Booting messages...");
|
|
1460
1498
|
const messageModules = undefined(
|
|
1461
|
-
"/src/app/messages
|
|
1499
|
+
"/src/app/messages/**/*.message.{ts,js}",
|
|
1462
1500
|
{ eager: true }
|
|
1463
1501
|
);
|
|
1464
1502
|
for (const module of Object.values(messageModules)) {
|
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;
|
|
@@ -1177,7 +1215,7 @@ class ApplicationBootstrap {
|
|
|
1177
1215
|
async discoverServices() {
|
|
1178
1216
|
this.logger.info("\u{1F50D} Discovering services...");
|
|
1179
1217
|
const serviceModules = import.meta.glob(
|
|
1180
|
-
"/src/app/services
|
|
1218
|
+
"/src/app/services/**/*.service.{ts,js}",
|
|
1181
1219
|
{ eager: true }
|
|
1182
1220
|
);
|
|
1183
1221
|
for (const module of Object.values(serviceModules)) {
|
|
@@ -1420,7 +1458,7 @@ class ApplicationBootstrap {
|
|
|
1420
1458
|
async registerMessages() {
|
|
1421
1459
|
this.logger.info("\u{1F4E8} Registering messages...");
|
|
1422
1460
|
const messageModules = import.meta.glob(
|
|
1423
|
-
"/src/app/messages
|
|
1461
|
+
"/src/app/messages/**/*.message.{ts,js}",
|
|
1424
1462
|
{ eager: true }
|
|
1425
1463
|
);
|
|
1426
1464
|
for (const module of Object.values(messageModules)) {
|
|
@@ -1456,7 +1494,7 @@ class ApplicationBootstrap {
|
|
|
1456
1494
|
async bootMessages() {
|
|
1457
1495
|
this.logger.info("\u{1F680} Booting messages...");
|
|
1458
1496
|
const messageModules = import.meta.glob(
|
|
1459
|
-
"/src/app/messages
|
|
1497
|
+
"/src/app/messages/**/*.message.{ts,js}",
|
|
1460
1498
|
{ eager: true }
|
|
1461
1499
|
);
|
|
1462
1500
|
for (const module of Object.values(messageModules)) {
|