mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 06:20:11 +00:00
fix: guard cloud promo scheduling after unmount
This commit is contained in:
@@ -91,6 +91,23 @@ describe('DesktopCloudNotificationController', () => {
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('does not schedule or show the notification after unmounting before settings load resolves', async () => {
|
||||
const loadSettings = createDeferred()
|
||||
settingStore.load.mockImplementation(() => loadSettings.promise)
|
||||
|
||||
const wrapper = mount(DesktopCloudNotificationController)
|
||||
await nextTick()
|
||||
|
||||
wrapper.unmount()
|
||||
loadSettings.resolve()
|
||||
|
||||
await flushPromises()
|
||||
await vi.advanceTimersByTimeAsync(2000)
|
||||
|
||||
expect(settingStore.set).not.toHaveBeenCalled()
|
||||
expect(dialogService.showCloudNotification).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('marks the notification as shown before awaiting dialog close', async () => {
|
||||
const dialogOpen = createDeferred()
|
||||
dialogService.showCloudNotification.mockImplementation(
|
||||
|
||||
@@ -9,6 +9,7 @@ import { electronAPI } from '@/utils/envUtil'
|
||||
const settingStore = useSettingStore()
|
||||
const dialogService = useDialogService()
|
||||
|
||||
let isDisposed = false
|
||||
let cloudNotificationTimer: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
async function scheduleCloudNotification() {
|
||||
@@ -21,11 +22,15 @@ async function scheduleCloudNotification() {
|
||||
return
|
||||
}
|
||||
|
||||
if (isDisposed) return
|
||||
if (settingStore.get('Comfy.Desktop.CloudNotificationShown')) return
|
||||
|
||||
cloudNotificationTimer = setTimeout(async () => {
|
||||
if (isDisposed) return
|
||||
|
||||
try {
|
||||
await settingStore.set('Comfy.Desktop.CloudNotificationShown', true)
|
||||
if (isDisposed) return
|
||||
await dialogService.showCloudNotification()
|
||||
} catch (error) {
|
||||
console.warn('[CloudNotification] Failed to show', error)
|
||||
@@ -46,6 +51,7 @@ onMounted(() => {
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
isDisposed = true
|
||||
if (cloudNotificationTimer) clearTimeout(cloudNotificationTimer)
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user