Skip to content

Commit

Permalink
Use localstorage cache for claude config
Browse files Browse the repository at this point in the history
Resolves #42
  • Loading branch information
ColinMcNeil committed Feb 3, 2025
1 parent e7aa07f commit 6ffbc83
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/extension/ui/src/components/ClaudeConfigSyncStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ const getClaudeConfigPath = (client: v1.DockerDesktopClient) => {
const getClaudeConfig = async (client: v1.DockerDesktopClient) => {
const path = getClaudeConfigPath(client)
const result = await client.docker.cli.exec('run', ['--rm', '--mount', `type=bind,source="${path}",target=/config.json`, 'alpine:latest', 'sh', '-c', `"cat /config.json"`])
localStorage.setItem('claude-config-sync-status-path', result.stdout)
return result.stdout
}


export const setNeverShowAgain = (value: boolean) => {
localStorage.setItem('claude-config-sync-status-never-show-again', value.toString())
}
Expand All @@ -66,18 +68,26 @@ export const ClaudeConfigSyncStatus = ({ client, setHasConfig }: { client: v1.Do
const [configPath, setConfigPath] = useState<string | null>(null)
useEffect(() => {
const refreshConfig = async () => {
const config = await getClaudeConfig(client)
const newConfig = JSON.parse(config)
setClaudeConfig(newConfig)
const cachedConfig = localStorage.getItem('claude-config')
try {
const config = cachedConfig ? JSON.parse(cachedConfig) : await getClaudeConfig(client)
const newConfig = JSON.parse(config)
setClaudeConfig(newConfig)
// Dumb cache, no way to see if config changed
localStorage.setItem('claude-config', config)
} catch (error) {
console.error('Error parsing config. Using cached config if available.', error)
if (cachedConfig) {
setClaudeConfig(JSON.parse(cachedConfig))
}
}
}
refreshConfig()

refreshConfig()

const interval = setInterval(() => {
refreshConfig()
}, 30000)


return () => {
clearInterval(interval)
}
Expand All @@ -103,7 +113,6 @@ export const ClaudeConfigSyncStatus = ({ client, setHasConfig }: { client: v1.Do
setStatus({ state: 'missing docker_mcp', message: 'No Docker servers found in Claude Desktop Config', color: 'error' })
setHasConfig(false)
}

}
}
}, [claudeConfig])
Expand Down

0 comments on commit 6ffbc83

Please sign in to comment.