Files
tolaria/src/hooks/useSettings.ts
lucaronin 2799d8f0a6 feat: add canary release channel and local feature flags
Add update_channel setting (stable/canary) to Settings with UI toggle.
Stable channel uses Tauri updater plugin; canary fetches latest-canary.json
and opens GitHub release page for manual download. Add useFeatureFlag()
hook with localStorage overrides and compile-time defaults (no remote
dependencies). Add release-canary.yml CI workflow for canary branch builds.
Update stable workflow to preserve latest-canary.json on GH Pages.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 17:51:33 +01:00

54 lines
1.5 KiB
TypeScript

import { useCallback, useEffect, useState } from 'react'
import { invoke } from '@tauri-apps/api/core'
import { isTauri, mockInvoke } from '../mock-tauri'
import type { Settings } from '../types'
function tauriCall<T>(command: string, tauriArgs: Record<string, unknown>, mockArgs?: Record<string, unknown>): Promise<T> {
return isTauri() ? invoke<T>(command, tauriArgs) : mockInvoke<T>(command, mockArgs ?? tauriArgs)
}
const EMPTY_SETTINGS: Settings = {
anthropic_key: null,
openai_key: null,
google_key: null,
github_token: null,
github_username: null,
auto_pull_interval_minutes: null,
telemetry_consent: null,
crash_reporting_enabled: null,
analytics_enabled: null,
anonymous_id: null,
update_channel: null,
}
export function useSettings() {
const [settings, setSettings] = useState<Settings>(EMPTY_SETTINGS)
const [loaded, setLoaded] = useState(false)
const loadSettings = useCallback(async () => {
try {
const s = await tauriCall<Settings>('get_settings', {})
setSettings(s)
} catch (err) {
console.warn('Failed to load settings:', err)
} finally {
setLoaded(true)
}
}, [])
useEffect(() => {
loadSettings()
}, [loadSettings])
const saveSettings = useCallback(async (newSettings: Settings) => {
try {
await tauriCall<null>('save_settings', { settings: newSettings })
setSettings(newSettings)
} catch (err) {
console.error('Failed to save settings:', err)
}
}, [])
return { settings, loaded, saveSettings }
}