Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/platform/onboarding/onboardingOverlayStore.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { describe, expect, it } from 'vitest'
import { ref } from 'vue'

import { useOnboardingOverlayStore } from '@/platform/onboarding/onboardingOverlayStore'

describe('useOnboardingOverlayStore', () => {
it('is inactive with no registered sources', () => {
const store = useOnboardingOverlayStore()
expect(store.active).toBe(false)
})

it('reports a registered source reactively', () => {
const store = useOnboardingOverlayStore()
const running = ref(false)
store.registerSource(() => running.value)

expect(store.active).toBe(false)
running.value = true
expect(store.active).toBe(true)
running.value = false
expect(store.active).toBe(false)
})

it('is active while any one source is active', () => {
const store = useOnboardingOverlayStore()
const a = ref(false)
const b = ref(false)
store.registerSource(() => a.value)
store.registerSource(() => b.value)

expect(store.active).toBe(false)
b.value = true
expect(store.active).toBe(true)
})

it('drops a source when it deregisters, so an overlay cannot leak', () => {
const store = useOnboardingOverlayStore()
const running = ref(true)
const stop = store.registerSource(() => running.value)

expect(store.active).toBe(true)
stop()
expect(store.active).toBe(false)
})

it('deregisters only the given source, leaving others active', () => {
const store = useOnboardingOverlayStore()
const stopA = store.registerSource(() => true)
store.registerSource(() => true)

stopA()
expect(store.active).toBe(true)
})

it('keeps registrations independent when the same getter is registered twice', () => {
const store = useOnboardingOverlayStore()
const getter = () => true
const stopA = store.registerSource(getter)
store.registerSource(getter)

stopA()
expect(store.active).toBe(true)
})
})
37 changes: 37 additions & 0 deletions src/platform/onboarding/onboardingOverlayStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { defineStore } from 'pinia'
import { computed, getCurrentScope, onScopeDispose, shallowRef } from 'vue'

/**
* Signals onboarding overlays that live outside the tour store (the agent
* onboarding coach is the first), so the What's New popup can defer to them as
* it already does to `activeTour`. A source registers a getter and drops it on
* teardown, so an unmounted overlay cannot leak as permanently active.
*/
export const useOnboardingOverlayStore = defineStore(
'onboardingOverlay',
() => {
const sources = shallowRef(new Set<() => boolean>())

const active = computed(() =>
[...sources.value].some((isActive) => isActive())
)

function registerSource(isActive: () => boolean): () => void {
// Wrap so each call owns a unique entry; two callers passing the same
// getter reference must not collapse to one, or one stop() drops both.
const source = () => isActive()
sources.value = new Set(sources.value).add(source)
const stop = () => {
const next = new Set(sources.value)
next.delete(source)
sources.value = next
}
// Drop the source with the caller's scope, so a component consumer cannot
// forget teardown and leak it. Direct callers outside a scope stop by hand.
if (getCurrentScope()) onScopeDispose(stop)
return stop
}

return { active, registerSource }
}
)
27 changes: 27 additions & 0 deletions src/platform/updates/common/releaseStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { until } from '@vueuse/core'
import { compare } from 'semver'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ref } from 'vue'
import type { Ref } from 'vue'

import { useOnboardingOverlayStore } from '@/platform/onboarding/onboardingOverlayStore'
import type { EntryPath } from '@/platform/onboarding/onboardingTours'
import type { ReleaseNote } from '@/platform/updates/common/releaseService'
import { useSettingStore } from '@/platform/settings/settingStore'
Expand Down Expand Up @@ -111,6 +113,7 @@ vi.mock('@/platform/onboarding/onboardingTourStore', async () => {
})

describe('useReleaseStore', () => {
let overlayActive: Ref<boolean>
const mockRelease = {
id: 1,
project: 'comfyui' as const,
Expand All @@ -124,6 +127,10 @@ describe('useReleaseStore', () => {
mockSystemStatsState.reset()
mockData.isCloud = false
mocks.tour.activeTour = null
overlayActive = ref(false)
vi.spyOn(useOnboardingOverlayStore(), 'active', 'get').mockImplementation(
() => overlayActive.value
)
})

describe('initial state', () => {
Expand Down Expand Up @@ -687,6 +694,26 @@ describe('useReleaseStore', () => {

expect(store.shouldShowPopup).toBe(true)
})

it('withholds the popup while an onboarding overlay is on screen', () => {
const store = useReleaseStore()
const systemStatsStore = useSystemStatsStore()
const settingStore = useSettingStore()
systemStatsStore.systemStats!.system.comfyui_version = '1.2.0'
vi.mocked(settingStore.get).mockImplementation((key: string) => {
if (key === 'Comfy.Notification.ShowVersionUpdates') return true
return null
})
vi.mocked(compare).mockReturnValue(0)

store.releases = [mockRelease]

overlayActive.value = true
expect(store.shouldShowPopup).toBe(false)

overlayActive.value = false
expect(store.shouldShowPopup).toBe(true)
})
})

describe('edge cases', () => {
Expand Down
6 changes: 6 additions & 0 deletions src/platform/updates/common/releaseStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { compare, valid } from 'semver'
import { computed, ref } from 'vue'

import { isCloud, isDesktop } from '@/platform/distribution/types'
import { useOnboardingOverlayStore } from '@/platform/onboarding/onboardingOverlayStore'
import { useOnboardingTourStore } from '@/platform/onboarding/onboardingTourStore'
import { useSettingStore } from '@/platform/settings/settingStore'
import { useSystemStatsStore } from '@/stores/systemStatsStore'
Expand All @@ -24,6 +25,7 @@ export const useReleaseStore = defineStore('release', () => {
const systemStatsStore = useSystemStatsStore()
const settingStore = useSettingStore()
const onboardingTourStore = useOnboardingTourStore()
const onboardingOverlayStore = useOnboardingOverlayStore()

const currentVersion = computed(
() => systemStatsStore.systemStats?.system.comfyui_version ?? ''
Expand Down Expand Up @@ -177,6 +179,10 @@ export const useReleaseStore = defineStore('release', () => {
return false
}

if (onboardingOverlayStore.active) {
return false
}

if (!isDesktop && !isCloud) {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
import { nextTick } from 'vue'

import { i18n } from '@/i18n'
import { useOnboardingOverlayStore } from '@/platform/onboarding/onboardingOverlayStore'
import type { CoachStep } from '../../composables/agent/useOnboarding'

import OnboardingCoach from './OnboardingCoach.vue'
Expand Down Expand Up @@ -226,6 +227,27 @@ describe('OnboardingCoach', () => {
expect(localStorage.getItem(KEY)).toBe('false')
})

it('signals the onboarding overlay while running and clears it when dismissed', async () => {
const overlay = useOnboardingOverlayStore()
const user = userEvent.setup()
mount()
await screen.findByRole('dialog', { name: STEPS[0].title })
expect(overlay.active).toBe(true)

await user.click(screen.getByRole('button', { name: 'Skip' }))
expect(overlay.active).toBe(false)
})

it('clears the onboarding overlay signal when it unmounts mid-tour', async () => {
const overlay = useOnboardingOverlayStore()
const { unmount } = mount()
await screen.findByRole('dialog', { name: STEPS[0].title })
expect(overlay.active).toBe(true)

unmount()
expect(overlay.active).toBe(false)
})

it('waits for a late target without letting Escape complete an unseen tour', async () => {
const storageKey = 'coach-late-target-test'
const lateSteps = [{ ...STEPS[0], target: '#late-panel' }]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { computed, nextTick, onBeforeUnmount, ref, useId, watch } from 'vue'
import { vRekaZIndex } from '@/components/dialog/vRekaZIndex'
import Button from '@/components/ui/button/Button.vue'
import { clampSpotlight } from '@/platform/onboarding/coachmarkLayout'
import { useOnboardingOverlayStore } from '@/platform/onboarding/onboardingOverlayStore'
import type { CoachStep } from '../../composables/agent/useOnboarding'
import { useOnboarding } from '../../composables/agent/useOnboarding'

Expand All @@ -25,6 +26,10 @@ const { active, index, step, isLast, next, finish } = useOnboarding(
() => steps,
storageKey
)

// Let surfaces like the What's New popup defer while these coach marks run.
// The store drops the source with this component's scope on unmount.
useOnboardingOverlayStore().registerSource(() => active.value)
const titleId = useId()
const bodyId = useId()
const target = ref<HTMLElement | null>(null)
Expand Down
Loading