diff --git a/src/platform/onboarding/onboardingOverlayStore.test.ts b/src/platform/onboarding/onboardingOverlayStore.test.ts new file mode 100644 index 00000000000..0f608e38e18 --- /dev/null +++ b/src/platform/onboarding/onboardingOverlayStore.test.ts @@ -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) + }) +}) diff --git a/src/platform/onboarding/onboardingOverlayStore.ts b/src/platform/onboarding/onboardingOverlayStore.ts new file mode 100644 index 00000000000..c67e2805717 --- /dev/null +++ b/src/platform/onboarding/onboardingOverlayStore.ts @@ -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 } + } +) diff --git a/src/platform/updates/common/releaseStore.test.ts b/src/platform/updates/common/releaseStore.test.ts index 7b9217bfe80..b0b9d3aceed 100644 --- a/src/platform/updates/common/releaseStore.test.ts +++ b/src/platform/updates/common/releaseStore.test.ts @@ -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' @@ -111,6 +113,7 @@ vi.mock('@/platform/onboarding/onboardingTourStore', async () => { }) describe('useReleaseStore', () => { + let overlayActive: Ref const mockRelease = { id: 1, project: 'comfyui' as const, @@ -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', () => { @@ -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', () => { diff --git a/src/platform/updates/common/releaseStore.ts b/src/platform/updates/common/releaseStore.ts index 8852cd7ddd5..495d92e4f59 100644 --- a/src/platform/updates/common/releaseStore.ts +++ b/src/platform/updates/common/releaseStore.ts @@ -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' @@ -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 ?? '' @@ -177,6 +179,10 @@ export const useReleaseStore = defineStore('release', () => { return false } + if (onboardingOverlayStore.active) { + return false + } + if (!isDesktop && !isCloud) { return false } diff --git a/src/workbench/extensions/agent/components/agent/OnboardingCoach.test.ts b/src/workbench/extensions/agent/components/agent/OnboardingCoach.test.ts index fb7c2cff6d5..b67105aab28 100644 --- a/src/workbench/extensions/agent/components/agent/OnboardingCoach.test.ts +++ b/src/workbench/extensions/agent/components/agent/OnboardingCoach.test.ts @@ -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' @@ -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' }] diff --git a/src/workbench/extensions/agent/components/agent/OnboardingCoach.vue b/src/workbench/extensions/agent/components/agent/OnboardingCoach.vue index 06a81fa31c6..c35657ce734 100644 --- a/src/workbench/extensions/agent/components/agent/OnboardingCoach.vue +++ b/src/workbench/extensions/agent/components/agent/OnboardingCoach.vue @@ -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' @@ -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(null)