mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-07-17 17:28:58 +00:00
Compare commits
8 Commits
feat/creat
...
feat/dashb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3d842cc32 | ||
|
|
d129ab23e1 | ||
|
|
4d774bfa99 | ||
|
|
146a88480c | ||
|
|
cd57484695 | ||
|
|
f524683f3c | ||
|
|
d1d55585f9 | ||
|
|
98c654df20 |
70
.github/workflows/ci-dashboard-deploy.yaml
vendored
Normal file
70
.github/workflows/ci-dashboard-deploy.yaml
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
# Triggered by workflow_run (not push) so this only runs after 'CI: Tests E2E' has
|
||||
# finished merging its sharded blob reports into an HTML report on main — the
|
||||
# 'playwright-report-chromium' artifact this job downloads doesn't exist until that
|
||||
# merge-reports job completes.
|
||||
name: 'CI: Dashboard Deploy'
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ['CI: Tests E2E']
|
||||
types:
|
||||
- completed
|
||||
|
||||
concurrency:
|
||||
group: dashboard-deploy-${{ github.event.workflow_run.head_branch }}
|
||||
cancel-in-progress: false
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
if: >
|
||||
github.repository == 'Comfy-Org/ComfyUI_frontend' &&
|
||||
github.event.workflow_run.event == 'push' &&
|
||||
github.event.workflow_run.head_branch == 'main' &&
|
||||
(github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure')
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
permissions:
|
||||
pages: write
|
||||
id-token: write
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Download merged Playwright report
|
||||
uses: dawidd6/action-download-artifact@0bd50d53a6d7fb5cb921e607957e9cc12b4ce392 # v12
|
||||
with:
|
||||
run_id: ${{ github.event.workflow_run.id }}
|
||||
name: playwright-report-chromium
|
||||
path: dashboard-site/playwright-report
|
||||
if_no_artifact_found: warn
|
||||
|
||||
- name: Check Playwright report was found
|
||||
id: report
|
||||
run: |
|
||||
if [ -f dashboard-site/playwright-report/index.html ]; then
|
||||
echo "found=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "found=false" >> "$GITHUB_OUTPUT"
|
||||
echo "No merged Playwright report artifact found for this run; skipping the dashboard deploy so the existing Pages deployment isn't wiped out." >> "$GITHUB_STEP_SUMMARY"
|
||||
fi
|
||||
|
||||
- name: Assemble dashboard index
|
||||
if: steps.report.outputs.found == 'true'
|
||||
run: cp scripts/cicd/dashboard/index.html dashboard-site/index.html
|
||||
|
||||
- name: Upload to GitHub Pages
|
||||
if: steps.report.outputs.found == 'true'
|
||||
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1
|
||||
with:
|
||||
path: dashboard-site
|
||||
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
if: steps.report.outputs.found == 'true'
|
||||
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5
|
||||
@@ -10,11 +10,12 @@ const PAYMENT_STATUSES = ['success', 'failed'] as const
|
||||
const LOCALE_PREFIXES = LOCALES.map((locale) =>
|
||||
locale === DEFAULT_LOCALE ? '' : `/${locale}`
|
||||
)
|
||||
const SITEMAP_EXCLUDED_PATHNAMES = new Set(
|
||||
LOCALE_PREFIXES.flatMap((prefix) =>
|
||||
const SITEMAP_EXCLUDED_PATHNAMES = new Set([
|
||||
...LOCALE_PREFIXES.flatMap((prefix) =>
|
||||
PAYMENT_STATUSES.map((status) => `${prefix}/payment/${status}`)
|
||||
)
|
||||
)
|
||||
),
|
||||
'/individual-submission'
|
||||
])
|
||||
|
||||
function isExcludedFromSitemap(page: string): boolean {
|
||||
const pathname = new URL(page).pathname.replace(/\/$/, '')
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import Button from '../ui/button/Button.vue'
|
||||
|
||||
const { href, label } = defineProps<{
|
||||
href: string
|
||||
label: string
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mt-2 flex justify-center">
|
||||
<Button as="a" :href variant="default" size="lg">
|
||||
{{ label }}
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,12 +1,25 @@
|
||||
<script setup lang="ts">
|
||||
const { title } = defineProps<{ title: string }>()
|
||||
import type { HTMLAttributes } from 'vue'
|
||||
import { cn } from '@comfyorg/tailwind-utils'
|
||||
|
||||
const { title, class: className } = defineProps<{
|
||||
title: string
|
||||
class?: HTMLAttributes['class']
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section
|
||||
class="flex items-center justify-center px-6 pt-20 pb-16 lg:pt-32 lg:pb-24"
|
||||
>
|
||||
<h1 class="text-primary-comfy-canvas text-4xl font-light lg:text-6xl">
|
||||
<h1
|
||||
:class="
|
||||
cn(
|
||||
'text-4xl font-light text-primary-comfy-canvas lg:text-6xl',
|
||||
className
|
||||
)
|
||||
"
|
||||
>
|
||||
{{ title }}
|
||||
</h1>
|
||||
</section>
|
||||
|
||||
60
apps/website/src/pages/individual-submission.astro
Normal file
60
apps/website/src/pages/individual-submission.astro
Normal file
@@ -0,0 +1,60 @@
|
||||
---
|
||||
import BaseLayout from '../layouts/BaseLayout.astro'
|
||||
import PlansPricingCta from '../components/individual-submission/PlansPricingCta.vue'
|
||||
import HeroSection from '../components/legal/HeroSection.vue'
|
||||
import { getRoutes } from '../config/routes'
|
||||
|
||||
const routes = getRoutes('en')
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
title="Thanks for reaching out - Comfy"
|
||||
description="Thanks for reaching out. Based on what you shared, one of our self-serve plans is probably a better fit."
|
||||
noindex
|
||||
>
|
||||
<HeroSection title="Thanks for reaching out." class="text-center" />
|
||||
|
||||
<section class="-mt-8 px-6 pb-24 lg:-mt-12 lg:pb-40">
|
||||
<div
|
||||
class="text-primary-comfy-canvas mx-auto flex max-w-2xl flex-col gap-6 text-center text-base font-light lg:text-lg"
|
||||
>
|
||||
<p>
|
||||
Based on what you shared, one of our self-serve plans is probably a
|
||||
better fit.
|
||||
<strong class="text-primary-comfy-yellow font-semibold italic">
|
||||
Standard</strong
|
||||
>,
|
||||
<strong class="text-primary-comfy-yellow font-semibold italic">
|
||||
Creator</strong
|
||||
>, and
|
||||
<strong class="text-primary-comfy-yellow font-semibold italic">
|
||||
Pro</strong
|
||||
> for individual creators, plus our new
|
||||
<strong class="text-primary-comfy-yellow font-semibold italic">
|
||||
Teams</strong
|
||||
> plan for multiple users under shared billing.
|
||||
</p>
|
||||
|
||||
<PlansPricingCta
|
||||
href={routes.cloudPricing}
|
||||
label="See plans and pricing →"
|
||||
/>
|
||||
|
||||
<p class="text-primary-warm-gray mt-8 text-sm">
|
||||
Still think you have an enterprise need?<br /> We're happy to assist. Email: <a
|
||||
href="mailto:gtm-team@comfy.org"
|
||||
class="text-primary-comfy-yellow whitespace-nowrap underline underline-offset-4 hover:no-underline"
|
||||
>gtm-team@comfy.org</a
|
||||
>
|
||||
</p>
|
||||
|
||||
<p class="text-primary-warm-gray text-sm">
|
||||
Need help with something else? Email: <a
|
||||
href="mailto:support@comfy.org"
|
||||
class="text-primary-comfy-yellow whitespace-nowrap underline underline-offset-4 hover:no-underline"
|
||||
>support@comfy.org</a
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
</BaseLayout>
|
||||
57
apps/website/src/pages/zh-CN/individual-submission.astro
Normal file
57
apps/website/src/pages/zh-CN/individual-submission.astro
Normal file
@@ -0,0 +1,57 @@
|
||||
---
|
||||
import BaseLayout from '../../layouts/BaseLayout.astro'
|
||||
import PlansPricingCta from '../../components/individual-submission/PlansPricingCta.vue'
|
||||
import HeroSection from '../../components/legal/HeroSection.vue'
|
||||
import { getRoutes } from '../../config/routes'
|
||||
|
||||
const routes = getRoutes('zh-CN')
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
title="感谢您的联系 - Comfy"
|
||||
description="感谢您的联系。根据您提供的信息,我们的自助服务套餐之一可能更适合您。"
|
||||
noindex
|
||||
>
|
||||
<HeroSection title="感谢您的联系。" class="text-center" />
|
||||
|
||||
<section class="-mt-8 px-6 pb-24 lg:-mt-12 lg:pb-40">
|
||||
<div
|
||||
class="text-primary-comfy-canvas mx-auto flex max-w-2xl flex-col gap-6 text-center text-base font-light lg:text-lg"
|
||||
>
|
||||
<p>
|
||||
根据您提供的信息,我们的自助服务套餐之一可能更适合您。面向个人创作者的
|
||||
<strong class="text-primary-comfy-yellow font-semibold italic">
|
||||
Standard</strong
|
||||
>、
|
||||
<strong class="text-primary-comfy-yellow font-semibold italic">
|
||||
Creator</strong
|
||||
>
|
||||
和
|
||||
<strong class="text-primary-comfy-yellow font-semibold italic">
|
||||
Pro</strong
|
||||
>,以及我们全新的
|
||||
<strong class="text-primary-comfy-yellow font-semibold italic">
|
||||
Teams</strong
|
||||
> 套餐,可让多位用户共享账单。
|
||||
</p>
|
||||
|
||||
<PlansPricingCta href={routes.cloudPricing} label="查看套餐与价格 →" />
|
||||
|
||||
<p class="text-primary-warm-gray mt-8 text-sm">
|
||||
仍然认为您有企业级需求?我们很乐意为您提供帮助。邮箱:<a
|
||||
href="mailto:gtm-team@comfy.org"
|
||||
class="text-primary-comfy-yellow whitespace-nowrap underline underline-offset-4 hover:no-underline"
|
||||
>gtm-team@comfy.org</a
|
||||
>
|
||||
</p>
|
||||
|
||||
<p class="text-primary-warm-gray text-sm">
|
||||
需要其他方面的帮助?邮箱:<a
|
||||
href="mailto:support@comfy.org"
|
||||
class="text-primary-comfy-yellow whitespace-nowrap underline underline-offset-4 hover:no-underline"
|
||||
>support@comfy.org</a
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
</BaseLayout>
|
||||
@@ -40,6 +40,11 @@ export type ComfyDesktop2TelemetryProperties = Record<
|
||||
ComfyDesktop2TelemetryValue | ComfyDesktop2TelemetryValue[]
|
||||
>
|
||||
|
||||
export type ComfyDesktop2FirebaseAuthState =
|
||||
| { status: 'pending' }
|
||||
| { status: 'signed_out' }
|
||||
| { status: 'signed_in'; userId: string }
|
||||
|
||||
export interface ComfyDesktop2TerminalBridge {
|
||||
subscribe(installationId?: string): Promise<TerminalRestore>
|
||||
unsubscribe(installationId?: string): Promise<void>
|
||||
@@ -60,6 +65,7 @@ export interface ComfyDesktop2LogsBridge {
|
||||
|
||||
export interface ComfyDesktop2TelemetryBridge {
|
||||
capture(event: string, properties?: ComfyDesktop2TelemetryProperties): void
|
||||
reportFirebaseAuthState?(state: ComfyDesktop2FirebaseAuthState): void
|
||||
}
|
||||
|
||||
export interface ComfyDesktop2Bridge {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@comfyorg/comfyui-desktop-bridge-types",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"description": "TypeScript definitions for the Comfy Desktop hosted frontend bridge",
|
||||
"homepage": "https://comfy.org",
|
||||
"license": "MIT",
|
||||
|
||||
126
scripts/cicd/dashboard/index.html
Normal file
126
scripts/cicd/dashboard/index.html
Normal file
@@ -0,0 +1,126 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="robots" content="noindex" />
|
||||
<title>ComfyUI_frontend CI Dashboard</title>
|
||||
<style>
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
--bg: #ffffff;
|
||||
--fg: #1a1a1a;
|
||||
--muted: #59636e;
|
||||
--border: #d8dee4;
|
||||
--card-bg: #f6f8fa;
|
||||
--link: #0969da;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg: #0d1117;
|
||||
--fg: #e6edf3;
|
||||
--muted: #9198a1;
|
||||
--border: #30363d;
|
||||
--card-bg: #161b22;
|
||||
--link: #4493f8;
|
||||
}
|
||||
}
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 2.5rem 1.5rem;
|
||||
background: var(--bg);
|
||||
color: var(--fg);
|
||||
font-family:
|
||||
-apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial,
|
||||
sans-serif;
|
||||
line-height: 1.5;
|
||||
}
|
||||
main {
|
||||
max-width: 40rem;
|
||||
margin: 0 auto;
|
||||
}
|
||||
h1 {
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
p.lede {
|
||||
color: var(--muted);
|
||||
margin-top: 0;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
ul.reports {
|
||||
list-style: none;
|
||||
margin: 0 0 2rem;
|
||||
padding: 0;
|
||||
display: grid;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
ul.reports li {
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
background: var(--card-bg);
|
||||
padding: 1rem 1.25rem;
|
||||
}
|
||||
ul.reports a {
|
||||
color: var(--link);
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
}
|
||||
ul.reports a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
ul.reports .description {
|
||||
color: var(--muted);
|
||||
font-size: 0.9rem;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
footer {
|
||||
color: var(--muted);
|
||||
font-size: 0.85rem;
|
||||
border-top: 1px solid var(--border);
|
||||
padding-top: 1rem;
|
||||
}
|
||||
code {
|
||||
background: var(--card-bg);
|
||||
padding: 0.1rem 0.35rem;
|
||||
border-radius: 4px;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>ComfyUI_frontend CI Dashboard</h1>
|
||||
<p class="lede">
|
||||
Persistent links to CI-generated reports and tools for the
|
||||
<code>main</code> branch, rebuilt on every push.
|
||||
</p>
|
||||
|
||||
<ul class="reports">
|
||||
<li>
|
||||
<a href="https://main.comfy-storybook.pages.dev">Storybook</a>
|
||||
<div class="description">
|
||||
Component library, built and deployed from
|
||||
<code>ci-tests-storybook.yaml</code>.
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<a href="./playwright-report/">Playwright report</a>
|
||||
<div class="description">
|
||||
Merged chromium E2E report from the latest <code>main</code> run of
|
||||
<code>ci-tests-e2e.yaml</code>.
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<footer>
|
||||
More report types (coverage, bundle size, lint, etc.) will be added here
|
||||
in follow-up PRs as they get a persistent, hosted home. This page is
|
||||
intentionally minimal for now.
|
||||
</footer>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
configValueOrDefault,
|
||||
remoteConfig
|
||||
} from '@/platform/remoteConfig/remoteConfig'
|
||||
import { syncHostUserIdWithFirebaseAuth } from '@/platform/telemetry/hostUserIdSync'
|
||||
import '@/lib/litegraph/public/css/litegraph.css'
|
||||
import router from '@/router'
|
||||
import { isDesktop, isNightly } from '@/platform/distribution/types'
|
||||
@@ -141,6 +142,10 @@ app
|
||||
modules: [VueFireAuth()]
|
||||
})
|
||||
|
||||
if (isCloud && hasHostTelemetryBridge) {
|
||||
syncHostUserIdWithFirebaseAuth()
|
||||
}
|
||||
|
||||
LGraph.proxyWidgetMigrationFlush = (hostNode, nodeData) =>
|
||||
flushProxyWidgetMigration({
|
||||
hostNode,
|
||||
|
||||
183
src/platform/telemetry/hostUserIdSync.test.ts
Normal file
183
src/platform/telemetry/hostUserIdSync.test.ts
Normal file
@@ -0,0 +1,183 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type * as VueModule from 'vue'
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
type MockAuthStore = {
|
||||
isInitialized: boolean
|
||||
currentUser: { uid: string } | null
|
||||
}
|
||||
|
||||
const hoisted = vi.hoisted(() => ({
|
||||
authStore: null as unknown as MockAuthStore
|
||||
}))
|
||||
|
||||
vi.mock('@/stores/authStore', async () => {
|
||||
const { reactive } = await vi.importActual<typeof VueModule>('vue')
|
||||
hoisted.authStore = reactive<MockAuthStore>({
|
||||
isInitialized: false,
|
||||
currentUser: null
|
||||
})
|
||||
return { useAuthStore: () => hoisted.authStore }
|
||||
})
|
||||
|
||||
import { syncHostUserIdWithFirebaseAuth } from './hostUserIdSync'
|
||||
|
||||
const stopHandles: Array<() => void> = []
|
||||
|
||||
function installTelemetryBridge() {
|
||||
const reportFirebaseAuthState = vi.fn()
|
||||
window.__comfyDesktop2 = {
|
||||
isRemote: () => false,
|
||||
Telemetry: {
|
||||
capture: vi.fn(),
|
||||
reportFirebaseAuthState
|
||||
}
|
||||
}
|
||||
return { reportFirebaseAuthState }
|
||||
}
|
||||
|
||||
function startSync(): void {
|
||||
const stop = syncHostUserIdWithFirebaseAuth()
|
||||
if (stop) stopHandles.push(stop)
|
||||
}
|
||||
|
||||
describe('host user ID sync', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
hoisted.authStore.isInitialized = false
|
||||
hoisted.authStore.currentUser = null
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
while (stopHandles.length) stopHandles.pop()?.()
|
||||
delete window.__comfyDesktop2
|
||||
})
|
||||
|
||||
it('waits for Firebase auth initialization before reporting a user', async () => {
|
||||
const { reportFirebaseAuthState } = installTelemetryBridge()
|
||||
startSync()
|
||||
|
||||
expect(reportFirebaseAuthState).toHaveBeenCalledOnce()
|
||||
expect(reportFirebaseAuthState).toHaveBeenLastCalledWith({
|
||||
status: 'pending'
|
||||
})
|
||||
|
||||
hoisted.authStore.currentUser = { uid: 'firebase-user-a' }
|
||||
await nextTick()
|
||||
|
||||
expect(reportFirebaseAuthState).toHaveBeenCalledOnce()
|
||||
|
||||
hoisted.authStore.isInitialized = true
|
||||
await nextTick()
|
||||
|
||||
expect(reportFirebaseAuthState).toHaveBeenLastCalledWith({
|
||||
status: 'signed_in',
|
||||
userId: 'firebase-user-a'
|
||||
})
|
||||
})
|
||||
|
||||
it('reports a restored Firebase session immediately', () => {
|
||||
const { reportFirebaseAuthState } = installTelemetryBridge()
|
||||
hoisted.authStore.currentUser = { uid: 'firebase-user-a' }
|
||||
hoisted.authStore.isInitialized = true
|
||||
|
||||
startSync()
|
||||
|
||||
expect(reportFirebaseAuthState.mock.calls).toEqual([
|
||||
[{ status: 'pending' }],
|
||||
[{ status: 'signed_in', userId: 'firebase-user-a' }]
|
||||
])
|
||||
})
|
||||
|
||||
it('reports an initially signed-out Firebase session', () => {
|
||||
const { reportFirebaseAuthState } = installTelemetryBridge()
|
||||
hoisted.authStore.isInitialized = true
|
||||
|
||||
startSync()
|
||||
|
||||
expect(reportFirebaseAuthState.mock.calls).toEqual([
|
||||
[{ status: 'pending' }],
|
||||
[{ status: 'signed_out' }]
|
||||
])
|
||||
})
|
||||
|
||||
it('reports signed out when Firebase finishes initialization', async () => {
|
||||
const { reportFirebaseAuthState } = installTelemetryBridge()
|
||||
startSync()
|
||||
|
||||
expect(reportFirebaseAuthState).toHaveBeenCalledOnce()
|
||||
|
||||
hoisted.authStore.isInitialized = true
|
||||
await nextTick()
|
||||
|
||||
expect(reportFirebaseAuthState).toHaveBeenLastCalledWith({
|
||||
status: 'signed_out'
|
||||
})
|
||||
})
|
||||
|
||||
it('reports account switches, logout, and subsequent login', async () => {
|
||||
const { reportFirebaseAuthState } = installTelemetryBridge()
|
||||
hoisted.authStore.currentUser = { uid: 'firebase-user-a' }
|
||||
hoisted.authStore.isInitialized = true
|
||||
startSync()
|
||||
|
||||
hoisted.authStore.currentUser = { uid: 'firebase-user-b' }
|
||||
await nextTick()
|
||||
|
||||
expect(reportFirebaseAuthState).toHaveBeenLastCalledWith({
|
||||
status: 'signed_in',
|
||||
userId: 'firebase-user-b'
|
||||
})
|
||||
|
||||
hoisted.authStore.currentUser = null
|
||||
await nextTick()
|
||||
|
||||
expect(reportFirebaseAuthState).toHaveBeenLastCalledWith({
|
||||
status: 'signed_out'
|
||||
})
|
||||
|
||||
hoisted.authStore.currentUser = { uid: 'firebase-user-c' }
|
||||
await nextTick()
|
||||
|
||||
expect(reportFirebaseAuthState.mock.calls).toEqual([
|
||||
[{ status: 'pending' }],
|
||||
[{ status: 'signed_in', userId: 'firebase-user-a' }],
|
||||
[{ status: 'signed_in', userId: 'firebase-user-b' }],
|
||||
[{ status: 'signed_out' }],
|
||||
[{ status: 'signed_in', userId: 'firebase-user-c' }]
|
||||
])
|
||||
})
|
||||
|
||||
it('does not report again when Firebase replaces the user object with the same UID', async () => {
|
||||
const { reportFirebaseAuthState } = installTelemetryBridge()
|
||||
hoisted.authStore.currentUser = { uid: 'firebase-user-a' }
|
||||
hoisted.authStore.isInitialized = true
|
||||
startSync()
|
||||
|
||||
hoisted.authStore.currentUser = { uid: 'firebase-user-a' }
|
||||
await nextTick()
|
||||
|
||||
expect(reportFirebaseAuthState.mock.calls).toEqual([
|
||||
[{ status: 'pending' }],
|
||||
[{ status: 'signed_in', userId: 'firebase-user-a' }]
|
||||
])
|
||||
})
|
||||
|
||||
it('does not let a host reporting failure interrupt Firebase state sync', async () => {
|
||||
const { reportFirebaseAuthState } = installTelemetryBridge()
|
||||
reportFirebaseAuthState.mockImplementationOnce(() => {
|
||||
throw new Error('host unavailable')
|
||||
})
|
||||
|
||||
expect(() => startSync()).not.toThrow()
|
||||
|
||||
hoisted.authStore.currentUser = { uid: 'firebase-user-a' }
|
||||
hoisted.authStore.isInitialized = true
|
||||
await nextTick()
|
||||
|
||||
expect(reportFirebaseAuthState).toHaveBeenLastCalledWith({
|
||||
status: 'signed_in',
|
||||
userId: 'firebase-user-a'
|
||||
})
|
||||
})
|
||||
})
|
||||
49
src/platform/telemetry/hostUserIdSync.ts
Normal file
49
src/platform/telemetry/hostUserIdSync.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { watch } from 'vue'
|
||||
import type { WatchStopHandle } from 'vue'
|
||||
|
||||
import { useAuthStore } from '@/stores/authStore'
|
||||
|
||||
function safelyReportFirebaseAuthState(report: () => void): void {
|
||||
try {
|
||||
report()
|
||||
} catch {
|
||||
// A host bridge failure must not block renderer startup or Firebase auth.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep the Desktop main-process telemetry identity aligned with Firebase auth.
|
||||
* Must run after Pinia and VueFire are installed.
|
||||
*/
|
||||
export function syncHostUserIdWithFirebaseAuth(): WatchStopHandle | undefined {
|
||||
const telemetry = window.__comfyDesktop2?.Telemetry
|
||||
if (!telemetry) return
|
||||
|
||||
// Register this Cloud renderer before Firebase resolves. Desktop may host
|
||||
// multiple Cloud main frames whose isolated browser partitions have
|
||||
// different auth states, so main owns all cross-WebContents arbitration.
|
||||
safelyReportFirebaseAuthState(() =>
|
||||
telemetry.reportFirebaseAuthState?.({ status: 'pending' })
|
||||
)
|
||||
|
||||
const authStore = useAuthStore()
|
||||
|
||||
return watch(
|
||||
() =>
|
||||
authStore.isInitialized
|
||||
? (authStore.currentUser?.uid ?? null)
|
||||
: undefined,
|
||||
(userId) => {
|
||||
if (userId === undefined) return
|
||||
|
||||
safelyReportFirebaseAuthState(() =>
|
||||
telemetry.reportFirebaseAuthState?.(
|
||||
userId === null
|
||||
? { status: 'signed_out' }
|
||||
: { status: 'signed_in', userId }
|
||||
)
|
||||
)
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
const hoisted = vi.hoisted(() => {
|
||||
const analytics = {
|
||||
identify: vi.fn().mockResolvedValue(undefined),
|
||||
page: vi.fn(),
|
||||
track: vi.fn().mockResolvedValue(undefined),
|
||||
reset: vi.fn(),
|
||||
register: vi.fn().mockResolvedValue(undefined)
|
||||
@@ -108,6 +109,89 @@ describe('CustomerIoTelemetryProvider', () => {
|
||||
expect(hoisted.analytics.register).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('reports the current page after registering the in-app plugin', async () => {
|
||||
const provider = createProvider()
|
||||
provider.trackPageView('workflow_editor', {
|
||||
path: 'https://cloud.comfy.org/'
|
||||
})
|
||||
await vi.dynamicImportSettled()
|
||||
|
||||
expect(hoisted.analytics.page).toHaveBeenCalledOnce()
|
||||
expect(hoisted.analytics.page).toHaveBeenCalledWith()
|
||||
expect(hoisted.analytics.register.mock.invocationCallOrder[0]).toBeLessThan(
|
||||
hoisted.analytics.page.mock.invocationCallOrder[0]
|
||||
)
|
||||
})
|
||||
|
||||
it('queues page views until the in-app plugin is registered', async () => {
|
||||
let resolveRegistration: (() => void) | undefined
|
||||
const registration = new Promise<void>((resolve) => {
|
||||
resolveRegistration = resolve
|
||||
})
|
||||
hoisted.analytics.register.mockReturnValue(registration)
|
||||
const provider = createProvider()
|
||||
await vi.dynamicImportSettled()
|
||||
|
||||
provider.trackPageView('workflow_editor', {
|
||||
path: 'https://cloud.comfy.org/'
|
||||
})
|
||||
expect(hoisted.analytics.page).not.toHaveBeenCalled()
|
||||
|
||||
resolveRegistration?.()
|
||||
await vi.waitFor(() =>
|
||||
expect(hoisted.analytics.page).toHaveBeenCalledOnce()
|
||||
)
|
||||
})
|
||||
|
||||
it('reports client-side route changes', async () => {
|
||||
const provider = createProvider()
|
||||
await vi.dynamicImportSettled()
|
||||
|
||||
expect(hoisted.analytics.page).not.toHaveBeenCalled()
|
||||
|
||||
provider.trackPageView('workflow_editor', {
|
||||
path: 'https://cloud.comfy.org/'
|
||||
})
|
||||
|
||||
expect(hoisted.analytics.page).toHaveBeenCalledOnce()
|
||||
expect(hoisted.analytics.page).toHaveBeenCalledWith()
|
||||
})
|
||||
|
||||
it('continues tracking events and page views when the in-app plugin fails to register', async () => {
|
||||
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||
const registrationError = new Error('in-app setup failed')
|
||||
hoisted.analytics.register.mockRejectedValue(registrationError)
|
||||
const provider = createProvider()
|
||||
provider.trackWorkflowExecution()
|
||||
provider.trackPageView('workflow_editor', {
|
||||
path: 'https://cloud.comfy.org/'
|
||||
})
|
||||
|
||||
await vi.dynamicImportSettled()
|
||||
|
||||
expect(hoisted.analytics.track).toHaveBeenCalledWith(
|
||||
'execution_start',
|
||||
SOURCE
|
||||
)
|
||||
expect(hoisted.analytics.page).toHaveBeenCalledOnce()
|
||||
expect(consoleError).toHaveBeenCalledWith(
|
||||
'Failed to initialize Customer.io in-app plugin:',
|
||||
registrationError
|
||||
)
|
||||
|
||||
provider.trackAddApiCreditButtonClicked()
|
||||
await vi.waitFor(() =>
|
||||
expect(hoisted.analytics.track).toHaveBeenCalledWith(
|
||||
'app:add_api_credit_button_clicked',
|
||||
SOURCE
|
||||
)
|
||||
)
|
||||
provider.trackPageView('settings', {
|
||||
path: 'https://cloud.comfy.org/settings'
|
||||
})
|
||||
expect(hoisted.analytics.page).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('does not initialize without a write key', async () => {
|
||||
const provider = createProvider({ customer_io: { site_id: SITE_ID } })
|
||||
await vi.dynamicImportSettled()
|
||||
|
||||
@@ -8,6 +8,7 @@ import { TelemetryEvents } from '../../types'
|
||||
import type {
|
||||
AuthMetadata,
|
||||
ExecutionSuccessMetadata,
|
||||
PageViewMetadata,
|
||||
ShareFlowMetadata,
|
||||
SubscriptionMetadata,
|
||||
TelemetryEventProperties,
|
||||
@@ -41,7 +42,9 @@ interface CustomerIoIdentity {
|
||||
export class CustomerIoTelemetryProvider implements TelemetryProvider {
|
||||
private analytics: AnalyticsBrowser | null = null
|
||||
private isEnabled = true
|
||||
private isPageViewTrackingReady = false
|
||||
private eventQueue: QueuedEvent[] = []
|
||||
private pageViewQueued = false
|
||||
private identifiedUser: CustomerIoIdentity | null = null
|
||||
private sessionIdentity: CustomerIoIdentity | null = null
|
||||
private operationQueue: Promise<void> = Promise.resolve()
|
||||
@@ -61,7 +64,7 @@ export class CustomerIoTelemetryProvider implements TelemetryProvider {
|
||||
void import('@customerio/cdp-analytics-browser')
|
||||
.then(({ AnalyticsBrowser, InAppPlugin }) => {
|
||||
const analytics = AnalyticsBrowser.load({ writeKey })
|
||||
void analytics.register(
|
||||
const inAppRegistration = analytics.register(
|
||||
InAppPlugin({
|
||||
siteId,
|
||||
events: null,
|
||||
@@ -97,6 +100,17 @@ export class CustomerIoTelemetryProvider implements TelemetryProvider {
|
||||
})
|
||||
|
||||
void this.flushQueue()
|
||||
void inAppRegistration
|
||||
.catch((error) => {
|
||||
console.error(
|
||||
'Failed to initialize Customer.io in-app plugin:',
|
||||
error
|
||||
)
|
||||
})
|
||||
.finally(() => {
|
||||
this.isPageViewTrackingReady = true
|
||||
this.flushPageView()
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Failed to load Customer.io:', error)
|
||||
@@ -198,6 +212,29 @@ export class CustomerIoTelemetryProvider implements TelemetryProvider {
|
||||
})
|
||||
}
|
||||
|
||||
private sendPageView(): void {
|
||||
void this.analytics?.page()?.catch((error) => {
|
||||
console.error('Failed to track Customer.io page view:', error)
|
||||
})
|
||||
}
|
||||
|
||||
private flushPageView(): void {
|
||||
if (!this.isPageViewTrackingReady || !this.pageViewQueued) {
|
||||
return
|
||||
}
|
||||
this.pageViewQueued = false
|
||||
this.sendPageView()
|
||||
}
|
||||
|
||||
trackPageView(_pageName: string, _properties?: PageViewMetadata): void {
|
||||
if (!this.isEnabled) return
|
||||
if (!this.isPageViewTrackingReady) {
|
||||
this.pageViewQueued = true
|
||||
return
|
||||
}
|
||||
this.sendPageView()
|
||||
}
|
||||
|
||||
trackAuth(metadata: AuthMetadata): void {
|
||||
const identity = metadata.user_id
|
||||
? {
|
||||
|
||||
Reference in New Issue
Block a user