Skip to content

Commit 3f290e2

Browse files
[feat] Limit release notifications to desktop app only (#4788)
1 parent 37099c4 commit 3f290e2

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

src/stores/releaseStore.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { computed, ref } from 'vue'
44
import { type ReleaseNote, useReleaseService } from '@/services/releaseService'
55
import { useSettingStore } from '@/stores/settingStore'
66
import { useSystemStatsStore } from '@/stores/systemStatsStore'
7+
import { isElectron } from '@/utils/envUtil'
78
import { compareVersions, stringToLocale } from '@/utils/formatUtil'
89

910
// Store for managing release notes
@@ -76,6 +77,11 @@ export const useReleaseStore = defineStore('release', () => {
7677

7778
// Show toast if needed
7879
const shouldShowToast = computed(() => {
80+
// Only show on desktop version
81+
if (!isElectron()) {
82+
return false
83+
}
84+
7985
// Skip if notifications are disabled
8086
if (!showVersionUpdates.value) {
8187
return false
@@ -103,6 +109,11 @@ export const useReleaseStore = defineStore('release', () => {
103109

104110
// Show red-dot indicator
105111
const shouldShowRedDot = computed(() => {
112+
// Only show on desktop version
113+
if (!isElectron()) {
114+
return false
115+
}
116+
106117
// Skip if notifications are disabled
107118
if (!showVersionUpdates.value) {
108119
return false
@@ -145,6 +156,11 @@ export const useReleaseStore = defineStore('release', () => {
145156

146157
// Show "What's New" popup
147158
const shouldShowPopup = computed(() => {
159+
// Only show on desktop version
160+
if (!isElectron()) {
161+
return false
162+
}
163+
148164
// Skip if notifications are disabled
149165
if (!showVersionUpdates.value) {
150166
return false

tests-ui/tests/store/releaseStore.test.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useReleaseStore } from '@/stores/releaseStore'
55

66
// Mock the dependencies
77
vi.mock('@/utils/formatUtil')
8+
vi.mock('@/utils/envUtil')
89
vi.mock('@/services/releaseService')
910
vi.mock('@/stores/settingStore')
1011
vi.mock('@/stores/systemStatsStore')
@@ -56,10 +57,12 @@ describe('useReleaseStore', () => {
5657
const { useReleaseService } = await import('@/services/releaseService')
5758
const { useSettingStore } = await import('@/stores/settingStore')
5859
const { useSystemStatsStore } = await import('@/stores/systemStatsStore')
60+
const { isElectron } = await import('@/utils/envUtil')
5961

6062
vi.mocked(useReleaseService).mockReturnValue(mockReleaseService)
6163
vi.mocked(useSettingStore).mockReturnValue(mockSettingStore)
6264
vi.mocked(useSystemStatsStore).mockReturnValue(mockSystemStatsStore)
65+
vi.mocked(isElectron).mockReturnValue(true)
6366

6467
// Default showVersionUpdates to true
6568
mockSettingStore.get.mockImplementation((key: string) => {
@@ -444,4 +447,118 @@ describe('useReleaseStore', () => {
444447
expect(mockReleaseService.getReleases).toHaveBeenCalledTimes(1)
445448
})
446449
})
450+
451+
describe('isElectron environment checks', () => {
452+
beforeEach(() => {
453+
// Set up a new version available
454+
store.releases = [mockRelease]
455+
mockSettingStore.get.mockImplementation((key: string) => {
456+
if (key === 'Comfy.Notification.ShowVersionUpdates') return true
457+
return null
458+
})
459+
})
460+
461+
describe('when running in Electron (desktop)', () => {
462+
beforeEach(async () => {
463+
const { isElectron } = await import('@/utils/envUtil')
464+
vi.mocked(isElectron).mockReturnValue(true)
465+
})
466+
467+
it('should show toast when conditions are met', async () => {
468+
const { compareVersions } = await import('@/utils/formatUtil')
469+
vi.mocked(compareVersions).mockReturnValue(1)
470+
471+
// Need multiple releases for hasMediumOrHighAttention
472+
const mediumRelease = {
473+
...mockRelease,
474+
id: 2,
475+
attention: 'medium' as const
476+
}
477+
store.releases = [mockRelease, mediumRelease]
478+
479+
expect(store.shouldShowToast).toBe(true)
480+
})
481+
482+
it('should show red dot when new version available', async () => {
483+
const { compareVersions } = await import('@/utils/formatUtil')
484+
vi.mocked(compareVersions).mockReturnValue(1)
485+
486+
expect(store.shouldShowRedDot).toBe(true)
487+
})
488+
489+
it('should show popup for latest version', async () => {
490+
mockSystemStatsStore.systemStats.system.comfyui_version = '1.2.0'
491+
const { compareVersions } = await import('@/utils/formatUtil')
492+
vi.mocked(compareVersions).mockReturnValue(0)
493+
494+
expect(store.shouldShowPopup).toBe(true)
495+
})
496+
})
497+
498+
describe('when NOT running in Electron (web)', () => {
499+
beforeEach(async () => {
500+
const { isElectron } = await import('@/utils/envUtil')
501+
vi.mocked(isElectron).mockReturnValue(false)
502+
})
503+
504+
it('should NOT show toast even when all other conditions are met', async () => {
505+
const { compareVersions } = await import('@/utils/formatUtil')
506+
vi.mocked(compareVersions).mockReturnValue(1)
507+
508+
// Set up all conditions that would normally show toast
509+
const mediumRelease = {
510+
...mockRelease,
511+
id: 2,
512+
attention: 'medium' as const
513+
}
514+
store.releases = [mockRelease, mediumRelease]
515+
516+
expect(store.shouldShowToast).toBe(false)
517+
})
518+
519+
it('should NOT show red dot even when new version available', async () => {
520+
const { compareVersions } = await import('@/utils/formatUtil')
521+
vi.mocked(compareVersions).mockReturnValue(1)
522+
523+
expect(store.shouldShowRedDot).toBe(false)
524+
})
525+
526+
it('should NOT show toast regardless of attention level', async () => {
527+
const { compareVersions } = await import('@/utils/formatUtil')
528+
vi.mocked(compareVersions).mockReturnValue(1)
529+
530+
// Test with high attention releases
531+
const highRelease = {
532+
...mockRelease,
533+
id: 2,
534+
attention: 'high' as const
535+
}
536+
const mediumRelease = {
537+
...mockRelease,
538+
id: 3,
539+
attention: 'medium' as const
540+
}
541+
store.releases = [highRelease, mediumRelease]
542+
543+
expect(store.shouldShowToast).toBe(false)
544+
})
545+
546+
it('should NOT show red dot even with high attention release', async () => {
547+
const { compareVersions } = await import('@/utils/formatUtil')
548+
vi.mocked(compareVersions).mockReturnValue(1)
549+
550+
store.releases = [{ ...mockRelease, attention: 'high' as const }]
551+
552+
expect(store.shouldShowRedDot).toBe(false)
553+
})
554+
555+
it('should NOT show popup even for latest version', async () => {
556+
mockSystemStatsStore.systemStats.system.comfyui_version = '1.2.0'
557+
const { compareVersions } = await import('@/utils/formatUtil')
558+
vi.mocked(compareVersions).mockReturnValue(0)
559+
560+
expect(store.shouldShowPopup).toBe(false)
561+
})
562+
})
563+
})
447564
})

0 commit comments

Comments
 (0)