|
| 1 | +/* eslint-disable max-len */ |
| 2 | +/* eslint-disable @typescript-eslint/restrict-template-expressions */ |
1 | 3 | /* --------------------------------------------------------------------------------------------- |
2 | 4 | * Copyright (c) Applied Eng & Design All rights reserved. |
3 | 5 | * 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 { |
115 | 117 |
|
116 | 118 | protected abstract getHtml(webview: Webview): Promise<string>; |
117 | 119 |
|
| 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 | + |
118 | 164 | protected getNonce(): string { |
119 | 165 | let text = ''; |
120 | 166 |
|
|
0 commit comments