From 684dd39181bdb8d7eb3c85700bab09c6ea97a35e Mon Sep 17 00:00:00 2001 From: Dave Holoway Date: Sun, 18 Aug 2019 13:22:12 +0100 Subject: [PATCH] Fix logcat not displaying (#64) * update LogcatContent constructor to use single deviceID argument * add support for WebviewPanel for displaying logcat data Fixes #63 --- src/contentprovider.js | 2 +- src/logcat.js | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/contentprovider.js b/src/contentprovider.js index 8dc9de0..67574e0 100644 --- a/src/contentprovider.js +++ b/src/contentprovider.js @@ -44,7 +44,7 @@ class AndroidContentProvider /*extends TextDocumentContentProvider*/ { provideLogcatDocumentContent(uri) { // LogcatContent depends upon AndroidContentProvider, so we must delay-load this const { LogcatContent } = require('./logcat'); - var doc = this._docs[uri] = new LogcatContent(this, uri); + var doc = this._docs[uri] = new LogcatContent(uri.query); return doc.content; } } diff --git a/src/logcat.js b/src/logcat.js index 05e1509..b23b79d 100644 --- a/src/logcat.js +++ b/src/logcat.js @@ -15,10 +15,8 @@ const { D } = require('./util'); */ class LogcatContent { - constructor(provider/*: AndroidContentProvider*/, uri/*: Uri*/) { - this._provider = provider; - this._uri = uri; - this._logcatid = uri.query; + constructor(deviceid) { + this._logcatid = deviceid; this._logs = []; this._htmllogs = []; this._oldhtmllogs = []; @@ -27,7 +25,7 @@ class LogcatContent { this._refreshRate = 200; // ms this._state = ''; this._htmltemplate = ''; - this._adbclient = new ADBClient(uri.query); + this._adbclient = new ADBClient(deviceid); this._initwait = new Promise((resolve, reject) => { this._state = 'connecting'; LogcatContent.initWebSocketServer() @@ -276,6 +274,21 @@ function openLogcatWindow(vscode) { .then(devices => { if (!Array.isArray(devices)) return; // user cancelled (or no devices connected) devices.forEach(device => { + if (vscode.window.createWebviewPanel) { + const panel = vscode.window.createWebviewPanel( + 'androidlogcat', // Identifies the type of the webview. Used internally + `logcat-${device.serial}`, // Title of the panel displayed to the user + vscode.ViewColumn.One, // Editor column to show the new webview panel in. + { + enableScripts: true, + } + ); + const logcat = new LogcatContent(device.serial); + logcat.content.then(html => { + panel.webview.html = html; + }); + return; + } var uri = AndroidContentProvider.getReadLogcatUri(device.serial); return vscode.commands.executeCommand("vscode.previewHtml",uri,vscode.ViewColumn.Two); });