Skip to content

Commit 00f2421

Browse files
committed
changes to webview html code
1 parent 9136161 commit 00f2421

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/webviews/webviews.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable max-len */
2+
/* eslint-disable @typescript-eslint/restrict-template-expressions */
13
/* ---------------------------------------------------------------------------------------------
24
* Copyright (c) Applied Eng & Design All rights reserved.
35
* Licensed under the MIT License. See License.md in the project root for license information.
@@ -115,6 +117,50 @@ export abstract class GWebView implements Disposable {
115117

116118
protected abstract getHtml(webview: Webview): Promise<string>;
117119

120+
private _getHtmlForWebview(webview: Webview, ...opts: string[]) {
121+
// CSS styles
122+
const stylesReset = webview
123+
.asWebviewUri(Uri.joinPath(Control.context.extensionUri, 'resources', 'webviews', 'css', 'reset.css'))
124+
.with({ scheme: 'vscode-resource' });
125+
126+
const stylesMain = webview
127+
.asWebviewUri(Uri.joinPath(Control.context.extensionUri, 'resources', 'webviews', 'css', 'vscode.css'))
128+
.with({ scheme: 'vscode-resource' });
129+
130+
const nonce = this.getNonce();
131+
132+
const scriptUri = webview
133+
.asWebviewUri(Uri.joinPath(Control.context.extensionUri, 'resources', 'webviews', 'js', `${opts[0]}.js`))
134+
.with({ scheme: 'vscode-resource' });
135+
136+
return `<!DOCTYPE html>
137+
<html lang="en">
138+
<head>
139+
<meta charset="utf-8">
140+
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
141+
<meta name="theme-color" content="#333333">
142+
143+
<title>${this.title}</title>
144+
145+
<link rel="stylesheet" type="text/css" href="${stylesReset}">
146+
<link rel="stylesheet" type="text/css" href="${stylesMain}">
147+
148+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${nonce}';style-src vscode-resource: 'unsafe-inline' http: https: data:;">
149+
150+
</head>
151+
152+
<body>
153+
<noscript>You need to enable JavaScript to run this app.</noscript>
154+
155+
<div id="app"></div>
156+
157+
158+
<script nonce="${nonce} src="${scriptUri}"></script>
159+
</body>
160+
</html>
161+
`;
162+
}
163+
118164
protected getNonce(): string {
119165
let text = '';
120166

0 commit comments

Comments
 (0)