-
Notifications
You must be signed in to change notification settings - Fork 6
/
extension.ts
55 lines (48 loc) · 1.73 KB
/
extension.ts
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
54
55
import * as vscode from "vscode";
import { renderHost, renderPlaceholder } from "./host";
import { getColumnFromPane } from "./pane";
export function activate(context: vscode.ExtensionContext) {
let currentPanel: vscode.WebviewPanel | undefined;
let disposable = vscode.commands.registerCommand(
"vscode-live-frame.open",
() => {
const config = vscode.workspace.getConfiguration("liveFrame");
const url = config.get<string>("url");
const title = config.get<string>("title") || url || "Live Frame";
const pane = config.get<string>("pane");
const column = getColumnFromPane(pane);
if (!currentPanel) {
const panel = (currentPanel = vscode.window.createWebviewPanel(
"vscode-live-frame",
title,
column,
{
enableCommandUris: true,
enableFindWidget: true,
localResourceRoots: [],
enableScripts: true,
}
));
vscode.workspace.onDidChangeConfiguration((e) => {
const newConfig = vscode.workspace.getConfiguration("liveFrame");
const newUrl = newConfig.get<string>("url");
const newTitle =
newConfig.get<string>("title") || newUrl || "Live Frame";
panel.webview.html = newUrl
? renderHost(newUrl)
: renderPlaceholder();
panel.title = newTitle;
});
panel.webview.html = url ? renderHost(url) : renderPlaceholder();
panel.onDidDispose(() => {
currentPanel = undefined;
});
} else {
currentPanel.reveal();
}
}
);
context.subscriptions.push(disposable);
}
// this method is called when your extension is deactivated
export function deactivate() {}