MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / WebPlatformAdapter

Class WebPlatformAdapter

src/services/platform/web.ts:19–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17declare const __APP_VERSION__: string
18
19export class WebPlatformAdapter implements PlatformAdapter {
20 async getVersion(): Promise<string> {
21 return typeof __APP_VERSION__ !== 'undefined' ? __APP_VERSION__ : 'web'
22 }
23
24 async fetchRemoteConfig(url: string): Promise<RemoteConfigResult> {
25 try {
26 const res = await fetch(url)
27 if (!res.ok) return { success: false, error: `HTTP ${res.status}` }
28 const data = await res.json()
29 return { success: true, data }
30 } catch (e) {
31 return { success: false, error: String(e) }
32 }
33 }
34
35 setThemeSource(_theme: 'system' | 'light' | 'dark'): void {
36 // Web 模式下主题通过 CSS class 切换,不需要 IPC
37 }
38
39 async getOpenAtLogin(): Promise<boolean> {
40 return false
41 }
42
43 async setOpenAtLogin(_enabled: boolean): Promise<{ success: boolean; error?: string }> {
44 return { success: false, error: 'Not available in web mode' }
45 }
46
47 async getAnalyticsEnabled(): Promise<boolean> {
48 try {
49 const resp = await fetchWithAuth('/_web/telemetry/enabled')
50 const data = (await resp.json()) as { enabled?: boolean }
51 return data.enabled === true
52 } catch {
53 return false
54 }
55 }
56
57 async setAnalyticsEnabled(enabled: boolean): Promise<{ success: boolean }> {
58 try {
59 const resp = await fetchWithAuth('/_web/telemetry/enabled', {
60 method: 'POST',
61 headers: { 'Content-Type': 'application/json' },
62 body: JSON.stringify({ enabled }),
63 })
64 return (await resp.json()) as { success: boolean }
65 } catch {
66 return { success: false }
67 }
68 }
69
70 async trackDailyActive(locale: string): Promise<void> {
71 await fetchWithAuth('/_web/telemetry/track', {
72 method: 'POST',
73 headers: { 'Content-Type': 'application/json' },
74 body: JSON.stringify({ eventName: 'app_active', properties: { platform: 'cli-web', locale } }),
75 }).catch(() => {})
76 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected