/* * @Author : Evan.G * @Date : 2020-12-24 15:43:11 * @LastEditTime : 2021-07-01 14:03:42 * @Description : */ import { ExtensionContext, ViewColumn, WebviewPanel, window, commands, Uri, } from "vscode"; import { join } from "path"; let webviewPanel: WebviewPanel | undefined; function getExtensionFileVscodeResource( context: ExtensionContext, relativePath: string ) { const diskPath = Uri.file(join(context.extensionPath, relativePath)); return diskPath .with({ scheme: "vscode-resource", }) .toString(); } export function createWebView( context: ExtensionContext, viewColumn: ViewColumn, label: string, name: string ) { // let path = getExtensionFileVscodeResource( // context, // "src/docs/hopeui/iframe.html" // ); let path = "https://seazeg.gitee.io/hopeui/iframe.html" if (webviewPanel === undefined) { webviewPanel = window.createWebviewPanel("webView", name, viewColumn, { retainContextWhenHidden: true, enableScripts: true, }); webviewPanel.webview.html = getIframeHtml(path, label); } else { console.log(`${path}?id=${label}&viewMode=docs`); webviewPanel.title = name; webviewPanel.webview.postMessage({ // path: path, // label: label params: `?id=${label}&viewMode=docs`, }); webviewPanel.reveal(); } webviewPanel.iconPath = Uri.file( join(__filename, "..", "images", "icon.png") ); webviewPanel.onDidDispose(() => { webviewPanel = undefined; }); webviewPanel.webview.onDidReceiveMessage((message) => { switch (message.command) { case "iframeLabel": window.showInformationMessage(message.text); } }); return webviewPanel; } export function getIframeHtml(path: string, label: string) { console.log(`${path}?id=${label}&viewMode=docs`); return ` `; }