提交 ffef9abe 编写于 作者: A Alex Ross

Hide auto forwarded port notification

上级 82fe1e7d
...@@ -224,6 +224,7 @@ class ForwardedPortNotifier extends Disposable { ...@@ -224,6 +224,7 @@ class ForwardedPortNotifier extends Disposable {
private lastNotifyTime: Date; private lastNotifyTime: Date;
private static COOL_DOWN = 5000; // milliseconds private static COOL_DOWN = 5000; // milliseconds
private lastNotification: INotificationHandle | undefined; private lastNotification: INotificationHandle | undefined;
private lastShownPort: number | undefined;
constructor(private readonly notificationService: INotificationService, constructor(private readonly notificationService: INotificationService,
private readonly remoteExplorerService: IRemoteExplorerService, private readonly remoteExplorerService: IRemoteExplorerService,
...@@ -242,6 +243,12 @@ class ForwardedPortNotifier extends Disposable { ...@@ -242,6 +243,12 @@ class ForwardedPortNotifier extends Disposable {
} }
} }
public async hide(removedPorts: number[]) {
if (this.lastShownPort && removedPorts.indexOf(this.lastShownPort) >= 0) {
this.lastNotification?.close();
}
}
private newerTunnel: RemoteTunnel | undefined; private newerTunnel: RemoteTunnel | undefined;
private async portNumberHeuristicDelay(tunnels: RemoteTunnel[]): Promise<RemoteTunnel | undefined> { private async portNumberHeuristicDelay(tunnels: RemoteTunnel[]): Promise<RemoteTunnel | undefined> {
if (tunnels.length === 0) { if (tunnels.length === 0) {
...@@ -272,6 +279,9 @@ class ForwardedPortNotifier extends Disposable { ...@@ -272,6 +279,9 @@ class ForwardedPortNotifier extends Disposable {
} }
private showNotification(tunnel: RemoteTunnel) { private showNotification(tunnel: RemoteTunnel) {
if (this.lastNotification) {
this.lastNotification.close();
}
const address = makeAddress(tunnel.tunnelRemoteHost, tunnel.tunnelRemotePort); const address = makeAddress(tunnel.tunnelRemoteHost, tunnel.tunnelRemotePort);
const message = nls.localize('remote.tunnelsView.automaticForward', "Your service running on port {0} is available. [See all forwarded ports](command:{1}.focus)", const message = nls.localize('remote.tunnelsView.automaticForward', "Your service running on port {0} is available. [See all forwarded ports](command:{1}.focus)",
tunnel.tunnelRemotePort, TunnelPanel.ID); tunnel.tunnelRemotePort, TunnelPanel.ID);
...@@ -280,9 +290,11 @@ class ForwardedPortNotifier extends Disposable { ...@@ -280,9 +290,11 @@ class ForwardedPortNotifier extends Disposable {
run: () => OpenPortInBrowserAction.run(this.remoteExplorerService.tunnelModel, this.openerService, address) run: () => OpenPortInBrowserAction.run(this.remoteExplorerService.tunnelModel, this.openerService, address)
}; };
this.lastNotification = this.notificationService.prompt(Severity.Info, message, [browserChoice], { neverShowAgain: { id: 'remote.tunnelsView.autoForwardNeverShow', isSecondary: true } }); this.lastNotification = this.notificationService.prompt(Severity.Info, message, [browserChoice], { neverShowAgain: { id: 'remote.tunnelsView.autoForwardNeverShow', isSecondary: true } });
this.lastShownPort = tunnel.tunnelRemotePort;
this.lastNotifyTime = new Date(); this.lastNotifyTime = new Date();
this.lastNotification.onDidClose(() => { this.lastNotification.onDidClose(() => {
this.lastNotification = undefined; this.lastNotification = undefined;
this.lastShownPort = undefined;
}); });
} }
} }
...@@ -447,18 +459,24 @@ class LinuxAutomaticPortForwarding extends Disposable { ...@@ -447,18 +459,24 @@ class LinuxAutomaticPortForwarding extends Disposable {
} }
private async handleCandidateUpdate(removed: Map<string, { host: string, port: number }>) { private async handleCandidateUpdate(removed: Map<string, { host: string, port: number }>) {
const removedPorts: number[] = [];
removed.forEach((value, key) => { removed.forEach((value, key) => {
if (this.autoForwarded.has(key)) { if (this.autoForwarded.has(key)) {
this.remoteExplorerService.close(value); this.remoteExplorerService.close(value);
this.autoForwarded.delete(key); this.autoForwarded.delete(key);
removedPorts.push(value.port);
} else if (this.initialCandidates.has(key)) { } else if (this.initialCandidates.has(key)) {
this.initialCandidates.delete(key); this.initialCandidates.delete(key);
} }
}); });
if (removedPorts.length > 0) {
await this.notifier.hide(removedPorts);
}
const tunnels = await this.forwardCandidates(); const tunnels = await this.forwardCandidates();
if (tunnels) { if (tunnels) {
this.notifier.notify(tunnels); await this.notifier.notify(tunnels);
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册