Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a452d6

Browse files
committed
detect when react webview is loaded
1 parent68e9e75 commit9a452d6

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

‎src/editor/ReactWebView.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as path from 'path'
77
*/
88
classReactWebView{
99
//@ts-ignore
10+
publicloaded:boolean
1011
privatepanel:vscode.WebviewPanel
1112
privateextensionPath:string
1213
privatedisposables: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-
constonReceive=(action:string|CR.Action)=>vscode.commands.executeCommand('coderoad.receive_action',action)
30+
constonReceive=(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-
publiccreateOrShow(column:number):void{
63+
publiccreateOrShow(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+
letwebPanelListener=setInterval(()=>{
75+
if(this.loaded){
76+
setTimeout(callback)
77+
clearInterval(webPanelListener)
78+
}
79+
},200)
80+
}
6381
}
6482

6583
privatecreateWebviewPanel(column:number):vscode.WebviewPanel{

‎src/editor/commands/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,8 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre
5050
orientation:0,
5151
groups:[{groups:[{}],size:0.6},{groups:[{}],size:0.4}],
5252
})
53-
webview.createOrShow(column)
54-
// NOTE: createOrShow and layout command cannot be async
55-
// this creates an async issue where the webview cannot detect when it has been initialized
56-
setTimeout(()=>{
57-
machine.send('WEBVIEW_INITIALIZED')
58-
},2000)
53+
constcallback=()=>machine.send('WEBVIEW_INITIALIZED')
54+
webview.createOrShow(column,callback)
5955
},
6056
// launch a new tutorial
6157
// NOTE: may be better to move into action as logic is primarily non-vscode

‎web-app/src/App.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as CR from 'typings'
33

44
importDebuggerfrom'./components/Debugger'
55
importRoutesfrom'./Routes'
6+
import{send}from'./utils/vscode'
67
importDataContext,{initialState,initialData}from'./utils/DataContext'
78

89
interfaceReceivedEvent{
@@ -35,6 +36,11 @@ const App = () => {
3536
}
3637
})
3738

39+
// trigger progress when webview loaded
40+
React.useEffect(()=>{
41+
send('WEBVIEW_LOADED')
42+
})
43+
3844
constvalue={
3945
state,
4046
position:data.position,
@@ -46,7 +52,7 @@ const App = () => {
4652
return(
4753
<DataContext.Providervalue={value}>
4854
<div>
49-
{/*<Debugger value={value} /> */}
55+
<Debuggervalue={value}/>
5056
<Routesstate={state}/>
5157
</div>
5258
</DataContext.Provider>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp