@@ -7,6 +7,7 @@ import * as path from 'path'
77 */
88class ReactWebView {
99//@ts -ignore
10+ public loaded :boolean
1011private panel :vscode . WebviewPanel
1112private extensionPath :string
1213private disposables :vscode . Disposable [ ] = [ ]
@@ -23,10 +24,17 @@ class ReactWebView {
2324
2425// Listen for when the panel is disposed
2526// This happens when the user closes the panel or when the panel is closed programatically
26- // this.panel.onDidDispose(() => this.dispose(), null, this.disposables)
27+ this . panel . onDidDispose ( ( ) => this . dispose ( ) , null , this . disposables )
2728
2829// Handle messages from the webview
29- const onReceive = ( action :string | CR . Action ) => vscode . commands . executeCommand ( 'coderoad.receive_action' , action )
30+ const onReceive = ( action :string | CR . Action ) => {
31+ // await loading of webview in React before proceeding with loaded state
32+ if ( action === 'WEBVIEW_LOADED' ) {
33+ this . loaded = true
34+ } else {
35+ vscode . commands . executeCommand ( 'coderoad.receive_action' , action )
36+ }
37+ }
3038this . panel . webview . onDidReceiveMessage ( onReceive , null , this . disposables )
3139
3240// update panel on changes
@@ -38,15 +46,6 @@ class ReactWebView {
3846this . panel . reveal ( vscode . ViewColumn . Two )
3947}
4048
41- this . panel . onDidDispose ( ( ) => {
42- updateWindows ( )
43- } )
44-
45- // this.panel.onDidChangeViewState(() => {
46- // console.log('onDidChangeViewState')
47- // updateWindows()
48- // })
49-
5049// prevents new panels from going ontop of coderoad panel
5150vscode . window . onDidChangeActiveTextEditor ( param => {
5251if ( ! param || param . viewColumn !== vscode . ViewColumn . Two ) {
@@ -61,14 +60,24 @@ class ReactWebView {
6160// TODO: prevent window from moving to the left when no windows remain on rights
6261}
6362
64- public createOrShow ( column :number ) :void {
63+ public createOrShow ( column :number , callback ?: ( ) => void ) :void {
6564// If we already have a panel, show it.
6665// Otherwise, create a new panel.
6766if ( this . panel && this . panel . webview ) {
6867this . panel . reveal ( column )
6968} else {
7069this . panel = this . createWebviewPanel ( column )
7170}
71+ if ( callback ) {
72+ // listen for when webview is loaded
73+ // unfortunately there is no easy way of doing this
74+ let webPanelListener = setInterval ( ( ) => {
75+ if ( this . loaded ) {
76+ setTimeout ( callback )
77+ clearInterval ( webPanelListener )
78+ }
79+ } , 200 )
80+ }
7281}
7382
7483private createWebviewPanel ( column :number ) :vscode . WebviewPanel {
@@ -145,8 +154,8 @@ class ReactWebView {
145154 <link rel="stylesheet" type="text/css" href="${ styleUri } ">
146155 <meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${ n1 } ' 'nonce-${ n2 } ' 'nonce-${ n3 } '; style-src vscode-resource: 'unsafe-inline' http: https: data:;">
147156 <base href="${ vscode . Uri . file ( path . join ( this . extensionPath , 'build' ) ) . with ( {
148- scheme :'vscode-resource' ,
149- } ) } /">
157+ scheme :'vscode-resource' ,
158+ } ) } /">
150159 <style></style>
151160 </head>
152161