Add openBrowserOnce to portsAttributes

Fixes #124160
This commit is contained in:
Alex Ross 2021-06-18 14:54:55 +02:00
parent eb42d4389b
commit 63e1edc203
No known key found for this signature in database
GPG key ID: 89DDDBA66CBA7840
8 changed files with 30 additions and 3 deletions

View file

@ -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."

View file

@ -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."

View file

@ -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."

View file

@ -55,7 +55,8 @@ export enum ProvidedOnAutoForward {
OpenBrowser = 2,
OpenPreview = 3,
Silent = 4,
Ignore = 5
Ignore = 5,
OpenBrowserOnce = 6
}
export interface ProvidedPortAttributes {

View file

@ -2687,7 +2687,8 @@ declare module 'vscode' {
OpenBrowser = 2,
OpenPreview = 3,
Silent = 4,
Ignore = 5
Ignore = 5,
OpenBrowserOnce = 6
}
export class PortAttributes {

View file

@ -221,6 +221,7 @@ class OnAutoForwardedAction extends Disposable {
private lastNotification: INotificationHandle | undefined;
private lastShownPort: number | undefined;
private doActionTunnels: RemoteTunnel[] | undefined;
private alreadyOpenedOnce: Set<string> = 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);

View file

@ -158,10 +158,11 @@ Registry.as<IConfigurationRegistry>(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.")

View file

@ -145,6 +145,7 @@ export function mapHasAddressLocalhostOrAllInterfaces<T>(map: Map<string, T>, 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;