Skip to content

Commit 6ffbc83

Browse files
committed
Use localstorage cache for claude config
Resolves #42
1 parent e7aa07f commit 6ffbc83

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/extension/ui/src/components/ClaudeConfigSyncStatus.tsx

+16-7
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ const getClaudeConfigPath = (client: v1.DockerDesktopClient) => {
4747
const getClaudeConfig = async (client: v1.DockerDesktopClient) => {
4848
const path = getClaudeConfigPath(client)
4949
const result = await client.docker.cli.exec('run', ['--rm', '--mount', `type=bind,source="${path}",target=/config.json`, 'alpine:latest', 'sh', '-c', `"cat /config.json"`])
50+
localStorage.setItem('claude-config-sync-status-path', result.stdout)
5051
return result.stdout
5152
}
5253

54+
5355
export const setNeverShowAgain = (value: boolean) => {
5456
localStorage.setItem('claude-config-sync-status-never-show-again', value.toString())
5557
}
@@ -66,18 +68,26 @@ export const ClaudeConfigSyncStatus = ({ client, setHasConfig }: { client: v1.Do
6668
const [configPath, setConfigPath] = useState<string | null>(null)
6769
useEffect(() => {
6870
const refreshConfig = async () => {
69-
const config = await getClaudeConfig(client)
70-
const newConfig = JSON.parse(config)
71-
setClaudeConfig(newConfig)
71+
const cachedConfig = localStorage.getItem('claude-config')
72+
try {
73+
const config = cachedConfig ? JSON.parse(cachedConfig) : await getClaudeConfig(client)
74+
const newConfig = JSON.parse(config)
75+
setClaudeConfig(newConfig)
76+
// Dumb cache, no way to see if config changed
77+
localStorage.setItem('claude-config', config)
78+
} catch (error) {
79+
console.error('Error parsing config. Using cached config if available.', error)
80+
if (cachedConfig) {
81+
setClaudeConfig(JSON.parse(cachedConfig))
82+
}
83+
}
7284
}
73-
refreshConfig()
7485

86+
refreshConfig()
7587

7688
const interval = setInterval(() => {
7789
refreshConfig()
7890
}, 30000)
79-
80-
8191
return () => {
8292
clearInterval(interval)
8393
}
@@ -103,7 +113,6 @@ export const ClaudeConfigSyncStatus = ({ client, setHasConfig }: { client: v1.Do
103113
setStatus({ state: 'missing docker_mcp', message: 'No Docker servers found in Claude Desktop Config', color: 'error' })
104114
setHasConfig(false)
105115
}
106-
107116
}
108117
}
109118
}, [claudeConfig])

0 commit comments

Comments
 (0)