From 89b9af8606a8d86439f962a9708c872026b77429 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Thu, 4 Dec 2025 22:09:17 -0800 Subject: [PATCH 1/5] Fix electron adapter docs link builder --- src/extensions/core/electronAdapter.ts | 33 ++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/extensions/core/electronAdapter.ts b/src/extensions/core/electronAdapter.ts index 9fec244148..43160b59b3 100644 --- a/src/extensions/core/electronAdapter.ts +++ b/src/extensions/core/electronAdapter.ts @@ -1,6 +1,5 @@ import log from 'loglevel' -import { useExternalLink } from '@/composables/useExternalLink' import { PYTHON_MIRROR } from '@/constants/uvMirrors' import { t } from '@/i18n' import { useToastStore } from '@/platform/updates/common/toastStore' @@ -9,6 +8,7 @@ import { app } from '@/scripts/app' import { useDialogService } from '@/services/dialogService' import { checkMirrorReachable } from '@/utils/electronMirrorCheck' import { electronAPI as getElectronAPI, isElectron } from '@/utils/envUtil' +import { i18n } from '@/i18n' ;(async () => { if (!isElectron()) return @@ -16,7 +16,36 @@ import { electronAPI as getElectronAPI, isElectron } from '@/utils/envUtil' const desktopAppVersion = await electronAPI.getElectronVersion() const workflowStore = useWorkflowStore() const toastStore = useToastStore() - const { staticUrls, buildDocsUrl } = useExternalLink() + // Build docs URLs without using useI18n (which requires a Vue setup context). + // This keeps the extension safe to load at module-eval time. + const staticUrls = { + githubElectron: 'https://github.com/Comfy-Org/electron' + } + const buildDocsUrl = ( + path: string, + options: { includeLocale?: boolean; platform?: boolean } = {} + ) => { + const { includeLocale = false, platform: includePlatform = false } = options + const locale = String(i18n.global.locale.value) + const isChinese = locale === 'zh' || locale === 'zh-TW' + + let url = 'https://docs.comfy.org' + if (includeLocale && isChinese) { + url += '/zh-CN' + } + + const normalizedPath = path.startsWith('/') ? path : `/${path}` + url += normalizedPath + + if (includePlatform) { + const platform = electronAPI.getPlatform() + const suffix = platform === 'darwin' ? 'macos' : 'windows' + url = url.endsWith('/') ? url : `${url}/` + url += suffix + } + + return url + } const onChangeRestartApp = (newValue: string, oldValue: string) => { // Add a delay to allow changes to take effect before restarting. From 4689f553af381affcbe7ba2092f99b6af805aec1 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Thu, 4 Dec 2025 22:14:01 -0800 Subject: [PATCH 2/5] Use global i18n in useExternalLink --- src/composables/useExternalLink.ts | 4 ++-- tests-ui/tests/composables/useExternalLink.test.ts | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/composables/useExternalLink.ts b/src/composables/useExternalLink.ts index 59cb9f6895..2758e2cedf 100644 --- a/src/composables/useExternalLink.ts +++ b/src/composables/useExternalLink.ts @@ -1,7 +1,7 @@ import { computed } from 'vue' import { electronAPI, isElectron } from '@/utils/envUtil' -import { useI18n } from 'vue-i18n' +import { i18n } from '@/i18n' /** * Composable for building docs.comfy.org URLs with automatic locale and platform detection @@ -23,7 +23,7 @@ import { useI18n } from 'vue-i18n' * ``` */ export function useExternalLink() { - const { locale } = useI18n() + const locale = computed(() => String(i18n.global.locale.value)) const isChinese = computed(() => { return locale.value === 'zh' || locale.value === 'zh-TW' diff --git a/tests-ui/tests/composables/useExternalLink.test.ts b/tests-ui/tests/composables/useExternalLink.test.ts index 986322cba4..9bba00d7df 100644 --- a/tests-ui/tests/composables/useExternalLink.test.ts +++ b/tests-ui/tests/composables/useExternalLink.test.ts @@ -9,12 +9,14 @@ vi.mock('@/utils/envUtil', () => ({ electronAPI: vi.fn() })) -// Mock vue-i18n +// Mock global i18n locale ref const mockLocale = ref('en') -vi.mock('vue-i18n', () => ({ - useI18n: vi.fn(() => ({ - locale: mockLocale - })) +vi.mock('@/i18n', () => ({ + i18n: { + global: { + locale: mockLocale + } + } })) // Import after mocking to get the mocked versions From 0b1e496ad5430767280f190a307df2c11fc69a75 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Thu, 4 Dec 2025 22:15:27 -0800 Subject: [PATCH 3/5] Use shared useExternalLink in electron adapter --- src/extensions/core/electronAdapter.ts | 33 ++------------------------ 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/src/extensions/core/electronAdapter.ts b/src/extensions/core/electronAdapter.ts index 43160b59b3..9fec244148 100644 --- a/src/extensions/core/electronAdapter.ts +++ b/src/extensions/core/electronAdapter.ts @@ -1,5 +1,6 @@ import log from 'loglevel' +import { useExternalLink } from '@/composables/useExternalLink' import { PYTHON_MIRROR } from '@/constants/uvMirrors' import { t } from '@/i18n' import { useToastStore } from '@/platform/updates/common/toastStore' @@ -8,7 +9,6 @@ import { app } from '@/scripts/app' import { useDialogService } from '@/services/dialogService' import { checkMirrorReachable } from '@/utils/electronMirrorCheck' import { electronAPI as getElectronAPI, isElectron } from '@/utils/envUtil' -import { i18n } from '@/i18n' ;(async () => { if (!isElectron()) return @@ -16,36 +16,7 @@ import { i18n } from '@/i18n' const desktopAppVersion = await electronAPI.getElectronVersion() const workflowStore = useWorkflowStore() const toastStore = useToastStore() - // Build docs URLs without using useI18n (which requires a Vue setup context). - // This keeps the extension safe to load at module-eval time. - const staticUrls = { - githubElectron: 'https://github.com/Comfy-Org/electron' - } - const buildDocsUrl = ( - path: string, - options: { includeLocale?: boolean; platform?: boolean } = {} - ) => { - const { includeLocale = false, platform: includePlatform = false } = options - const locale = String(i18n.global.locale.value) - const isChinese = locale === 'zh' || locale === 'zh-TW' - - let url = 'https://docs.comfy.org' - if (includeLocale && isChinese) { - url += '/zh-CN' - } - - const normalizedPath = path.startsWith('/') ? path : `/${path}` - url += normalizedPath - - if (includePlatform) { - const platform = electronAPI.getPlatform() - const suffix = platform === 'darwin' ? 'macos' : 'windows' - url = url.endsWith('/') ? url : `${url}/` - url += suffix - } - - return url - } + const { staticUrls, buildDocsUrl } = useExternalLink() const onChangeRestartApp = (newValue: string, oldValue: string) => { // Add a delay to allow changes to take effect before restarting. From bd794d7dbcd8c15cdd8e6d6cf5930bb41969bcdb Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Fri, 5 Dec 2025 13:42:35 -0800 Subject: [PATCH 4/5] Fix test issue --- .../tests/composables/useExternalLink.test.ts | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/tests-ui/tests/composables/useExternalLink.test.ts b/tests-ui/tests/composables/useExternalLink.test.ts index 9bba00d7df..b6c191fdf5 100644 --- a/tests-ui/tests/composables/useExternalLink.test.ts +++ b/tests-ui/tests/composables/useExternalLink.test.ts @@ -1,7 +1,5 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' -import { ref } from 'vue' - -import { useExternalLink } from '@/composables/useExternalLink' +import { createI18n } from 'vue-i18n' // Mock the environment utilities vi.mock('@/utils/envUtil', () => ({ @@ -9,24 +7,28 @@ vi.mock('@/utils/envUtil', () => ({ electronAPI: vi.fn() })) -// Mock global i18n locale ref -const mockLocale = ref('en') +// Provide a minimal i18n instance for the composable +const i18n = vi.hoisted(() => + createI18n, string, false>({ + legacy: false, + locale: 'en', + fallbackLocale: 'en', + messages: { en: {} } + }) +) vi.mock('@/i18n', () => ({ - i18n: { - global: { - locale: mockLocale - } - } + i18n })) // Import after mocking to get the mocked versions +import { useExternalLink } from '@/composables/useExternalLink' import { electronAPI, isElectron } from '@/utils/envUtil' describe('useExternalLink', () => { beforeEach(() => { vi.clearAllMocks() // Reset to default state - mockLocale.value = 'en' + i18n.global.locale.value = 'en' vi.mocked(isElectron).mockReturnValue(false) }) @@ -55,7 +57,7 @@ describe('useExternalLink', () => { describe('buildDocsUrl', () => { it('should build basic docs URL without locale', () => { - mockLocale.value = 'en' + i18n.global.locale.value = 'en' const { buildDocsUrl } = useExternalLink() const url = buildDocsUrl('/changelog') @@ -63,7 +65,7 @@ describe('useExternalLink', () => { }) it('should build docs URL with Chinese (zh) locale when requested', () => { - mockLocale.value = 'zh' + i18n.global.locale.value = 'zh' const { buildDocsUrl } = useExternalLink() const url = buildDocsUrl('/changelog', { includeLocale: true }) @@ -71,7 +73,7 @@ describe('useExternalLink', () => { }) it('should build docs URL with Chinese (zh-TW) locale when requested', () => { - mockLocale.value = 'zh-TW' + i18n.global.locale.value = 'zh-TW' const { buildDocsUrl } = useExternalLink() const url = buildDocsUrl('/changelog', { includeLocale: true }) @@ -79,7 +81,7 @@ describe('useExternalLink', () => { }) it('should not include locale for English when requested', () => { - mockLocale.value = 'en' + i18n.global.locale.value = 'en' const { buildDocsUrl } = useExternalLink() const url = buildDocsUrl('/changelog', { includeLocale: true }) @@ -94,7 +96,7 @@ describe('useExternalLink', () => { }) it('should add platform suffix when requested', () => { - mockLocale.value = 'en' + i18n.global.locale.value = 'en' vi.mocked(isElectron).mockReturnValue(true) vi.mocked(electronAPI).mockReturnValue({ getPlatform: () => 'darwin' @@ -106,7 +108,7 @@ describe('useExternalLink', () => { }) it('should add platform suffix with trailing slash', () => { - mockLocale.value = 'en' + i18n.global.locale.value = 'en' vi.mocked(isElectron).mockReturnValue(true) vi.mocked(electronAPI).mockReturnValue({ getPlatform: () => 'win32' @@ -118,7 +120,7 @@ describe('useExternalLink', () => { }) it('should combine locale and platform', () => { - mockLocale.value = 'zh' + i18n.global.locale.value = 'zh' vi.mocked(isElectron).mockReturnValue(true) vi.mocked(electronAPI).mockReturnValue({ getPlatform: () => 'darwin' @@ -135,7 +137,7 @@ describe('useExternalLink', () => { }) it('should not add platform when not desktop', () => { - mockLocale.value = 'en' + i18n.global.locale.value = 'en' vi.mocked(isElectron).mockReturnValue(false) const { buildDocsUrl } = useExternalLink() From 54f9e768dda76e507b67448374181d4ffeafe670 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Fri, 5 Dec 2025 14:28:14 -0800 Subject: [PATCH 5/5] Switch to mocking i18n.global.locale.value --- .../tests/composables/useExternalLink.test.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tests-ui/tests/composables/useExternalLink.test.ts b/tests-ui/tests/composables/useExternalLink.test.ts index b6c191fdf5..7f0ef90aa4 100644 --- a/tests-ui/tests/composables/useExternalLink.test.ts +++ b/tests-ui/tests/composables/useExternalLink.test.ts @@ -1,5 +1,4 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' -import { createI18n } from 'vue-i18n' // Mock the environment utilities vi.mock('@/utils/envUtil', () => ({ @@ -8,14 +7,13 @@ vi.mock('@/utils/envUtil', () => ({ })) // Provide a minimal i18n instance for the composable -const i18n = vi.hoisted(() => - createI18n, string, false>({ - legacy: false, - locale: 'en', - fallbackLocale: 'en', - messages: { en: {} } - }) -) +const i18n = vi.hoisted(() => ({ + global: { + locale: { + value: 'en' + } + } +})) vi.mock('@/i18n', () => ({ i18n }))