From bac4dcf73ca1e55f01398f706f10089fb45d67a0 Mon Sep 17 00:00:00 2001 From: suyao Date: Wed, 12 Mar 2025 23:25:26 +0800 Subject: [PATCH] refactor(Proxy): Improve system proxy monitoring and configuration handling --- src/main/services/ProxyManager.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/services/ProxyManager.ts b/src/main/services/ProxyManager.ts index 6ad7807c32..5a839a1311 100644 --- a/src/main/services/ProxyManager.ts +++ b/src/main/services/ProxyManager.ts @@ -14,15 +14,13 @@ export class ProxyManager { private config: ProxyConfig private proxyAgent: HttpsProxyAgent | null = null private proxyUrl: string | null = null + private systemProxyInterval: NodeJS.Timeout | null = null constructor() { this.config = { mode: 'none', url: '' } - if (this.config.mode === 'system') { - this.monitorSystemProxy() - } } private async setSessionsProxy(config: _ProxyConfig): Promise { @@ -31,16 +29,28 @@ export class ProxyManager { } private async monitorSystemProxy(): Promise { - setInterval(async () => { + // Clear any existing interval first + this.clearSystemProxyMonitor() + // Set new interval + this.systemProxyInterval = setInterval(async () => { await this.setSystemProxy() }, 10000) } + private clearSystemProxyMonitor(): void { + if (this.systemProxyInterval) { + clearInterval(this.systemProxyInterval) + this.systemProxyInterval = null + } + } + async configureProxy(config: ProxyConfig): Promise { try { this.config = config + this.clearSystemProxyMonitor() if (this.config.mode === 'system') { await this.setSystemProxy() + this.monitorSystemProxy() } else if (this.config.mode == 'custom') { await this.setCustomProxy() } else {