diff --git a/src/vs/workbench/api/browser/mainThreadTunnelService.ts b/src/vs/workbench/api/browser/mainThreadTunnelService.ts index 1d198877f0e..b09d08fab27 100644 --- a/src/vs/workbench/api/browser/mainThreadTunnelService.ts +++ b/src/vs/workbench/api/browser/mainThreadTunnelService.ts @@ -12,6 +12,8 @@ import { ITunnelProvider, ITunnelService, TunnelCreationOptions, TunnelProviderF import { Disposable } from 'vs/base/common/lifecycle'; import type { TunnelDescription } from 'vs/platform/remote/common/remoteAuthorityResolver'; import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { PORT_AUTO_FORWARD_SETTING } from 'vs/workbench/contrib/remote/browser/tunnelView'; @extHostNamedCustomer(MainContext.MainThreadTunnelService) export class MainThreadTunnelService extends Disposable implements MainThreadTunnelServiceShape { @@ -22,7 +24,8 @@ export class MainThreadTunnelService extends Disposable implements MainThreadTun extHostContext: IExtHostContext, @IRemoteExplorerService private readonly remoteExplorerService: IRemoteExplorerService, @ITunnelService private readonly tunnelService: ITunnelService, - @INotificationService private readonly notificationService: INotificationService + @INotificationService private readonly notificationService: INotificationService, + @IConfigurationService private readonly configurationService: IConfigurationService ) { super(); this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostTunnelService); @@ -32,10 +35,15 @@ export class MainThreadTunnelService extends Disposable implements MainThreadTun async $setCandidateFinder(): Promise { if (this.remoteExplorerService.portsFeaturesEnabled) { - this._proxy.$registerCandidateFinder(); + this._proxy.$registerCandidateFinder(true); } else { - this._register(this.remoteExplorerService.onEnabledPortsFeatures(() => this._proxy.$registerCandidateFinder())); + this._register(this.remoteExplorerService.onEnabledPortsFeatures(() => this._proxy.$registerCandidateFinder(true))); } + this._register(this.configurationService.onDidChangeConfiguration(async (e) => { + if (e.affectsConfiguration(PORT_AUTO_FORWARD_SETTING)) { + return this._proxy.$registerCandidateFinder((this.configurationService.getValue(PORT_AUTO_FORWARD_SETTING))); + } + })); } async $openTunnel(tunnelOptions: TunnelOptions, source: string): Promise { diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 5da7b6f3761..8cdc92b4a5e 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1810,7 +1810,7 @@ export interface ExtHostTunnelServiceShape { $forwardPort(tunnelOptions: TunnelOptions, tunnelCreationOptions: TunnelCreationOptions): Promise; $closeTunnel(remote: { host: string, port: number }, silent?: boolean): Promise; $onDidTunnelsChange(): Promise; - $registerCandidateFinder(): Promise; + $registerCandidateFinder(enable: boolean): Promise; $applyCandidateFilter(candidates: CandidatePort[]): Promise; } diff --git a/src/vs/workbench/api/node/extHostTunnelService.ts b/src/vs/workbench/api/node/extHostTunnelService.ts index f3e5ae5ff5f..8075d654f89 100644 --- a/src/vs/workbench/api/node/extHostTunnelService.ts +++ b/src/vs/workbench/api/node/extHostTunnelService.ts @@ -138,6 +138,7 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe private _extensionTunnels: Map> = new Map(); private _onDidChangeTunnels: Emitter = new Emitter(); onDidChangeTunnels: vscode.Event = this._onDidChangeTunnels.event; + private _candidateFindingEnabled: boolean = false; constructor( @IExtHostRpcService extHostRpc: IExtHostRpcService, @@ -171,11 +172,16 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe return Math.max(movingAverage * 20, 2000); } - async $registerCandidateFinder(): Promise { + async $registerCandidateFinder(enable: boolean): Promise { + if (enable && this._candidateFindingEnabled) { + // already enabled + return; + } + this._candidateFindingEnabled = enable; // Regularly scan to see if the candidate ports have changed. let movingAverage = new MovingAverage(); let oldPorts: { host: string, port: number, detail: string }[] | undefined = undefined; - while (1) { + while (this._candidateFindingEnabled) { const startTime = new Date().getTime(); const newPorts = await this.findCandidatePorts(); const timeTaken = new Date().getTime() - startTime;