11const vscode = require ( 'vscode' )
2+ const fs = require ( 'fs' )
23const path = require ( 'path' )
34const { writeFileSync } = require ( 'fs' )
45const { homedir } = require ( 'os' )
@@ -8,8 +9,13 @@ const writeSerializedBlobToFile = (serializeBlob, fileName) => {
89 writeFileSync ( fileName , new Buffer ( bytes ) )
910}
1011
12+ const P_TITLE = 'Polacode πΈ'
13+
14+ /**
15+ * @param {vscode.ExtensionContext } context
16+ */
1117function activate ( context ) {
12- const htmlPath = path . resolve ( context . extensionPath , 'src/ webview/index.html' )
18+ const htmlPath = path . resolve ( context . extensionPath , 'webview/index.html' )
1319 const indexUri = vscode . Uri . file ( htmlPath )
1420
1521 let lastUsedImageUri = vscode . Uri . file ( path . resolve ( homedir ( ) , 'Desktop/code.png' ) )
@@ -30,19 +36,28 @@ function activate(context) {
3036 } )
3137
3238 vscode . commands . registerCommand ( 'polacode.activate' , ( ) => {
33- vscode . commands
34- . executeCommand ( 'vscode.previewHtml' , indexUri , 2 , 'Polacode πΈ' , {
35- allowScripts : true
36- } )
37- . then ( ( ) => {
38- const fontFamily = vscode . workspace . getConfiguration ( 'editor' ) . fontFamily
39- const bgColor = context . globalState . get ( 'polacode.bgColor' , '#2e3440' )
40- vscode . commands . executeCommand ( '_workbench.htmlPreview.postMessage' , indexUri , {
41- type : 'init' ,
42- fontFamily,
43- bgColor
44- } )
45- } )
39+ const panel = vscode . window . createWebviewPanel ( 'polacode' , P_TITLE , 2 , {
40+ enableScripts : true ,
41+ localResourceRoots : [
42+ vscode . Uri . file ( path . join ( context . extensionPath , 'webview' ) )
43+ ]
44+ } ) ;
45+
46+ panel . webview . html = fs . readFileSync ( htmlPath , 'utf-8' )
47+
48+ // vscode.commands
49+ // .executeCommand('vscode.previewHtml', indexUri, 2, 'Polacode πΈ', {
50+ // allowScripts: true,
51+ // })
52+ // .then(() => {
53+ // const fontFamily = vscode.workspace.getConfiguration('editor').fontFamily
54+ // const bgColor = context.globalState.get('polacode.bgColor', '#2e3440')
55+ // vscode.commands.executeCommand('_workbench.htmlPreview.postMessage', indexUri, {
56+ // type: 'init',
57+ // fontFamily,
58+ // bgColor
59+ // })
60+ // })
4661 } )
4762
4863 vscode . window . onDidChangeTextEditorSelection ( e => {
0 commit comments