mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-27 17:52:16 +00:00
Simplify OS detection to use systemStatsStore only
- Remove navigator fallback since systemStatsStore is the standard - Default to Windows when OS info not available - Simplify tests to match new behavior - More consistent with app architecture
This commit is contained in:
@@ -128,6 +128,7 @@ import { type ReleaseNote } from '@/services/releaseService'
|
||||
import { useCommandStore } from '@/stores/commandStore'
|
||||
import { useReleaseStore } from '@/stores/releaseStore'
|
||||
import { useSettingStore } from '@/stores/settingStore'
|
||||
import { useSystemStatsStore } from '@/stores/systemStatsStore'
|
||||
import { electronAPI, isElectron } from '@/utils/envUtil'
|
||||
import { formatVersionAnchor } from '@/utils/formatUtil'
|
||||
|
||||
@@ -170,6 +171,7 @@ const { t, locale } = useI18n()
|
||||
const releaseStore = useReleaseStore()
|
||||
const commandStore = useCommandStore()
|
||||
const settingStore = useSettingStore()
|
||||
const systemStatsStore = useSystemStatsStore()
|
||||
|
||||
// Emits
|
||||
const emit = defineEmits<{
|
||||
@@ -199,7 +201,12 @@ const menuItems = computed<MenuItem[]>(() => {
|
||||
type: 'item',
|
||||
label: t('helpCenter.desktopUserGuide'),
|
||||
action: () => {
|
||||
openExternalLink(getDesktopGuideUrl(locale.value))
|
||||
openExternalLink(
|
||||
getDesktopGuideUrl(
|
||||
locale.value,
|
||||
systemStatsStore.systemStats?.system?.os
|
||||
)
|
||||
)
|
||||
emit('close')
|
||||
}
|
||||
},
|
||||
|
||||
@@ -80,13 +80,23 @@ export const DEVELOPER_TOOLS = {
|
||||
}
|
||||
|
||||
// Platform and locale-aware desktop guide URL generator
|
||||
export const getDesktopGuideUrl = (locale: string): string => {
|
||||
export const getDesktopGuideUrl = (
|
||||
locale: string,
|
||||
systemStatsOs?: string
|
||||
): string => {
|
||||
const isChineseLocale = locale === 'zh'
|
||||
const isMacOS =
|
||||
typeof navigator !== 'undefined' &&
|
||||
navigator.platform.toUpperCase().indexOf('MAC') >= 0
|
||||
|
||||
const platform = isMacOS ? 'macos' : 'windows'
|
||||
let platform = 'windows' // default
|
||||
|
||||
if (systemStatsOs) {
|
||||
const os = systemStatsOs.toLowerCase()
|
||||
if (os.includes('darwin') || os.includes('mac')) {
|
||||
platform = 'macos'
|
||||
} else if (os.includes('windows')) {
|
||||
platform = 'windows'
|
||||
}
|
||||
}
|
||||
|
||||
const baseUrl = isChineseLocale
|
||||
? `https://docs.${COMFY_BASE_DOMAIN}/zh-CN/installation/desktop`
|
||||
: `https://docs.${COMFY_BASE_DOMAIN}/installation/desktop`
|
||||
|
||||
@@ -5,6 +5,7 @@ import { getDesktopGuideUrl } from '@/constants/urls'
|
||||
import { i18n, t } from '@/i18n'
|
||||
import { app } from '@/scripts/app'
|
||||
import { useDialogService } from '@/services/dialogService'
|
||||
import { useSystemStatsStore } from '@/stores/systemStatsStore'
|
||||
import { useToastStore } from '@/stores/toastStore'
|
||||
import { useWorkflowStore } from '@/stores/workflowStore'
|
||||
import { electronAPI as getElectronAPI, isElectron } from '@/utils/envUtil'
|
||||
@@ -160,7 +161,14 @@ import { checkMirrorReachable } from '@/utils/networkUtil'
|
||||
label: 'Desktop User Guide',
|
||||
icon: 'pi pi-book',
|
||||
function() {
|
||||
window.open(getDesktopGuideUrl(i18n.global.locale.value), '_blank')
|
||||
const systemStatsStore = useSystemStatsStore()
|
||||
window.open(
|
||||
getDesktopGuideUrl(
|
||||
i18n.global.locale.value,
|
||||
systemStatsStore.systemStats?.system?.os
|
||||
),
|
||||
'_blank'
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -102,23 +102,35 @@ describe('URL Constants', () => {
|
||||
})
|
||||
|
||||
it('should generate platform and locale-aware desktop guide URLs', () => {
|
||||
// Test English locale
|
||||
const enUrl = getDesktopGuideUrl('en')
|
||||
expect(enUrl).toMatch(
|
||||
/^https:\/\/docs\.comfy\.org\/installation\/desktop\/(windows|macos)$/
|
||||
// Test default (no OS provided) - should default to Windows
|
||||
const defaultUrl = getDesktopGuideUrl('en')
|
||||
expect(defaultUrl).toBe(
|
||||
'https://docs.comfy.org/installation/desktop/windows'
|
||||
)
|
||||
|
||||
// Test Chinese locale
|
||||
const zhUrl = getDesktopGuideUrl('zh')
|
||||
expect(zhUrl).toMatch(
|
||||
/^https:\/\/docs\.comfy\.org\/zh-CN\/installation\/desktop\/(windows|macos)$/
|
||||
// Test with systemStats OS parameter - macOS
|
||||
const macUrl = getDesktopGuideUrl('en', 'Darwin 23.1.0')
|
||||
expect(macUrl).toBe('https://docs.comfy.org/installation/desktop/macos')
|
||||
|
||||
// Test with systemStats OS parameter - Windows
|
||||
const winUrl = getDesktopGuideUrl('en', 'Windows 10')
|
||||
expect(winUrl).toBe('https://docs.comfy.org/installation/desktop/windows')
|
||||
|
||||
// Test Chinese locale with systemStats
|
||||
const zhMacUrl = getDesktopGuideUrl('zh', 'macOS 14.0')
|
||||
expect(zhMacUrl).toBe(
|
||||
'https://docs.comfy.org/zh-CN/installation/desktop/macos'
|
||||
)
|
||||
|
||||
// Test Chinese locale defaults to Windows
|
||||
const zhDefaultUrl = getDesktopGuideUrl('zh')
|
||||
expect(zhDefaultUrl).toBe(
|
||||
'https://docs.comfy.org/zh-CN/installation/desktop/windows'
|
||||
)
|
||||
|
||||
// Test other locales default to English
|
||||
const frUrl = getDesktopGuideUrl('fr')
|
||||
expect(frUrl).toMatch(
|
||||
/^https:\/\/docs\.comfy\.org\/installation\/desktop\/(windows|macos)$/
|
||||
)
|
||||
const frUrl = getDesktopGuideUrl('fr', 'Windows 11')
|
||||
expect(frUrl).toBe('https://docs.comfy.org/installation/desktop/windows')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user