@@ -94,7 +94,7 @@ async function launch(context: vscode.ExtensionContext, launchUrl?: string, chro
9494 telemetryReporter . sendTelemetryEvent ( 'launch/error/tab_not_found' , telemetryProps ) ;
9595 attach ( context , viaConfig ) ;
9696 } else {
97- DevToolsPanel . createOrShow ( context . extensionPath , target . webSocketDebuggerUrl ) ;
97+ DevToolsPanel . createOrShow ( context , target . webSocketDebuggerUrl ) ;
9898 }
9999}
100100
@@ -116,7 +116,7 @@ async function attach(context: vscode.ExtensionContext, viaConfig: boolean) {
116116
117117 vscode . window . showQuickPick ( items ) . then ( ( selection ) => {
118118 if ( selection ) {
119- DevToolsPanel . createOrShow ( context . extensionPath , selection . detail as string ) ;
119+ DevToolsPanel . createOrShow ( context , selection . detail as string ) ;
120120 }
121121 } ) ;
122122 } else {
@@ -164,36 +164,38 @@ async function getListOfTargets(hostname: string, port: number): Promise<Array<a
164164class DevToolsPanel {
165165 private static currentPanel : DevToolsPanel ;
166166 private readonly _panel : vscode . WebviewPanel ;
167+ private readonly _context : vscode . ExtensionContext ;
167168 private readonly _extensionPath : string ;
168169 private readonly _targetUrl : string ;
169170 private _socket : WebSocket = undefined ;
170171 private _isConnected : boolean = false ;
171172 private _messages : any [ ] = [ ] ;
172173 private _disposables : vscode . Disposable [ ] = [ ] ;
173174
174- public static createOrShow ( extensionPath : string , targetUrl : string ) {
175- const column = vscode . window . activeTextEditor ? vscode . window . activeTextEditor . viewColumn : undefined ;
175+ public static createOrShow ( context : vscode . ExtensionContext , targetUrl : string ) {
176+ const column = vscode . ViewColumn . Beside ;
176177
177178 if ( DevToolsPanel . currentPanel ) {
178179 DevToolsPanel . currentPanel . _panel . reveal ( column ) ;
179180 } else {
180- const panel = vscode . window . createWebviewPanel ( 'devtools-for-chrome' , 'DevTools' , column || vscode . ViewColumn . Two , {
181+ const panel = vscode . window . createWebviewPanel ( 'devtools-for-chrome' , 'DevTools' , column , {
181182 enableScripts : true ,
182183 enableCommandUris : true ,
183184 retainContextWhenHidden : true
184185 } ) ;
185186
186- DevToolsPanel . currentPanel = new DevToolsPanel ( panel , extensionPath , targetUrl ) ;
187+ DevToolsPanel . currentPanel = new DevToolsPanel ( panel , context , targetUrl ) ;
187188 }
188189 }
189190
190- public static revive ( panel : vscode . WebviewPanel , extensionPath : string , targetUrl : string ) {
191- DevToolsPanel . currentPanel = new DevToolsPanel ( panel , extensionPath , targetUrl ) ;
191+ public static revive ( panel : vscode . WebviewPanel , context : vscode . ExtensionContext , targetUrl : string ) {
192+ DevToolsPanel . currentPanel = new DevToolsPanel ( panel , context , targetUrl ) ;
192193 }
193194
194- private constructor ( panel : vscode . WebviewPanel , extensionPath : string , targetUrl : string ) {
195+ private constructor ( panel : vscode . WebviewPanel , context : vscode . ExtensionContext , targetUrl : string ) {
195196 this . _panel = panel ;
196- this . _extensionPath = extensionPath ;
197+ this . _context = context ;
198+ this . _extensionPath = context . extensionPath ;
197199 this . _targetUrl = targetUrl ;
198200
199201 this . _update ( ) ;
@@ -251,6 +253,10 @@ class DevToolsPanel {
251253 this . _disposeSocket ( ) ;
252254 } else if ( message . substr ( 0 , 10 ) === 'telemetry:' ) {
253255 return this . _sendTelemetryMessage ( message . substr ( 10 ) ) ;
256+ } else if ( message . substr ( 0 , 9 ) === 'getState:' ) {
257+ return this . _getDevtoolsState ( ) ;
258+ } else if ( message . substr ( 0 , 9 ) === 'setState:' ) {
259+ return this . _setDevtoolsState ( message . substr ( 9 ) ) ;
254260 }
255261
256262 if ( ! this . _socket ) {
@@ -320,6 +326,26 @@ class DevToolsPanel {
320326 telemetryReporter . sendTelemetryEvent ( telemetry . name , telemetry . properties , telemetry . metrics ) ;
321327 }
322328
329+ private _getDevtoolsState ( ) {
330+ const allPrefsKey = 'devtools-preferences' ;
331+ const allPrefs : any = this . _context . workspaceState . get ( allPrefsKey ) ||
332+ {
333+ uiTheme : '"dark"' ,
334+ screencastEnabled : false
335+ } ;
336+ this . _panel . webview . postMessage ( `preferences:${ JSON . stringify ( allPrefs ) } ` ) ;
337+ }
338+
339+ private _setDevtoolsState ( state : string ) {
340+ // Parse the preference from the message and store it
341+ const pref = JSON . parse ( state ) as { name : string , value : string } ;
342+
343+ const allPrefsKey = 'devtools-preferences' ;
344+ const allPrefs : any = this . _context . workspaceState . get ( allPrefsKey ) || { } ;
345+ allPrefs [ pref . name ] = pref . value ;
346+ this . _context . workspaceState . update ( allPrefsKey , allPrefs ) ;
347+ }
348+
323349 private _update ( ) {
324350 this . _panel . webview . html = this . _getHtmlForWebview ( ) ;
325351 }
0 commit comments