From 63e1edc203fb1dbbfa1ec43e2903ebbf0bcf232f Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Fri, 18 Jun 2021 14:54:55 +0200 Subject: [PATCH] Add openBrowserOnce to portsAttributes Fixes #124160 --- .../schemas/attachContainer.schema.json | 2 ++ .../schemas/devContainer.schema.generated.json | 10 ++++++++++ .../schemas/devContainer.schema.src.json | 2 ++ src/vs/platform/remote/common/tunnel.ts | 3 ++- src/vs/vscode.proposed.d.ts | 3 ++- .../workbench/contrib/remote/browser/remoteExplorer.ts | 8 ++++++++ .../contrib/remote/common/remote.contribution.ts | 3 ++- .../services/remote/common/remoteExplorerService.ts | 2 ++ 8 files changed, 30 insertions(+), 3 deletions(-) diff --git a/extensions/configuration-editing/schemas/attachContainer.schema.json b/extensions/configuration-editing/schemas/attachContainer.schema.json index 9cdd3a5f6d3..9fbc5d0fec7 100644 --- a/extensions/configuration-editing/schemas/attachContainer.schema.json +++ b/extensions/configuration-editing/schemas/attachContainer.schema.json @@ -31,6 +31,7 @@ "enum": [ "notify", "openBrowser", + "openBrowserOnce", "openPreview", "silent", "ignore" @@ -38,6 +39,7 @@ "enumDescriptions": [ "Shows a notification when a port is automatically forwarded.", "Opens the browser when the port is automatically forwarded. Depending on your settings, this could open an embedded browser.", + "Opens the browser when the port is automatically forwarded, but only the first time the port is forward during a session. Depending on your settings, this could open an embedded browser.", "Opens a preview in the same window when the port is automatically forwarded.", "Shows no notification and takes no action when this port is automatically forwarded.", "This port will not be automatically forwarded." diff --git a/extensions/configuration-editing/schemas/devContainer.schema.generated.json b/extensions/configuration-editing/schemas/devContainer.schema.generated.json index 112b4e48279..436bede2081 100644 --- a/extensions/configuration-editing/schemas/devContainer.schema.generated.json +++ b/extensions/configuration-editing/schemas/devContainer.schema.generated.json @@ -139,6 +139,7 @@ "enum": [ "notify", "openBrowser", + "openBrowserOnce", "openPreview", "silent", "ignore" @@ -146,6 +147,7 @@ "enumDescriptions": [ "Shows a notification when a port is automatically forwarded.", "Opens the browser when the port is automatically forwarded. Depending on your settings, this could open an embedded browser.", + "Opens the browser when the port is automatically forwarded, but only the first time the port is forward during a session. Depending on your settings, this could open an embedded browser.", "Opens a preview in the same window when the port is automatically forwarded.", "Shows no notification and takes no action when this port is automatically forwarded.", "This port will not be automatically forwarded." @@ -518,6 +520,7 @@ "enum": [ "notify", "openBrowser", + "openBrowserOnce", "openPreview", "silent", "ignore" @@ -525,6 +528,7 @@ "enumDescriptions": [ "Shows a notification when a port is automatically forwarded.", "Opens the browser when the port is automatically forwarded. Depending on your settings, this could open an embedded browser.", + "Opens the browser when the port is automatically forwarded, but only the first time the port is forward during a session. Depending on your settings, this could open an embedded browser.", "Opens a preview in the same window when the port is automatically forwarded.", "Shows no notification and takes no action when this port is automatically forwarded.", "This port will not be automatically forwarded." @@ -873,6 +877,7 @@ "enum": [ "notify", "openBrowser", + "openBrowserOnce", "openPreview", "silent", "ignore" @@ -880,6 +885,7 @@ "enumDescriptions": [ "Shows a notification when a port is automatically forwarded.", "Opens the browser when the port is automatically forwarded. Depending on your settings, this could open an embedded browser.", + "Opens the browser when the port is automatically forwarded, but only the first time the port is forward during a session. Depending on your settings, this could open an embedded browser.", "Opens a preview in the same window when the port is automatically forwarded.", "Shows no notification and takes no action when this port is automatically forwarded.", "This port will not be automatically forwarded." @@ -1194,6 +1200,7 @@ "enum": [ "notify", "openBrowser", + "openBrowserOnce", "openPreview", "silent", "ignore" @@ -1201,6 +1208,7 @@ "enumDescriptions": [ "Shows a notification when a port is automatically forwarded.", "Opens the browser when the port is automatically forwarded. Depending on your settings, this could open an embedded browser.", + "Opens the browser when the port is automatically forwarded, but only the first time the port is forward during a session. Depending on your settings, this could open an embedded browser.", "Opens a preview in the same window when the port is automatically forwarded.", "Shows no notification and takes no action when this port is automatically forwarded.", "This port will not be automatically forwarded." @@ -1484,6 +1492,7 @@ "enum": [ "notify", "openBrowser", + "openBrowserOnce", "openPreview", "silent", "ignore" @@ -1491,6 +1500,7 @@ "enumDescriptions": [ "Shows a notification when a port is automatically forwarded.", "Opens the browser when the port is automatically forwarded. Depending on your settings, this could open an embedded browser.", + "Opens the browser when the port is automatically forwarded, but only the first time the port is forward during a session. Depending on your settings, this could open an embedded browser.", "Opens a preview in the same window when the port is automatically forwarded.", "Shows no notification and takes no action when this port is automatically forwarded.", "This port will not be automatically forwarded." diff --git a/extensions/configuration-editing/schemas/devContainer.schema.src.json b/extensions/configuration-editing/schemas/devContainer.schema.src.json index 14c13a958b3..8297432256d 100644 --- a/extensions/configuration-editing/schemas/devContainer.schema.src.json +++ b/extensions/configuration-editing/schemas/devContainer.schema.src.json @@ -45,6 +45,7 @@ "enum": [ "notify", "openBrowser", + "openBrowserOnce", "openPreview", "silent", "ignore" @@ -52,6 +53,7 @@ "enumDescriptions": [ "Shows a notification when a port is automatically forwarded.", "Opens the browser when the port is automatically forwarded. Depending on your settings, this could open an embedded browser.", + "Opens the browser when the port is automatically forwarded, but only the first time the port is forward during a session. Depending on your settings, this could open an embedded browser.", "Opens a preview in the same window when the port is automatically forwarded.", "Shows no notification and takes no action when this port is automatically forwarded.", "This port will not be automatically forwarded." diff --git a/src/vs/platform/remote/common/tunnel.ts b/src/vs/platform/remote/common/tunnel.ts index 88dcc0a0a31..0d717c6d901 100644 --- a/src/vs/platform/remote/common/tunnel.ts +++ b/src/vs/platform/remote/common/tunnel.ts @@ -55,7 +55,8 @@ export enum ProvidedOnAutoForward { OpenBrowser = 2, OpenPreview = 3, Silent = 4, - Ignore = 5 + Ignore = 5, + OpenBrowserOnce = 6 } export interface ProvidedPortAttributes { diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 53d71797fb2..017f4df470a 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -2687,7 +2687,8 @@ declare module 'vscode' { OpenBrowser = 2, OpenPreview = 3, Silent = 4, - Ignore = 5 + Ignore = 5, + OpenBrowserOnce = 6 } export class PortAttributes { diff --git a/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts b/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts index 0ba9d54a78e..5487dac973f 100644 --- a/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts +++ b/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts @@ -221,6 +221,7 @@ class OnAutoForwardedAction extends Disposable { private lastNotification: INotificationHandle | undefined; private lastShownPort: number | undefined; private doActionTunnels: RemoteTunnel[] | undefined; + private alreadyOpenedOnce: Set = new Set(); constructor(private readonly notificationService: INotificationService, private readonly remoteExplorerService: IRemoteExplorerService, @@ -243,6 +244,13 @@ class OnAutoForwardedAction extends Disposable { const attributes = (await this.remoteExplorerService.tunnelModel.getAttributes([tunnel.tunnelRemotePort]))?.get(tunnel.tunnelRemotePort)?.onAutoForward; this.logService.trace(`ForwardedPorts: (OnAutoForwardedAction) onAutoForward action is ${attributes}`); switch (attributes) { + case OnPortForward.OpenBrowserOnce: { + if (this.alreadyOpenedOnce.has(tunnel.localAddress)) { + break; + } + this.alreadyOpenedOnce.add(tunnel.localAddress); + // Intentionally do not break so that the open browser path can be run. + } case OnPortForward.OpenBrowser: { const address = makeAddress(tunnel.tunnelRemoteHost, tunnel.tunnelRemotePort); await OpenPortInBrowserAction.run(this.remoteExplorerService.tunnelModel, this.openerService, address); diff --git a/src/vs/workbench/contrib/remote/common/remote.contribution.ts b/src/vs/workbench/contrib/remote/common/remote.contribution.ts index 1b68b513319..5dfe4a758b8 100644 --- a/src/vs/workbench/contrib/remote/common/remote.contribution.ts +++ b/src/vs/workbench/contrib/remote/common/remote.contribution.ts @@ -158,10 +158,11 @@ Registry.as(ConfigurationExtensions.Configuration) properties: { 'onAutoForward': { type: 'string', - enum: ['notify', 'openBrowser', 'openPreview', 'silent', 'ignore'], + enum: ['notify', 'openBrowser', 'openBrowserOnce', 'openPreview', 'silent', 'ignore'], enumDescriptions: [ localize('remote.portsAttributes.notify', "Shows a notification when a port is automatically forwarded."), localize('remote.portsAttributes.openBrowser', "Opens the browser when the port is automatically forwarded. Depending on your settings, this could open an embedded browser."), + localize('remote.portsAttributes.openBrowserOnce', "Opens the browser when the port is automatically forwarded, but only the first time the port is forward during a session. Depending on your settings, this could open an embedded browser."), localize('remote.portsAttributes.openPreview', "Opens a preview in the same window when the port is automatically forwarded."), localize('remote.portsAttributes.silent', "Shows no notification and takes no action when this port is automatically forwarded."), localize('remote.portsAttributes.ignore', "This port will not be automatically forwarded.") diff --git a/src/vs/workbench/services/remote/common/remoteExplorerService.ts b/src/vs/workbench/services/remote/common/remoteExplorerService.ts index cfa49044fb3..d89fe91ee91 100644 --- a/src/vs/workbench/services/remote/common/remoteExplorerService.ts +++ b/src/vs/workbench/services/remote/common/remoteExplorerService.ts @@ -145,6 +145,7 @@ export function mapHasAddressLocalhostOrAllInterfaces(map: Map, ho export enum OnPortForward { Notify = 'notify', OpenBrowser = 'openBrowser', + OpenBrowserOnce = 'openBrowserOnce', OpenPreview = 'openPreview', Silent = 'silent', Ignore = 'ignore' @@ -328,6 +329,7 @@ export class PortsAttributes extends Disposable { switch (providedAction) { case ProvidedOnAutoForward.Notify: return OnPortForward.Notify; case ProvidedOnAutoForward.OpenBrowser: return OnPortForward.OpenBrowser; + case ProvidedOnAutoForward.OpenBrowserOnce: return OnPortForward.OpenBrowserOnce; case ProvidedOnAutoForward.OpenPreview: return OnPortForward.OpenPreview; case ProvidedOnAutoForward.Silent: return OnPortForward.Silent; case ProvidedOnAutoForward.Ignore: return OnPortForward.Ignore;