diff --git a/src/main/services/ProxyManager.ts b/src/main/services/ProxyManager.ts index 6ad7807c..5a839a13 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 {