parent
f542a0e83a
commit
62d631a165
|
@ -24,7 +24,8 @@
|
|||
"onCommand:simpleBrowser.show",
|
||||
"onCommand:simpleBrowser.api.open",
|
||||
"onOpenExternalUri:http",
|
||||
"onOpenExternalUri:https"
|
||||
"onOpenExternalUri:https",
|
||||
"onWebviewPanel:simpleBrowser.view"
|
||||
],
|
||||
"capabilities": {
|
||||
"virtualWorkspaces": true,
|
||||
|
|
|
@ -101,6 +101,8 @@ onceDocumentLoaded(() => {
|
|||
} catch {
|
||||
iframe.src = rawUrl;
|
||||
}
|
||||
|
||||
vscode.setState({ url: rawUrl });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { SimpleBrowserManager } from './simpleBrowserManager';
|
||||
import { SimpleBrowserView } from './simpleBrowserView';
|
||||
|
||||
declare class URL {
|
||||
constructor(input: string, base?: string | URL);
|
||||
|
@ -38,6 +39,12 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
const manager = new SimpleBrowserManager(context.extensionUri);
|
||||
context.subscriptions.push(manager);
|
||||
|
||||
context.subscriptions.push(vscode.window.registerWebviewPanelSerializer(SimpleBrowserView.viewType, {
|
||||
deserializeWebviewPanel: async (panel, state) => {
|
||||
manager.restore(panel, state);
|
||||
}
|
||||
}));
|
||||
|
||||
context.subscriptions.push(vscode.commands.registerCommand(showCommand, async (url?: string) => {
|
||||
if (!url) {
|
||||
url = await vscode.window.showInputBox({
|
||||
|
|
|
@ -23,16 +23,27 @@ export class SimpleBrowserManager {
|
|||
if (this._activeView) {
|
||||
this._activeView.show(url, options);
|
||||
} else {
|
||||
const view = new SimpleBrowserView(this.extensionUri, url, options);
|
||||
view.onDispose(() => {
|
||||
if (this._activeView === view) {
|
||||
this._activeView = undefined;
|
||||
}
|
||||
});
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
private registerWebviewListeners(view: SimpleBrowserView) {
|
||||
view.onDispose(() => {
|
||||
if (this._activeView === view) {
|
||||
this._activeView = undefined;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,14 +24,12 @@ export class SimpleBrowserView extends Disposable {
|
|||
private readonly _onDidDispose = this._register(new vscode.EventEmitter<void>());
|
||||
public readonly onDispose = this._onDidDispose.event;
|
||||
|
||||
constructor(
|
||||
private readonly extensionUri: vscode.Uri,
|
||||
public static create(
|
||||
extensionUri: vscode.Uri,
|
||||
url: string,
|
||||
showOptions?: ShowOptions
|
||||
) {
|
||||
super();
|
||||
|
||||
this._webviewPanel = this._register(vscode.window.createWebviewPanel(SimpleBrowserView.viewType, SimpleBrowserView.title, {
|
||||
): SimpleBrowserView {
|
||||
const webview = vscode.window.createWebviewPanel(SimpleBrowserView.viewType, SimpleBrowserView.title, {
|
||||
viewColumn: showOptions?.viewColumn ?? vscode.ViewColumn.Active,
|
||||
preserveFocus: showOptions?.preserveFocus
|
||||
}, {
|
||||
|
@ -41,7 +39,26 @@ export class SimpleBrowserView extends Disposable {
|
|||
localResourceRoots: [
|
||||
vscode.Uri.joinPath(extensionUri, 'media')
|
||||
]
|
||||
}));
|
||||
});
|
||||
return new SimpleBrowserView(extensionUri, url, webview);
|
||||
}
|
||||
|
||||
public static restore(
|
||||
extensionUri: vscode.Uri,
|
||||
url: string,
|
||||
webview: vscode.WebviewPanel,
|
||||
): SimpleBrowserView {
|
||||
return new SimpleBrowserView(extensionUri, url, webview);
|
||||
}
|
||||
|
||||
private constructor(
|
||||
private readonly extensionUri: vscode.Uri,
|
||||
url: string,
|
||||
webviewPanel: vscode.WebviewPanel,
|
||||
) {
|
||||
super();
|
||||
|
||||
this._webviewPanel = this._register(webviewPanel);
|
||||
|
||||
this._register(this._webviewPanel.webview.onDidReceiveMessage(e => {
|
||||
switch (e.type) {
|
||||
|
|
Loading…
Reference in New Issue