Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Ports view when there's an onTunnel extension #190202

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion extensions/tunnel-forwarding/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"tunnelFactory"
],
"activationEvents": [
"onStartupFinished"
"onTunnel"
],
"contributes": {
"commands": [
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/api/browser/mainThreadTunnelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { Registry } from 'vs/platform/registry/common/platform';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { forwardedPortsViewEnabled } from 'vs/workbench/contrib/remote/browser/tunnelView';
import { CandidatePort, TunnelCloseReason, TunnelSource, makeAddress } from 'vs/workbench/services/remote/common/tunnelModel';
import { CandidatePort, TunnelCloseReason, TunnelSource, forwardedPortsViewEnabled, makeAddress } from 'vs/workbench/services/remote/common/tunnelModel';

@extHostNamedCustomer(MainContext.MainThreadTunnelService)
export class MainThreadTunnelService extends Disposable implements MainThreadTunnelServiceShape, PortAttributesProvider {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/remote/browser/remoteExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { Extensions, IViewContainersRegistry, IViewsRegistry, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views';
import { IRemoteExplorerService, PORT_AUTO_FORWARD_SETTING, PORT_AUTO_SOURCE_SETTING, PORT_AUTO_SOURCE_SETTING_HYBRID, PORT_AUTO_SOURCE_SETTING_OUTPUT, PORT_AUTO_SOURCE_SETTING_PROCESS, TUNNEL_VIEW_CONTAINER_ID, TUNNEL_VIEW_ID } from 'vs/workbench/services/remote/common/remoteExplorerService';
import { Attributes, AutoTunnelSource, makeAddress, mapHasAddressLocalhostOrAllInterfaces, OnPortForward, Tunnel, TunnelCloseReason, TunnelSource } from 'vs/workbench/services/remote/common/tunnelModel';
import { forwardedPortsViewEnabled, ForwardPortAction, OpenPortInBrowserAction, TunnelPanel, TunnelPanelDescriptor, TunnelViewModel, OpenPortInPreviewAction, openPreviewEnabledContext } from 'vs/workbench/contrib/remote/browser/tunnelView';
import { Attributes, AutoTunnelSource, forwardedPortsViewEnabled, makeAddress, mapHasAddressLocalhostOrAllInterfaces, OnPortForward, Tunnel, TunnelCloseReason, TunnelSource } from 'vs/workbench/services/remote/common/tunnelModel';
import { ForwardPortAction, OpenPortInBrowserAction, TunnelPanel, TunnelPanelDescriptor, TunnelViewModel, OpenPortInPreviewAction, openPreviewEnabledContext } from 'vs/workbench/contrib/remote/browser/tunnelView';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { Registry } from 'vs/platform/registry/common/platform';
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/remote/browser/tunnelFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
import { URI } from 'vs/base/common/uri';
import { IRemoteExplorerService } from 'vs/workbench/services/remote/common/remoteExplorerService';
import { ILogService } from 'vs/platform/log/common/log';
import { forwardedPortsViewEnabled } from 'vs/workbench/contrib/remote/browser/tunnelView';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { forwardedPortsViewEnabled } from 'vs/workbench/services/remote/common/tunnelModel';

export class TunnelFactoryContribution extends Disposable implements IWorkbenchContribution {

Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/contrib/remote/browser/tunnelView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ import { IHoverService } from 'vs/workbench/services/hover/browser/hover';
import { STATUS_BAR_HOST_NAME_BACKGROUND } from 'vs/workbench/common/theme';
import { Codicon } from 'vs/base/common/codicons';
import { defaultButtonStyles, defaultInputBoxStyles } from 'vs/platform/theme/browser/defaultStyles';
import { Attributes, CandidatePort, Tunnel, TunnelCloseReason, TunnelModel, TunnelSource, makeAddress, mapHasAddressLocalhostOrAllInterfaces, parseAddress } from 'vs/workbench/services/remote/common/tunnelModel';
import { Attributes, CandidatePort, Tunnel, TunnelCloseReason, TunnelModel, TunnelSource, forwardedPortsViewEnabled, makeAddress, mapHasAddressLocalhostOrAllInterfaces, parseAddress } from 'vs/workbench/services/remote/common/tunnelModel';

export const forwardedPortsViewEnabled = new RawContextKey<boolean>('forwardedPortsViewEnabled', false, nls.localize('tunnel.forwardedPortsViewEnabled', "Whether the Ports view is enabled."));
export const openPreviewEnabledContext = new RawContextKey<boolean>('openPreviewEnabled', false);

class TunnelTreeVirtualDelegate implements ITableVirtualDelegate<ITunnelItem> {
Expand Down
29 changes: 27 additions & 2 deletions src/vs/workbench/services/remote/common/tunnelModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { isNumber, isObject, isString } from 'vs/base/common/types';
import { deepClone } from 'vs/base/common/objects';
import { IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';

const MISMATCH_LOCAL_PORT_COOLDOWN = 10 * 1000; // 10 seconds
const TUNNELS_TO_RESTORE = 'remote.tunnels.toRestore';
export const ACTIVATION_EVENT = 'onTunnel';
export const forwardedPortsViewEnabled = new RawContextKey<boolean>('forwardedPortsViewEnabled', false, nls.localize('tunnel.forwardedPortsViewEnabled', "Whether the Ports view is enabled."));

export interface Tunnel {
remoteHost: string;
Expand Down Expand Up @@ -415,7 +418,8 @@ export class TunnelModel extends Disposable {
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
@ILogService private readonly logService: ILogService,
@IDialogService private readonly dialogService: IDialogService,
@IExtensionService private readonly extensionService: IExtensionService
@IExtensionService private readonly extensionService: IExtensionService,
@IContextKeyService private readonly contextKeyService: IContextKeyService
) {
super();
this.configPortsAttributes = new PortsAttributes(configurationService);
Expand Down Expand Up @@ -480,6 +484,27 @@ export class TunnelModel extends Disposable {
this._register(this.tunnelService.onTunnelClosed(address => {
return this.onTunnelClosed(address, TunnelCloseReason.Other);
}));
this.checkExtensionActivationEvents();
}

private extensionHasActivationEvent() {
if (this.extensionService.extensions.find(extension => extension.activationEvents?.includes(ACTIVATION_EVENT))) {
this.contextKeyService.createKey(forwardedPortsViewEnabled.key, true);
return true;
}
return false;
}

private checkExtensionActivationEvents() {
if (this.extensionHasActivationEvent()) {
return;
}

const activationDisposable = this._register(this.extensionService.onDidRegisterExtensions(() => {
if (this.extensionHasActivationEvent()) {
activationDisposable.dispose();
}
}));
}

private async onTunnelClosed(address: { host: string; port: number }, reason: TunnelCloseReason) {
Expand Down Expand Up @@ -594,7 +619,7 @@ export class TunnelModel extends Disposable {
}

async forward(tunnelProperties: TunnelProperties, attributes?: Attributes | null): Promise<RemoteTunnel | undefined> {
await this.extensionService.activateByEvent('onTunnel');
await this.extensionService.activateByEvent(ACTIVATION_EVENT);

const existingTunnel = mapHasAddressLocalhostOrAllInterfaces(this.forwarded, tunnelProperties.remote.host, tunnelProperties.remote.port);
attributes = attributes ??
Expand Down