mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-22 06:46:56 +01:00
@@ -842,6 +842,8 @@ class RemoteAgentConnectionStatusListener implements IWorkbenchContribution {
|
||||
|
||||
class AutomaticPortForwarding extends Disposable implements IWorkbenchContribution {
|
||||
private contextServiceListener?: IDisposable;
|
||||
private urlFinder?: UrlFinder;
|
||||
private static AUTO_FORWARD_SETTING = 'remote.autoForwardPorts';
|
||||
|
||||
constructor(
|
||||
@ITerminalService private readonly terminalService: ITerminalService,
|
||||
@@ -850,31 +852,43 @@ class AutomaticPortForwarding extends Disposable implements IWorkbenchContributi
|
||||
@IViewsService private readonly viewsService: IViewsService,
|
||||
@IRemoteExplorerService private readonly remoteExplorerService: IRemoteExplorerService,
|
||||
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
|
||||
@IContextKeyService private readonly contextKeyService: IContextKeyService
|
||||
@IContextKeyService private readonly contextKeyService: IContextKeyService,
|
||||
@IConfigurationService private readonly configurationService: IConfigurationService
|
||||
) {
|
||||
super();
|
||||
this._register(configurationService.onDidChangeConfiguration((e) => {
|
||||
if (e.affectsConfiguration(AutomaticPortForwarding.AUTO_FORWARD_SETTING)) {
|
||||
this.tryStartStopUrlFinder();
|
||||
}
|
||||
}));
|
||||
if (this.environmentService.remoteAuthority) {
|
||||
this.startUrlFinder();
|
||||
this.tryStartStopUrlFinder();
|
||||
} else {
|
||||
this.contextServiceListener = this._register(this.contextKeyService.onDidChangeContext(e => {
|
||||
if (e.affectsSome(new Set(forwardedPortsViewEnabled.keys()))) {
|
||||
this.startUrlFinder();
|
||||
this.tryStartStopUrlFinder();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private isStarted = false;
|
||||
private tryStartStopUrlFinder() {
|
||||
if (this.configurationService.getValue(AutomaticPortForwarding.AUTO_FORWARD_SETTING)) {
|
||||
this.startUrlFinder();
|
||||
} else {
|
||||
this.stopUrlFinder();
|
||||
}
|
||||
}
|
||||
|
||||
private startUrlFinder() {
|
||||
if (!this.isStarted && !forwardedPortsViewEnabled.getValue(this.contextKeyService)) {
|
||||
if (!this.urlFinder && !forwardedPortsViewEnabled.getValue(this.contextKeyService)) {
|
||||
return;
|
||||
}
|
||||
if (this.contextServiceListener) {
|
||||
this.contextServiceListener.dispose();
|
||||
}
|
||||
this.isStarted = true;
|
||||
const urlFinder = this._register(new UrlFinder(this.terminalService));
|
||||
this._register(urlFinder.onDidMatchLocalUrl(async (localUrl) => {
|
||||
this.urlFinder = this._register(new UrlFinder(this.terminalService));
|
||||
this._register(this.urlFinder.onDidMatchLocalUrl(async (localUrl) => {
|
||||
if (mapHasTunnelLocalhostOrAllInterfaces(this.remoteExplorerService.tunnelModel.forwarded, localUrl.host, localUrl.port)) {
|
||||
return;
|
||||
}
|
||||
@@ -902,6 +916,13 @@ class AutomaticPortForwarding extends Disposable implements IWorkbenchContributi
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private stopUrlFinder() {
|
||||
if (this.urlFinder) {
|
||||
this.urlFinder.dispose();
|
||||
this.urlFinder = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const workbenchContributionsRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
|
||||
|
||||
@@ -172,6 +172,11 @@ Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration)
|
||||
type: 'boolean',
|
||||
markdownDescription: nls.localize('remote.restoreForwardedPorts', "Restores the ports you forwarded in a workspace."),
|
||||
default: false
|
||||
},
|
||||
'remote.autoForwardPorts': {
|
||||
type: 'boolean',
|
||||
markdownDescription: nls.localize('remote.autoForwardPorts', "When enabled, URLs with ports (ex. `http://127.0.0.1:3000`) that are printed to your terminals are automatically forwarded."),
|
||||
default: true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user