Skip to content
This repository was archived by the owner on Sep 17, 2021. It is now read-only.

Commit b82b49b

Browse files
committed
Updates for devtools class
1 parent 67abca2 commit b82b49b

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/extension.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ import WebSocket from 'ws';
44
import QuickPickItem = vscode.QuickPickItem;
55
import * as utils from './utils';
66

7-
const settings = vscode.workspace.getConfiguration('vscode-devtools-for-chrome');
8-
const hostname = settings.get('hostname') as string || 'localhost';
9-
const port = settings.get('port') as number || 9222;
10-
const debuggerType = 'devtools-for-chrome';
7+
let settings: vscode.WorkspaceConfiguration;
8+
let hostname: string;
9+
let port: number;
10+
const debuggerType: string = 'devtools-for-chrome';
1111

1212
export function activate(context: vscode.ExtensionContext) {
13+
settings = vscode.workspace.getConfiguration('vscode-devtools-for-chrome');
14+
hostname = settings.get('hostname') as string || 'localhost';
15+
port = settings.get('port') as number || 9222;
16+
1317
context.subscriptions.push(vscode.commands.registerCommand('devtools-for-chrome.launch', async () => {
1418
launch(context);
1519
}));
@@ -121,7 +125,7 @@ class DevToolsPanel {
121125
if (DevToolsPanel.currentPanel) {
122126
DevToolsPanel.currentPanel._panel.reveal(column);
123127
} else {
124-
const panel = vscode.window.createWebviewPanel('devtools-for-chrome', 'DevTools', column || vscode.ViewColumn.One, {
128+
const panel = vscode.window.createWebviewPanel('devtools-for-chrome', 'DevTools', column || vscode.ViewColumn.Two, {
125129
enableScripts: true,
126130
enableCommandUris: true,
127131
retainContextWhenHidden: true
@@ -164,6 +168,7 @@ class DevToolsPanel {
164168
DevToolsPanel.currentPanel = undefined;
165169

166170
this._panel.dispose();
171+
this._disposeSocket();
167172

168173
while (this._disposables.length) {
169174
const x = this._disposables.pop();
@@ -173,18 +178,21 @@ class DevToolsPanel {
173178
}
174179
}
175180

181+
private _disposeSocket() {
182+
if (this._socket) {
183+
// Reset the socket since the devtools have been reloaded
184+
this._socket.onerror = undefined;
185+
this._socket.onopen = undefined;
186+
this._socket.onclose = undefined;
187+
this._socket.onmessage = undefined;
188+
this._socket.close();
189+
this._socket = undefined;
190+
}
191+
}
192+
176193
private _onMessageFromWebview(message: string) {
177194
if (message === 'ready') {
178-
if (this._socket) {
179-
// Reset the socket since the devtools have been reloaded
180-
this._socket.onerror = undefined;
181-
this._socket.onopen = undefined;
182-
this._socket.onclose = undefined;
183-
this._socket.onmessage = undefined;
184-
this._socket.close();
185-
}
186-
187-
this._socket = undefined;
195+
this._disposeSocket();
188196
}
189197

190198
if (!this._socket) {

0 commit comments

Comments
 (0)