LCOV - code coverage report
Current view: top level - src/platform/workspace - deploymentSwitchReload.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 6.5 % 31 2
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1         2356 : const SWITCH_LANDING_KEY = 'Comfy.DeploymentSwitch.Reloading'
       2              : 
       3            0 : function forgetSwitchLanding() {
       4            0 :   try {
       5            0 :     sessionStorage.removeItem(SWITCH_LANDING_KEY)
       6              :   } catch {
       7            0 :     return
       8              :   }
       9              : }
      10              : 
      11            0 : function markSwitchLanding() {
      12            0 :   try {
      13            0 :     sessionStorage.setItem(SWITCH_LANDING_KEY, '1')
      14              :   } catch {
      15            0 :     return
      16              :   }
      17              : }
      18              : 
      19         2356 : let stayWatch = new AbortController()
      20              : 
      21            0 : function onNextInteraction(callback: () => void) {
      22            0 :   stayWatch.abort()
      23            0 :   const controller = new AbortController()
      24            0 :   stayWatch = controller
      25            0 :   const run = () => {
      26            0 :     controller.abort()
      27            0 :     callback()
      28              :   }
      29            0 :   for (const type of ['pointerdown', 'keydown']) {
      30            0 :     window.addEventListener(type, run, {
      31              :       capture: true,
      32              :       signal: controller.signal
      33              :     })
      34              :   }
      35              : }
      36              : 
      37              : /** Reloads for a switch; `onStay` runs on the next interaction if it stays. */
      38            0 : export function reloadForDeploymentSwitch(onStay: () => void): void {
      39            0 :   markSwitchLanding()
      40            0 :   onNextInteraction(() => {
      41            0 :     forgetSwitchLanding()
      42            0 :     onStay()
      43              :   })
      44            0 :   window.location.reload()
      45              : }
      46              : 
      47              : /** True once, on the first boot after a deployment switch reloaded this tab. */
      48            0 : export function takeDeploymentSwitchLanding(): boolean {
      49            0 :   try {
      50            0 :     const landed = sessionStorage.getItem(SWITCH_LANDING_KEY) !== null
      51            0 :     sessionStorage.removeItem(SWITCH_LANDING_KEY)
      52            0 :     return landed
      53              :   } catch {
      54            0 :     return false
      55              :   }
      56              : }
        

Generated by: LCOV version 2.0-1