- Add `release_channel` to Settings (Rust + TypeScript) - Add channel selector in Settings panel (alpha/beta/stable) - Pass `release_channel` as PostHog person property on identify - Add `isFeatureEnabled()` helper: alpha always true, beta/stable use PostHog flags with hardcoded fallback defaults - Update `useFeatureFlag` to delegate to PostHog-backed evaluation (localStorage overrides still work for dev/QA) - Create ADR-0042 (supersedes ADR-0017) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import { useEffect, useRef } from 'react'
|
|
import { invoke } from '@tauri-apps/api/core'
|
|
import { isTauri, mockInvoke } from '../mock-tauri'
|
|
import { initSentry, teardownSentry, initPostHog, teardownPostHog, updatePostHogIdentify, setReleaseChannel } from '../lib/telemetry'
|
|
import type { Settings } from '../types'
|
|
|
|
function tauriCall(command: string): Promise<void> {
|
|
return isTauri() ? invoke<void>(command) : mockInvoke<void>(command)
|
|
}
|
|
|
|
/**
|
|
* Initializes / tears down Sentry and PostHog reactively based on user settings.
|
|
* Call once in App after settings are loaded.
|
|
*/
|
|
export function useTelemetry(settings: Settings, loaded: boolean): void {
|
|
const prevCrash = useRef(false)
|
|
const prevAnalytics = useRef(false)
|
|
|
|
useEffect(() => {
|
|
if (!loaded) return
|
|
const crashEnabled = settings.crash_reporting_enabled === true
|
|
const analyticsEnabled = settings.analytics_enabled === true
|
|
const id = settings.anonymous_id
|
|
|
|
if (crashEnabled && id && !prevCrash.current) {
|
|
initSentry(id)
|
|
} else if (!crashEnabled && prevCrash.current) {
|
|
teardownSentry()
|
|
tauriCall('reinit_telemetry').catch(() => {})
|
|
}
|
|
|
|
const channel = settings.release_channel ?? 'stable'
|
|
setReleaseChannel(channel)
|
|
|
|
if (analyticsEnabled && id && !prevAnalytics.current) {
|
|
initPostHog(id, channel)
|
|
} else if (!analyticsEnabled && prevAnalytics.current) {
|
|
teardownPostHog()
|
|
} else if (analyticsEnabled && id) {
|
|
updatePostHogIdentify(channel)
|
|
}
|
|
|
|
prevCrash.current = crashEnabled
|
|
prevAnalytics.current = analyticsEnabled
|
|
}, [loaded, settings.crash_reporting_enabled, settings.analytics_enabled, settings.anonymous_id, settings.release_channel])
|
|
}
|