@chromahq/core 1.0.53 → 1.0.54

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.
@@ -1963,12 +1963,77 @@ class Scheduler {
1963
1963
  this.logger.info("Scheduler initialized");
1964
1964
  this.alarm.onTrigger(this.execute.bind(this));
1965
1965
  this.timeout.onTrigger(this.execute.bind(this));
1966
+ this.setupPopupVisibilityListener();
1967
+ }
1968
+ /**
1969
+ * Setup listener for popup visibility changes.
1970
+ * When popup closes, pause all jobs with requiresPopup.
1971
+ * When popup opens, resume those jobs.
1972
+ */
1973
+ setupPopupVisibilityListener() {
1974
+ const visibilityService = PopupVisibilityService.instance;
1975
+ this.popupVisibilityUnsubscribe = visibilityService.onVisibilityChange((isVisible) => {
1976
+ if (isVisible) {
1977
+ this.resumePopupDependentJobs();
1978
+ } else {
1979
+ this.pausePopupDependentJobs();
1980
+ }
1981
+ });
1982
+ }
1983
+ /**
1984
+ * Pause all jobs that have requiresPopup: true
1985
+ */
1986
+ pausePopupDependentJobs() {
1987
+ const jobs = this.registry.listAll();
1988
+ let pausedCount = 0;
1989
+ for (const job of jobs) {
1990
+ if (job.options?.requiresPopup && !this.registry.getContext(job.id)?.isPaused()) {
1991
+ this.logger.debug(`Pausing popup-dependent job: ${job.id}`);
1992
+ this.alarm.cancel(job.id);
1993
+ this.timeout.cancel(job.id);
1994
+ this.registry.pause(job.id);
1995
+ pausedCount++;
1996
+ }
1997
+ }
1998
+ if (pausedCount > 0) {
1999
+ this.logger.info(`Paused ${pausedCount} popup-dependent jobs (popup closed)`);
2000
+ }
2001
+ }
2002
+ /**
2003
+ * Resume all jobs that have requiresPopup: true
2004
+ */
2005
+ resumePopupDependentJobs() {
2006
+ const jobs = this.registry.listAll();
2007
+ let resumedCount = 0;
2008
+ for (const job of jobs) {
2009
+ if (job.options?.requiresPopup && this.registry.getContext(job.id)?.isPaused()) {
2010
+ this.logger.debug(`Resuming popup-dependent job: ${job.id}`);
2011
+ this.registry.resume(job.id);
2012
+ this.schedule(job.id, job.options);
2013
+ resumedCount++;
2014
+ }
2015
+ }
2016
+ if (resumedCount > 0) {
2017
+ this.logger.info(`Resumed ${resumedCount} popup-dependent jobs (popup opened)`);
2018
+ }
1966
2019
  }
1967
2020
  schedule(id, options) {
1968
2021
  const context = this.registry.getContext(id);
1969
2022
  if (!context || context.isStopped()) {
1970
2023
  return;
1971
2024
  }
2025
+ if (options?.requiresPopup) {
2026
+ const isPopupVisible = PopupVisibilityService.instance.isPopupVisible();
2027
+ if (!isPopupVisible) {
2028
+ this.logger.debug(
2029
+ `Job ${id} requires popup but popup is not visible, pausing instead of scheduling`
2030
+ );
2031
+ if (!context.isPaused()) {
2032
+ this.registry.pause(id);
2033
+ }
2034
+ return;
2035
+ }
2036
+ }
1972
2037
  const when = this.getScheduleTime(options);
1973
2038
  const now = Date.now();
1974
2039
  if (when <= now) {
@@ -2031,10 +2096,8 @@ class Scheduler {
2031
2096
  if (options?.requiresPopup) {
2032
2097
  const isPopupVisible = PopupVisibilityService.instance.isPopupVisible();
2033
2098
  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
- }
2099
+ this.logger.debug(`Job ${id} requires popup but popup closed, pausing job`);
2100
+ this.registry.pause(id);
2038
2101
  return;
2039
2102
  }
2040
2103
  }
@@ -2084,6 +2147,10 @@ class Scheduler {
2084
2147
  */
2085
2148
  shutdown() {
2086
2149
  this.logger.info("Shutting down scheduler...");
2150
+ if (this.popupVisibilityUnsubscribe) {
2151
+ this.popupVisibilityUnsubscribe();
2152
+ this.popupVisibilityUnsubscribe = void 0;
2153
+ }
2087
2154
  this.alarm.clear();
2088
2155
  this.timeout.clear();
2089
2156
  this.registry.clear();
@@ -2629,4 +2696,4 @@ class BootstrapBuilder {
2629
2696
  }
2630
2697
 
2631
2698
  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
2699
+ //# sourceMappingURL=boot-DRsz4LpW.js.map