提交 6710df44 编写于 作者: M Matt Bierner

Allow tunneling when clicking on links in the terminal

Fixes #76175
上级 93ba04b2
......@@ -10,7 +10,7 @@ import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
export const IOpenerService = createDecorator<IOpenerService>('openerService');
type OpenToSideOptions = { readonly openToSide?: boolean };
type OpenExternalOptions = { readonly openExternal?: boolean };
type OpenExternalOptions = { readonly openExternal?: boolean; readonly allowTunneling?: boolean };
export type OpenOptions = OpenToSideOptions & OpenExternalOptions;
......@@ -24,7 +24,7 @@ export interface IValidator {
}
export interface IExternalUriResolver {
resolveExternalUri(resource: URI): Promise<URI>;
resolveExternalUri(resource: URI, options?: OpenOptions): Promise<URI>;
}
export interface IOpenerService {
......
......@@ -47,8 +47,8 @@ export class MainThreadWindow implements MainThreadWindowShape {
}
async $openUri(uriComponents: UriComponents, options: IOpenUriOptions): Promise<boolean> {
const uri = await this.resolveExternalUri(URI.from(uriComponents), options);
return this.openerService.open(uri, { openExternal: true });
const uri = URI.from(uriComponents);
return this.openerService.open(uri, { openExternal: true, allowTunneling: options.allowTunneling });
}
async $resolveExternalUri(uriComponents: UriComponents, options: IOpenUriOptions): Promise<UriComponents> {
......
......@@ -238,7 +238,7 @@ export class TerminalLinkHandler {
private _handleHypertextLink(url: string): void {
const uri = URI.parse(url);
this._openerService.open(uri);
this._openerService.open(uri, { allowTunneling: !!(this._processManager && this._processManager.remoteAuthority) });
}
private _isLinkActivationModifierDown(event: MouseEvent): boolean {
......
......@@ -58,6 +58,7 @@ import { Schemas } from 'vs/base/common/network';
import { IElectronService } from 'vs/platform/electron/node/electron';
import { posix, dirname } from 'vs/base/common/path';
import { getBaseLabel } from 'vs/base/common/labels';
import { ITunnelService, extractLocalHostUriMetaDataForPortMapping } from 'vs/platform/remote/common/tunnel';
const TextInputActions: IAction[] = [
new Action('undo', nls.localize('undo', "Undo"), undefined, true, () => Promise.resolve(document.execCommand('undo'))),
......@@ -108,7 +109,8 @@ export class ElectronWindow extends Disposable {
@ITextFileService private readonly textFileService: ITextFileService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IOpenerService private readonly openerService: IOpenerService,
@IElectronService private readonly electronService: IElectronService
@IElectronService private readonly electronService: IElectronService,
@ITunnelService private readonly tunnelService: ITunnelService,
) {
super();
......@@ -435,6 +437,21 @@ export class ElectronWindow extends Disposable {
return false; // not handled by us
}
});
this.openerService.registerExternalUriResolver({
resolveExternalUri: async (uri: URI, options?: OpenOptions): Promise<URI> => {
if (options && options.allowTunneling) {
const portMappingRequest = extractLocalHostUriMetaDataForPortMapping(uri);
if (portMappingRequest) {
const tunnel = await this.tunnelService.openTunnel(portMappingRequest.port);
if (tunnel) {
return uri.with({ authority: `127.0.0.1:${tunnel.tunnelLocalPort}` });
}
}
}
return uri;
}
});
}
private shouldOpenExternal(resource: URI, options?: OpenOptions) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册