|
1 | 1 | import { useState, useEffect, useCallback } from 'react'; |
2 | 2 | import { Trash2, Plus, RefreshCw, Terminal, CheckCircle2, Copy, Circle } from 'lucide-react'; |
3 | 3 | import { decryptKeys, maskKey } from '@/utils/crypto'; |
4 | | -import { fetchEncryptedKeys, fetchCurrentIndex, fetchCache, addKey, removeKey, useKey, refreshCache } from '@/utils/api'; |
| 4 | +import { fetchEncryptedKeys, fetchCurrentIndex, fetchCache, addKey, removeKey, useKey, refreshCache, isElectron } from '@/utils/api'; |
5 | 5 | import type { KeyInfo, KeyUsage } from '@/utils/api'; |
6 | 6 | import { cn } from '@/lib/utils'; |
7 | 7 | import { Button } from '@/components/ui/button'; |
@@ -110,10 +110,12 @@ export default function KeyList() { |
110 | 110 | const [newKey, setNewKey] = useState(''); |
111 | 111 | const [adding, setAdding] = useState(false); |
112 | 112 |
|
113 | | - const loadData = useCallback(async (showRefreshing = false, autoRefresh = true) => { |
| 113 | + const loadData = useCallback(async (showRefreshing = false, autoRefresh = true, silent = false) => { |
114 | 114 | try { |
115 | | - if (showRefreshing) setRefreshing(true); |
116 | | - else setLoading(true); |
| 115 | + if (!silent) { |
| 116 | + if (showRefreshing) setRefreshing(true); |
| 117 | + else setLoading(true); |
| 118 | + } |
117 | 119 | setError(null); |
118 | 120 |
|
119 | 121 | const [encryptedData, currentIndex, cache] = await Promise.all([ |
@@ -157,6 +159,14 @@ export default function KeyList() { |
157 | 159 |
|
158 | 160 | useEffect(() => { |
159 | 161 | loadData(); |
| 162 | + |
| 163 | + // Listen for updates from tray menu (Electron only) |
| 164 | + if (isElectron) { |
| 165 | + const unsubscribe = window.oroio.on('keys-updated', () => { |
| 166 | + loadData(false, false, true); |
| 167 | + }); |
| 168 | + return unsubscribe; |
| 169 | + } |
160 | 170 | }, [loadData]); |
161 | 171 |
|
162 | 172 | const handleRefresh = async () => { |
|
0 commit comments