Skip to content

Commit e97910b

Browse files
author
Tyler Deemer
committed
Opens CSP pages in a webview
1 parent 166c1e5 commit e97910b

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

src/commands/studio.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,54 @@ class StudioActions {
3636
.showWarningMessage(target, { modal: true }, "Yes", "No")
3737
.then(answer => (answer === "Yes" ? "1" : answer === "No" ? "0" : "2"));
3838
case 2: // Run a CSP page/Template. The Target is the full url to the CSP page/Template
39+
// Open the target URL in a webview
3940
const conn = config().conn;
40-
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(`http://${conn.host}:${conn.port}${target}`));
41+
const column = vscode.window.activeTextEditor
42+
? vscode.window.activeTextEditor.viewColumn
43+
: undefined;
44+
const panel = vscode.window.createWebviewPanel(
45+
'studioactionwebview',
46+
'CSP Page',
47+
column || vscode.ViewColumn.One,
48+
{
49+
enableScripts: true,
50+
}
51+
);
52+
panel.webview.html = `
53+
<!DOCTYPE html>
54+
<html lang="en">
55+
<head>
56+
<style type="text/css">
57+
body, html
58+
{
59+
margin: 0; padding: 0; height: 100%; overflow: hidden;
60+
}
61+
#content
62+
{
63+
position:absolute; left: 0; right: 0; bottom: 0; top: 0px;
64+
}
65+
</style>
66+
</head>
67+
<body>
68+
<div id="content">
69+
<iframe src="http://${conn.host}:${conn.port}${target}" onLoad="checkForCancelState()" width="100%" height="100%" frameborder="0"></iframe>
70+
</div>
71+
<script>
72+
function checkForCancelState() {
73+
var x = document.getElementsByTagName("BODY")[0];
74+
console.log(x);
75+
}
76+
</script>
77+
</body>
78+
</html>
79+
`;
80+
panel.onDidDispose(
81+
() => {
82+
// fire a cancel answer if the user closes the webview
83+
return "2";
84+
}
85+
);
86+
// TODO: use panel.dispose() when the cancel text is sent back in the iframe
4187
break;
4288
// throw new Error("Not suppoorted");
4389
case 3: // Run an EXE on the client.

0 commit comments

Comments
 (0)