@chromahq/core 1.0.53 → 1.0.55

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.
@@ -341,8 +341,10 @@ const _PopupVisibilityService = class _PopupVisibilityService {
341
341
  onPortConnected() {
342
342
  const wasVisible = this.isPopupVisible();
343
343
  this.connectedPortCount++;
344
+ console.log(`[PopupVisibilityService] Port connected, count: ${this.connectedPortCount}`);
344
345
  if (!wasVisible && this.isPopupVisible()) {
345
346
  this.lastVisibilityChangeAt = Date.now();
347
+ console.log("[PopupVisibilityService] Popup became visible, notifying listeners");
346
348
  this.notifyListeners(true);
347
349
  }
348
350
  }
@@ -353,8 +355,10 @@ const _PopupVisibilityService = class _PopupVisibilityService {
353
355
  onPortDisconnected() {
354
356
  const wasVisible = this.isPopupVisible();
355
357
  this.connectedPortCount = Math.max(0, this.connectedPortCount - 1);
358
+ console.log(`[PopupVisibilityService] Port disconnected, count: ${this.connectedPortCount}`);
356
359
  if (wasVisible && !this.isPopupVisible()) {
357
360
  this.lastVisibilityChangeAt = Date.now();
361
+ console.log("[PopupVisibilityService] Popup became hidden, notifying listeners");
358
362
  this.notifyListeners(false);
359
363
  }
360
364
  }
@@ -1307,7 +1311,7 @@ class JobRegistry {
1307
1311
  }
1308
1312
  pause(id) {
1309
1313
  const entry = this.jobs.get(id);
1310
- if (entry && entry.context.state === JobState.RUNNING) {
1314
+ if (entry && (entry.context.state === JobState.RUNNING || entry.context.state === JobState.SCHEDULED)) {
1311
1315
  this.updateState(id, JobState.PAUSED);
1312
1316
  this.clearTimers(id);
1313
1317
  entry.job.pause?.();
@@ -1963,12 +1967,101 @@ class Scheduler {
1963
1967
  this.logger.info("Scheduler initialized");
1964
1968
  this.alarm.onTrigger(this.execute.bind(this));
1965
1969
  this.timeout.onTrigger(this.execute.bind(this));
1970
+ this.setupPopupVisibilityListener();
1971
+ }
1972
+ /**
1973
+ * Setup listener for popup visibility changes.
1974
+ * When popup closes, pause all jobs with requiresPopup.
1975
+ * When popup opens, resume those jobs.
1976
+ */
1977
+ setupPopupVisibilityListener() {
1978
+ const visibilityService = PopupVisibilityService.instance;
1979
+ this.logger.info("[Scheduler] Setting up popup visibility listener");
1980
+ this.popupVisibilityUnsubscribe = visibilityService.onVisibilityChange((isVisible) => {
1981
+ this.logger.info(`[Scheduler] Visibility changed: ${isVisible ? "visible" : "hidden"}`);
1982
+ if (isVisible) {
1983
+ this.resumePopupDependentJobs();
1984
+ } else {
1985
+ this.pausePopupDependentJobs();
1986
+ }
1987
+ });
1988
+ }
1989
+ /**
1990
+ * Pause all jobs that have requiresPopup: true
1991
+ */
1992
+ pausePopupDependentJobs() {
1993
+ const jobs = this.registry.listAll();
1994
+ this.logger.info(`[Scheduler] pausePopupDependentJobs called, total jobs: ${jobs.length}`);
1995
+ let pausedCount = 0;
1996
+ const pausedJobIds = [];
1997
+ for (const job of jobs) {
1998
+ const hasRequiresPopup = job.options?.requiresPopup;
1999
+ const isPaused = this.registry.getContext(job.id)?.isPaused();
2000
+ this.logger.debug(
2001
+ `[Scheduler] Job ${job.id}: requiresPopup=${hasRequiresPopup}, isPaused=${isPaused}`
2002
+ );
2003
+ if (hasRequiresPopup && !isPaused) {
2004
+ this.alarm.cancel(job.id);
2005
+ this.timeout.cancel(job.id);
2006
+ this.registry.pause(job.id);
2007
+ pausedJobIds.push(job.id);
2008
+ pausedCount++;
2009
+ }
2010
+ }
2011
+ if (pausedCount > 0) {
2012
+ this.logger.info(
2013
+ `[Scheduler] Paused ${pausedCount} popup-dependent jobs (popup closed): ${pausedJobIds.join(", ")}`
2014
+ );
2015
+ } else {
2016
+ this.logger.info(`[Scheduler] No popup-dependent jobs to pause`);
2017
+ }
2018
+ }
2019
+ /**
2020
+ * Resume all jobs that have requiresPopup: true
2021
+ */
2022
+ resumePopupDependentJobs() {
2023
+ const jobs = this.registry.listAll();
2024
+ this.logger.info(`[Scheduler] resumePopupDependentJobs called, total jobs: ${jobs.length}`);
2025
+ let resumedCount = 0;
2026
+ const resumedJobIds = [];
2027
+ for (const job of jobs) {
2028
+ const hasRequiresPopup = job.options?.requiresPopup;
2029
+ const isPaused = this.registry.getContext(job.id)?.isPaused();
2030
+ this.logger.debug(
2031
+ `[Scheduler] Job ${job.id}: requiresPopup=${hasRequiresPopup}, isPaused=${isPaused}`
2032
+ );
2033
+ if (hasRequiresPopup && isPaused) {
2034
+ this.registry.resume(job.id);
2035
+ this.schedule(job.id, job.options);
2036
+ resumedJobIds.push(job.id);
2037
+ resumedCount++;
2038
+ }
2039
+ }
2040
+ if (resumedCount > 0) {
2041
+ this.logger.info(
2042
+ `[Scheduler] Resumed ${resumedCount} popup-dependent jobs (popup opened): ${resumedJobIds.join(", ")}`
2043
+ );
2044
+ } else {
2045
+ this.logger.info(`[Scheduler] No popup-dependent jobs to resume`);
2046
+ }
1966
2047
  }
1967
2048
  schedule(id, options) {
1968
2049
  const context = this.registry.getContext(id);
1969
2050
  if (!context || context.isStopped()) {
1970
2051
  return;
1971
2052
  }
2053
+ if (options?.requiresPopup) {
2054
+ const isPopupVisible = PopupVisibilityService.instance.isPopupVisible();
2055
+ if (!isPopupVisible) {
2056
+ this.logger.debug(
2057
+ `Job ${id} requires popup but popup is not visible, pausing instead of scheduling`
2058
+ );
2059
+ if (!context.isPaused()) {
2060
+ this.registry.pause(id);
2061
+ }
2062
+ return;
2063
+ }
2064
+ }
1972
2065
  const when = this.getScheduleTime(options);
1973
2066
  const now = Date.now();
1974
2067
  if (when <= now) {
@@ -2031,10 +2124,8 @@ class Scheduler {
2031
2124
  if (options?.requiresPopup) {
2032
2125
  const isPopupVisible = PopupVisibilityService.instance.isPopupVisible();
2033
2126
  if (!isPopupVisible) {
2034
- this.logger.debug(`Job ${id} requires popup but popup is not visible, skipping`);
2035
- if (options?.cron || options?.recurring) {
2036
- this.schedule(id, options);
2037
- }
2127
+ this.logger.debug(`Job ${id} requires popup but popup closed, pausing job`);
2128
+ this.registry.pause(id);
2038
2129
  return;
2039
2130
  }
2040
2131
  }
@@ -2084,6 +2175,10 @@ class Scheduler {
2084
2175
  */
2085
2176
  shutdown() {
2086
2177
  this.logger.info("Shutting down scheduler...");
2178
+ if (this.popupVisibilityUnsubscribe) {
2179
+ this.popupVisibilityUnsubscribe();
2180
+ this.popupVisibilityUnsubscribe = void 0;
2181
+ }
2087
2182
  this.alarm.clear();
2088
2183
  this.timeout.clear();
2089
2184
  this.registry.clear();
@@ -2629,4 +2724,4 @@ class BootstrapBuilder {
2629
2724
  }
2630
2725
 
2631
2726
  export { JobRegistry as J, NonceService as N, PopupVisibilityService as P, Scheduler as S, getPopupVisibilityService as a, arePortsClaimed as b, claimEarlyPorts as c, container as d, create as e, bootstrap as f, getNonceService as g, JobState as h, isEarlyListenerSetup as i, setupEarlyListener as s };
2632
- //# sourceMappingURL=boot-DrOND1Zi.js.map
2727
+ //# sourceMappingURL=boot-Bty0U5M4.js.map