@@ -7,6 +7,7 @@ import * as path from 'path'
7
7
*/
8
8
class ReactWebView {
9
9
// @ts -ignore
10
+ public loaded : boolean
10
11
private panel : vscode . WebviewPanel
11
12
private extensionPath : string
12
13
private disposables : vscode . Disposable [ ] = [ ]
@@ -26,7 +27,14 @@ class ReactWebView {
26
27
this . panel . onDidDispose ( ( ) => this . dispose ( ) , null , this . disposables )
27
28
28
29
// 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
+ }
30
38
this . panel . webview . onDidReceiveMessage ( onReceive , null , this . disposables )
31
39
32
40
// update panel on changes
@@ -52,14 +60,24 @@ class ReactWebView {
52
60
// TODO: prevent window from moving to the left when no windows remain on rights
53
61
}
54
62
55
- public createOrShow ( column : number ) : void {
63
+ public createOrShow ( column : number , callback ?: ( ) => void ) : void {
56
64
// If we already have a panel, show it.
57
65
// Otherwise, create a new panel.
58
66
if ( this . panel && this . panel . webview ) {
59
67
this . panel . reveal ( column )
60
68
} else {
61
69
this . panel = this . createWebviewPanel ( column )
62
70
}
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
+ }
63
81
}
64
82
65
83
private createWebviewPanel ( column : number ) : vscode . WebviewPanel {
0 commit comments