@chromahq/core 1.0.52 → 1.0.53
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/{boot-B33Lf5tn.js → boot-CscXvoFf.js} +149 -3
- package/dist/boot-CscXvoFf.js.map +1 -0
- package/dist/{boot-DmW_OC5R.js → boot-DrOND1Zi.js} +148 -4
- package/dist/boot-DrOND1Zi.js.map +1 -0
- package/dist/boot.cjs.js +1 -1
- package/dist/boot.es.js +1 -1
- package/dist/index.cjs.js +18 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +162 -8
- package/dist/index.es.js +16 -4
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
- package/dist/boot-B33Lf5tn.js.map +0 -1
- package/dist/boot-DmW_OC5R.js.map +0 -1
|
@@ -263,6 +263,139 @@ function getNonceService() {
|
|
|
263
263
|
return nonceServiceInstance;
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
+
const _PopupVisibilityService = class _PopupVisibilityService {
|
|
267
|
+
/**
|
|
268
|
+
* Private constructor - use PopupVisibilityService.instance instead.
|
|
269
|
+
*/
|
|
270
|
+
constructor() {
|
|
271
|
+
/** Number of currently connected ports (popup views) */
|
|
272
|
+
this.connectedPortCount = 0;
|
|
273
|
+
/** Listeners for visibility changes */
|
|
274
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
275
|
+
/** Timestamp of last visibility change */
|
|
276
|
+
this.lastVisibilityChangeAt = 0;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Get the singleton instance of the service.
|
|
280
|
+
*/
|
|
281
|
+
static get instance() {
|
|
282
|
+
if (!_PopupVisibilityService._instance) {
|
|
283
|
+
_PopupVisibilityService._instance = new _PopupVisibilityService();
|
|
284
|
+
}
|
|
285
|
+
return _PopupVisibilityService._instance;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Reset the singleton instance (primarily for testing).
|
|
289
|
+
* @internal
|
|
290
|
+
*/
|
|
291
|
+
static resetInstance() {
|
|
292
|
+
if (_PopupVisibilityService._instance) {
|
|
293
|
+
_PopupVisibilityService._instance.listeners.clear();
|
|
294
|
+
}
|
|
295
|
+
_PopupVisibilityService._instance = null;
|
|
296
|
+
}
|
|
297
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
298
|
+
// Public API
|
|
299
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
300
|
+
/**
|
|
301
|
+
* Check if the popup (or any extension view) is currently visible.
|
|
302
|
+
*
|
|
303
|
+
* @returns true if at least one port is connected (popup is open)
|
|
304
|
+
*/
|
|
305
|
+
isPopupVisible() {
|
|
306
|
+
return this.connectedPortCount > 0;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Get the number of connected ports.
|
|
310
|
+
*
|
|
311
|
+
* @returns The current count of connected extension views
|
|
312
|
+
*/
|
|
313
|
+
getConnectedPortCount() {
|
|
314
|
+
return this.connectedPortCount;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Get the timestamp of the last visibility change.
|
|
318
|
+
*
|
|
319
|
+
* @returns Unix timestamp in milliseconds, or 0 if never changed
|
|
320
|
+
*/
|
|
321
|
+
getLastVisibilityChangeAt() {
|
|
322
|
+
return this.lastVisibilityChangeAt;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Register a callback to be notified when visibility changes.
|
|
326
|
+
*
|
|
327
|
+
* @param callback - Function to call when visibility changes
|
|
328
|
+
* @returns Unsubscribe function to remove the listener
|
|
329
|
+
*/
|
|
330
|
+
onVisibilityChange(callback) {
|
|
331
|
+
this.listeners.add(callback);
|
|
332
|
+
return () => {
|
|
333
|
+
this.listeners.delete(callback);
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
337
|
+
// Internal API (called by BridgeRuntime)
|
|
338
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
339
|
+
/**
|
|
340
|
+
* Called when a port connects (popup opens).
|
|
341
|
+
* @internal
|
|
342
|
+
*/
|
|
343
|
+
onPortConnected() {
|
|
344
|
+
const wasVisible = this.isPopupVisible();
|
|
345
|
+
this.connectedPortCount++;
|
|
346
|
+
if (!wasVisible && this.isPopupVisible()) {
|
|
347
|
+
this.lastVisibilityChangeAt = Date.now();
|
|
348
|
+
this.notifyListeners(true);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Called when a port disconnects (popup closes).
|
|
353
|
+
* @internal
|
|
354
|
+
*/
|
|
355
|
+
onPortDisconnected() {
|
|
356
|
+
const wasVisible = this.isPopupVisible();
|
|
357
|
+
this.connectedPortCount = Math.max(0, this.connectedPortCount - 1);
|
|
358
|
+
if (wasVisible && !this.isPopupVisible()) {
|
|
359
|
+
this.lastVisibilityChangeAt = Date.now();
|
|
360
|
+
this.notifyListeners(false);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Sync the port count with the actual connected ports set.
|
|
365
|
+
* Called by BridgeRuntime to ensure consistency.
|
|
366
|
+
* @internal
|
|
367
|
+
*/
|
|
368
|
+
syncPortCount(count) {
|
|
369
|
+
const wasVisible = this.isPopupVisible();
|
|
370
|
+
this.connectedPortCount = count;
|
|
371
|
+
const isNowVisible = this.isPopupVisible();
|
|
372
|
+
if (wasVisible !== isNowVisible) {
|
|
373
|
+
this.lastVisibilityChangeAt = Date.now();
|
|
374
|
+
this.notifyListeners(isNowVisible);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
378
|
+
// Private Methods
|
|
379
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
380
|
+
/**
|
|
381
|
+
* Notify all registered listeners of a visibility change.
|
|
382
|
+
*/
|
|
383
|
+
notifyListeners(isVisible) {
|
|
384
|
+
this.listeners.forEach((callback) => {
|
|
385
|
+
try {
|
|
386
|
+
callback(isVisible);
|
|
387
|
+
} catch (error) {
|
|
388
|
+
console.error("[PopupVisibilityService] Listener error:", error);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
_PopupVisibilityService._instance = null;
|
|
394
|
+
let PopupVisibilityService = _PopupVisibilityService;
|
|
395
|
+
function getPopupVisibilityService() {
|
|
396
|
+
return PopupVisibilityService.instance;
|
|
397
|
+
}
|
|
398
|
+
|
|
266
399
|
const DEFAULT_PORT_NAME$1 = "chroma-bridge";
|
|
267
400
|
const earlyPorts = [];
|
|
268
401
|
let listenerSetup = false;
|
|
@@ -517,6 +650,7 @@ const _BridgeRuntimeManager = class _BridgeRuntimeManager {
|
|
|
517
650
|
*/
|
|
518
651
|
setupMessageHandler(port) {
|
|
519
652
|
this.connectedPorts.add(port);
|
|
653
|
+
PopupVisibilityService.instance.onPortConnected();
|
|
520
654
|
if (this.keepAlive && this.connectedPorts.size === 1) {
|
|
521
655
|
this.startKeepAlive();
|
|
522
656
|
}
|
|
@@ -552,6 +686,7 @@ const _BridgeRuntimeManager = class _BridgeRuntimeManager {
|
|
|
552
686
|
});
|
|
553
687
|
port.onDisconnect.addListener(() => {
|
|
554
688
|
this.connectedPorts.delete(port);
|
|
689
|
+
PopupVisibilityService.instance.onPortDisconnected();
|
|
555
690
|
const runtimeErrorMessage = chrome.runtime.lastError?.message;
|
|
556
691
|
if (runtimeErrorMessage) {
|
|
557
692
|
this.logger.warn(`\u{1F4F4} Port disconnected with error: ${runtimeErrorMessage}`);
|
|
@@ -1886,6 +2021,7 @@ class Scheduler {
|
|
|
1886
2021
|
async execute(id) {
|
|
1887
2022
|
const job = this.registry.resolve(id);
|
|
1888
2023
|
const context = this.registry.getContext(id);
|
|
2024
|
+
const options = this.registry.meta(id);
|
|
1889
2025
|
if (!job || !context) {
|
|
1890
2026
|
this.logger.debug(`Job ${id} not found or no context`);
|
|
1891
2027
|
return;
|
|
@@ -1894,6 +2030,16 @@ class Scheduler {
|
|
|
1894
2030
|
this.logger.debug(`Job ${id} is paused or stopped, skipping execution`);
|
|
1895
2031
|
return;
|
|
1896
2032
|
}
|
|
2033
|
+
if (options?.requiresPopup) {
|
|
2034
|
+
const isPopupVisible = PopupVisibilityService.instance.isPopupVisible();
|
|
2035
|
+
if (!isPopupVisible) {
|
|
2036
|
+
this.logger.debug(`Job ${id} requires popup but popup is not visible, skipping`);
|
|
2037
|
+
if (options?.cron || options?.recurring) {
|
|
2038
|
+
this.schedule(id, options);
|
|
2039
|
+
}
|
|
2040
|
+
return;
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
1897
2043
|
try {
|
|
1898
2044
|
this.registry.updateState(id, JobState.RUNNING);
|
|
1899
2045
|
this.logger.info(`Executing job ${id}`);
|
|
@@ -1902,7 +2048,6 @@ class Scheduler {
|
|
|
1902
2048
|
await jobInstance.handle.bind(jobInstance).call(jobInstance, context);
|
|
1903
2049
|
if (!context.isStopped() && !context.isPaused()) {
|
|
1904
2050
|
this.registry.updateState(id, JobState.COMPLETED);
|
|
1905
|
-
const options = this.registry.meta(id);
|
|
1906
2051
|
if (options?.cron || options?.recurring) {
|
|
1907
2052
|
this.registry.updateState(id, JobState.SCHEDULED);
|
|
1908
2053
|
this.schedule(id, options);
|
|
@@ -1911,7 +2056,6 @@ class Scheduler {
|
|
|
1911
2056
|
} catch (error) {
|
|
1912
2057
|
this.logger.error(`Job ${id} execution failed:`, error);
|
|
1913
2058
|
context.fail(error);
|
|
1914
|
-
const options = this.registry.meta(id);
|
|
1915
2059
|
if (options?.cron || options?.recurring) {
|
|
1916
2060
|
this.logger.info(`Rescheduling failed recurring job ${id}`);
|
|
1917
2061
|
this.registry.updateState(id, JobState.SCHEDULED);
|
|
@@ -2489,6 +2633,7 @@ class BootstrapBuilder {
|
|
|
2489
2633
|
exports.JobRegistry = JobRegistry;
|
|
2490
2634
|
exports.JobState = JobState;
|
|
2491
2635
|
exports.NonceService = NonceService;
|
|
2636
|
+
exports.PopupVisibilityService = PopupVisibilityService;
|
|
2492
2637
|
exports.Scheduler = Scheduler;
|
|
2493
2638
|
exports.arePortsClaimed = arePortsClaimed;
|
|
2494
2639
|
exports.bootstrap = bootstrap;
|
|
@@ -2496,6 +2641,7 @@ exports.claimEarlyPorts = claimEarlyPorts;
|
|
|
2496
2641
|
exports.container = container;
|
|
2497
2642
|
exports.create = create;
|
|
2498
2643
|
exports.getNonceService = getNonceService;
|
|
2644
|
+
exports.getPopupVisibilityService = getPopupVisibilityService;
|
|
2499
2645
|
exports.isEarlyListenerSetup = isEarlyListenerSetup;
|
|
2500
2646
|
exports.setupEarlyListener = setupEarlyListener;
|
|
2501
|
-
//# sourceMappingURL=boot-
|
|
2647
|
+
//# sourceMappingURL=boot-CscXvoFf.js.map
|