Skip to content

Commit 8cdd0bc

Browse files
committed
Switch to Webiew API
1 parent d385836 commit 8cdd0bc

File tree

9 files changed

+41
-32
lines changed

9 files changed

+41
-32
lines changed

β€Žjsconfig.jsonβ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2015",
4+
"module": "commonjs"
5+
}
6+
}

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
]
4040
},
4141
"devDependencies": {
42+
"@types/node": "^11.12.0",
4243
"@types/vscode": "^1.32.0"
4344
}
4445
}

β€Žsrc/extension.jsβ€Ž

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const vscode = require('vscode')
2+
const fs = require('fs')
23
const path = require('path')
34
const { writeFileSync } = require('fs')
45
const { 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+
*/
1117
function 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 => {

β€Žtsconfig.jsonβ€Ž

Lines changed: 0 additions & 18 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

β€Žyarn.lockβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# yarn lockfile v1
33

44

5+
"@types/node@^11.12.0":
6+
version "11.12.0"
7+
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.12.0.tgz#ec5594728811dc2797e42396cfcdf786f2052c12"
8+
integrity sha512-Lg00egj78gM+4aE0Erw05cuDbvX9sLJbaaPwwRtdCdAMnIudqrQZ0oZX98Ek0yiSK/A2nubHgJfvII/rTT2Dwg==
9+
510
"@types/vscode@^1.32.0":
611
version "1.32.0"
712
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.32.0.tgz#e0a57de5fc8690a8a3a473996a6b6dfbccc28fbd"

0 commit comments

Comments
Β (0)