Skip to content

Commit 0951cfd

Browse files
feat(#201): Sync clipboard monitor state with store.json on mount
1 parent fd7525b commit 0951cfd

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/app/core/record/chat/clipboard-monitor.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,32 @@
22
import { useTranslations } from 'next-intl'
33
import { Clipboard, ClipboardX } from 'lucide-react'
44
import { TooltipButton } from '@/components/tooltip-button'
5-
import { useState } from 'react'
5+
import { useState, useEffect } from 'react'
66
import { Store } from '@tauri-apps/plugin-store'
77

88
export function ClipboardMonitor() {
99
const t = useTranslations('record.chat.input.clipboardMonitor')
1010
const [isEnabled, setIsEnabled] = useState(true)
11+
12+
// Sync with store.json on mount
13+
useEffect(() => {
14+
const syncWithStore = async () => {
15+
try {
16+
const store = await Store.load('store.json')
17+
const storedValue = await store.get<boolean>('clipboardMonitor')
18+
19+
// Only update if the stored value exists and is different from the current state
20+
if (storedValue !== undefined && storedValue !== isEnabled) {
21+
setIsEnabled(storedValue)
22+
}
23+
} catch (error) {
24+
console.error('Failed to load clipboard monitor state from store:', error)
25+
}
26+
}
27+
28+
syncWithStore()
29+
}, [])
30+
1131

1232
const toggleClipboardMonitor = async () => {
1333
const newState = !isEnabled

0 commit comments

Comments
 (0)