@@ -7,6 +7,7 @@ import * as path from 'path'
77 */
88class ReactWebView {
99 // @ts -ignore
10+ public loaded : boolean
1011 private panel : vscode . WebviewPanel
1112 private extensionPath : string
1213 private disposables : vscode . Disposable [ ] = [ ]
@@ -26,7 +27,14 @@ class ReactWebView {
2627 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+ }
3038 this . panel . webview . onDidReceiveMessage ( onReceive , null , this . disposables )
3139
3240 // update panel on changes
@@ -52,14 +60,24 @@ class ReactWebView {
5260 // TODO: prevent window from moving to the left when no windows remain on rights
5361 }
5462
55- public createOrShow ( column : number ) : void {
63+ public createOrShow ( column : number , callback ?: ( ) => void ) : void {
5664 // If we already have a panel, show it.
5765 // Otherwise, create a new panel.
5866 if ( this . panel && this . panel . webview ) {
5967 this . panel . reveal ( column )
6068 } else {
6169 this . panel = this . createWebviewPanel ( column )
6270 }
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+ }
6381 }
6482
6583 private createWebviewPanel ( column : number ) : vscode . WebviewPanel {
0 commit comments