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

This commit is contained in:
Alex Ross 2023-08-10 23:23:00 +02:00 коммит произвёл GitHub
Родитель cb968b2878
Коммит a7d7ad8797
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 33 добавлений и 10 удалений

Просмотреть файл

@ -20,7 +20,7 @@
"tunnelFactory"
],
"activationEvents": [
"onStartupFinished"
"onTunnel"
],
"contributes": {
"commands": [

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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';

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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> {

Просмотреть файл

@ -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;
@ -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);
@ -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) {
@ -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 ??