-
Notifications
You must be signed in to change notification settings - Fork 39.5k
Expand file tree
/
Copy pathsimpleBrowserManager.ts
More file actions
53 lines (42 loc) · 1.52 KB
/
simpleBrowserManager.ts
File metadata and controls
53 lines (42 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { ShowOptions, SimpleBrowserView } from './simpleBrowserView';
export class SimpleBrowserManager {
private _activeView?: SimpleBrowserView;
constructor(
private readonly extensionUri: vscode.Uri,
) { }
dispose() {
this._activeView?.dispose();
this._activeView = undefined;
}
public show(inputUri: string | vscode.Uri, options?: ShowOptions): void {
const url = typeof inputUri === 'string' ? inputUri : inputUri.toString(true);
if (this._activeView) {
this._activeView.show(url, options);
} else {
const view = SimpleBrowserView.create(this.extensionUri, url, options);
this.registerWebviewListeners(view);
this._activeView = view;
}
}
public restore(panel: vscode.WebviewPanel, state: any): void {
const url = state?.url ?? '';
const view = SimpleBrowserView.restore(this.extensionUri, url, panel);
this.registerWebviewListeners(view);
this._activeView ??= view;
}
public focusContent(): void {
this._activeView?.focusContent();
}
private registerWebviewListeners(view: SimpleBrowserView) {
view.onDispose(() => {
if (this._activeView === view) {
this._activeView = undefined;
}
});
}
}