use indexedDB manager proxySwitch

This commit is contained in:
go0p
2026-08-06 15:11:35 +08:00
committed by go0p
parent a8ab3a2899
commit 841f663ed5
23 changed files with 1542 additions and 753 deletions
@@ -0,0 +1,59 @@
import { useState, useEffect } from 'react';
import { ProxyLog } from '@/types/proxy';
import { ProxyActionType } from '@/types/action';
export const useProxyLogs = () => {
const [proxyLogs, setProxyLogs] = useState<ProxyLog[]>([]);
useEffect(() => {
loadLogs();
// 监听日志更新
const handleLogsUpdate = () => {
loadLogs();
};
chrome.runtime.onMessage.addListener((message) => {
if (message.action === 'PROXY_LOGS_UPDATED') {
handleLogsUpdate();
}
});
return () => {
chrome.runtime.onMessage.removeListener(handleLogsUpdate);
};
}, []);
const loadLogs = async () => {
try {
console.log('Fetching proxy logs...');
const response = await chrome.runtime.sendMessage({
action: 'GET_PROXY_LOGS'
});
console.log('Received response:', response);
if (response.success) {
setProxyLogs(response.data || []);
} else {
console.error('Failed to load logs:', response.error);
}
} catch (error) {
console.error('Error loading logs:', error);
}
};
const handleClearLogs = async () => {
try {
await chrome.runtime.sendMessage({
action: ProxyActionType.CLEAR_PROXY_LOGS
});
setProxyLogs([]);
} catch (error) {
console.error('Error clearing logs:', error);
}
};
return {
proxyLogs,
handleClearLogs
};
};