From e95d8fafded40dc976773bc38add8d8a4d723eb2 Mon Sep 17 00:00:00 2001 From: Vladisav Tupikin Date: Mon, 20 Jul 2020 22:24:22 +0300 Subject: [PATCH 1/3] output channel added --- src/extension.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/extension.js b/src/extension.js index 93d6698..9890c36 100644 --- a/src/extension.js +++ b/src/extension.js @@ -14,6 +14,7 @@ const P_TITLE = 'Polacode 📸' * @param {vscode.ExtensionContext} context */ function activate(context) { + const outputChannel = vscode.window.createOutputChannel(P_TITLE) const htmlPath = path.resolve(context.extensionPath, 'webview/index.html') let lastUsedImageUri = vscode.Uri.file(path.resolve(homedir(), 'Desktop/code.png')) @@ -129,6 +130,9 @@ function activate(context) { } }) } + + outputChannel.appendLine(`${P_TITLE} activated`) + outputChannel.show(); } function getHtmlContent(htmlPath) { From 394607b5c55cdf35b2a8455d0804a050fe59b4d4 Mon Sep 17 00:00:00 2001 From: Vladislav Tupikin Date: Mon, 20 Jul 2020 23:32:02 +0300 Subject: [PATCH 2/3] channel removed. paths to JS files fixed --- src/extension.js | 18 +++++++----------- webview/index.html | 6 +++--- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/extension.js b/src/extension.js index 9890c36..fda4f18 100644 --- a/src/extension.js +++ b/src/extension.js @@ -14,7 +14,6 @@ const P_TITLE = 'Polacode 📸' * @param {vscode.ExtensionContext} context */ function activate(context) { - const outputChannel = vscode.window.createOutputChannel(P_TITLE) const htmlPath = path.resolve(context.extensionPath, 'webview/index.html') let lastUsedImageUri = vscode.Uri.file(path.resolve(homedir(), 'Desktop/code.png')) @@ -131,16 +130,13 @@ function activate(context) { }) } - outputChannel.appendLine(`${P_TITLE} activated`) - outputChannel.show(); -} - -function getHtmlContent(htmlPath) { - const htmlContent = fs.readFileSync(htmlPath, 'utf-8') - return htmlContent.replace(/script src="([^"]*)"/g, (match, src) => { - const realSource = 'vscode-resource:' + path.resolve(htmlPath, '..', src) - return `script src="${realSource}"` - }) + function getHtmlContent(htmlPath) { + const htmlContent = fs.readFileSync(htmlPath, 'utf-8') + const absolutePath = vscode.Uri.file(context.asAbsolutePath('./webview')) + const webviewPath = panel.webview.asWebviewUri(absolutePath).toString() + + return htmlContent.replace(/{{root}}/g, webviewPath); + } } exports.activate = activate diff --git a/webview/index.html b/webview/index.html index 65df1a8..87a555f 100644 --- a/webview/index.html +++ b/webview/index.html @@ -96,8 +96,8 @@ - - - + + + \ No newline at end of file From ff9c542d6c327f7f3aef54f926f0c2fb10afdae2 Mon Sep 17 00:00:00 2001 From: Vladisav Tupikin Date: Mon, 20 Jul 2020 23:53:27 +0300 Subject: [PATCH 3/3] argument htmlPath removed --- src/extension.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/extension.js b/src/extension.js index fda4f18..a407f7a 100644 --- a/src/extension.js +++ b/src/extension.js @@ -22,7 +22,7 @@ function activate(context) { vscode.window.registerWebviewPanelSerializer('polacode', { async deserializeWebviewPanel(_panel, state) { panel = _panel - panel.webview.html = getHtmlContent(htmlPath) + panel.webview.html = getHtmlContent() panel.webview.postMessage({ type: 'restore', innerHTML: state.innerHTML, @@ -42,7 +42,7 @@ function activate(context) { localResourceRoots: [vscode.Uri.file(path.join(context.extensionPath, 'webview'))] }) - panel.webview.html = getHtmlContent(htmlPath) + panel.webview.html = getHtmlContent() const selectionListener = setupSelectionSync() panel.onDidDispose(() => { @@ -130,7 +130,7 @@ function activate(context) { }) } - function getHtmlContent(htmlPath) { + function getHtmlContent() { const htmlContent = fs.readFileSync(htmlPath, 'utf-8') const absolutePath = vscode.Uri.file(context.asAbsolutePath('./webview')) const webviewPath = panel.webview.asWebviewUri(absolutePath).toString()