mirror of
https://github.com/yaklang/yaklang-chrome-extension.git
synced 2026-09-22 03:10:43 +08:00
Improve proxy initialization with last used proxy restoration
This commit is contained in:
+13
-6
@@ -290,6 +290,16 @@ async function checkAndSetInitialProxy() {
|
|||||||
// 确保默认配置存在
|
// 确保默认配置存在
|
||||||
await ProxySettings.setDefaultConfigs();
|
await ProxySettings.setDefaultConfigs();
|
||||||
|
|
||||||
|
// 获取上次保存的代理配置
|
||||||
|
const lastProxy = await proxyStore.getCurrentProxy();
|
||||||
|
|
||||||
|
if (lastProxy) {
|
||||||
|
// 如果有上次的配置,恢复它
|
||||||
|
console.log('Restoring last proxy configuration:', lastProxy);
|
||||||
|
await handleSetProxyConfig(lastProxy, () => {});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 获取当前的代理设置
|
// 获取当前的代理设置
|
||||||
const settings = await getProxySettings();
|
const settings = await getProxySettings();
|
||||||
console.log('Current proxy settings:', settings);
|
console.log('Current proxy settings:', settings);
|
||||||
@@ -338,7 +348,7 @@ async function checkAndSetInitialProxy() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果没有检测到代理或已存在配置,则设置为系统代理
|
// 如果没有之前的配置也没有检测到代理,才设置为系统代理
|
||||||
await handleSetProxyConfig({
|
await handleSetProxyConfig({
|
||||||
id: 'system',
|
id: 'system',
|
||||||
name: '[系统代理]',
|
name: '[系统代理]',
|
||||||
@@ -346,9 +356,6 @@ async function checkAndSetInitialProxy() {
|
|||||||
enabled: true
|
enabled: true
|
||||||
}, () => {});
|
}, () => {});
|
||||||
|
|
||||||
// 设置认证监听
|
|
||||||
await ProxyAuth.setupAuthListener();
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error during initialization:', error);
|
console.error('Error during initialization:', error);
|
||||||
}
|
}
|
||||||
@@ -356,10 +363,10 @@ async function checkAndSetInitialProxy() {
|
|||||||
|
|
||||||
// 修改 setupProxyHandlers 函数
|
// 修改 setupProxyHandlers 函数
|
||||||
export function setupProxyHandlers() {
|
export function setupProxyHandlers() {
|
||||||
// 设置代理错误处理和认证
|
// 设置代理错误处理
|
||||||
ProxyAuth.setupErrorHandler();
|
ProxyAuth.setupErrorHandler();
|
||||||
|
// 设置认证监听
|
||||||
ProxyAuth.setupAuthListener();
|
ProxyAuth.setupAuthListener();
|
||||||
|
|
||||||
// 设置代理请求监听器
|
// 设置代理请求监听器
|
||||||
setupProxyRequestListener();
|
setupProxyRequestListener();
|
||||||
|
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ async function switchProxy(config) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 发送配置更改消息
|
||||||
await sendMessageWithRetry({
|
await sendMessageWithRetry({
|
||||||
action: ProxyActionType.SET_PROXY_CONFIG,
|
action: ProxyActionType.SET_PROXY_CONFIG,
|
||||||
config: proxyConfig
|
config: proxyConfig
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ export class ProxySettings {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
// 确保日志存储已初始化
|
// 确保日志存储已初始化
|
||||||
const logs = await proxyStore.getLogs(); // 使用 getLogs 而不是 getProxyLogs
|
const logs = await proxyStore.getLogs();
|
||||||
if (!logs || logs.length === 0) {
|
if (!logs || logs.length === 0) {
|
||||||
await proxyStore.clearLogs(); // 初始化日志存储
|
await proxyStore.clearLogs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user