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

Commit9d0c783

Browse files
authored
Merge pull requestcoderoad#12 from ShMcK/fix/disposable
Fix/disposable
2 parentsd71a7e5 +42d6f59 commit9d0c783

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

‎src/editor/ReactWebView.ts

Lines changed: 23 additions & 14 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[]=[]
@@ -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-
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
@@ -38,15 +46,6 @@ class ReactWebView {
3846
this.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
5150
vscode.window.onDidChangeActiveTextEditor(param=>{
5251
if(!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-
publiccreateOrShow(column:number):void{
63+
publiccreateOrShow(column:number,callback?:()=>void):void{
6564
// If we already have a panel, show it.
6665
// Otherwise, create a new panel.
6766
if(this.panel&&this.panel.webview){
6867
this.panel.reveal(column)
6968
}else{
7069
this.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+
letwebPanelListener=setInterval(()=>{
75+
if(this.loaded){
76+
setTimeout(callback)
77+
clearInterval(webPanelListener)
78+
}
79+
},200)
80+
}
7281
}
7382

7483
privatecreateWebviewPanel(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

‎src/editor/commands/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ let webview: any
3535
exportconstcreateCommands=({ context, machine, storage, git, position}:CreateCommandProps)=>({
3636
// initialize
3737
[COMMANDS.START]:()=>{
38+
if(webview){
39+
console.log('CodeRoad already loaded')
40+
return
41+
}
3842
// set local storage workspace
3943
setStorage(context.workspaceState)
4044

@@ -50,12 +54,8 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre
5054
orientation:0,
5155
groups:[{groups:[{}],size:0.6},{groups:[{}],size:0.4}],
5256
})
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)
57+
constcallback=()=>machine.send('WEBVIEW_INITIALIZED')
58+
webview.createOrShow(column,callback)
5959
},
6060
// launch a new tutorial
6161
// NOTE: may be better to move into action as logic is primarily non-vscode

‎web-app/src/App.tsx

Lines changed: 8 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{
@@ -13,6 +14,7 @@ const App = () => {
1314
const[state,setState]=React.useState(initialState)
1415
const[data,setData]:[CR.MachineContext,(data:CR.MachineContext)=>void]=React.useState(initialData)
1516

17+
// update state based on response from editor
1618
consthandleEvent=(event:ReceivedEvent):void=>{
1719
constmessage=event.data
1820
console.log('RECEIVED')
@@ -35,6 +37,11 @@ const App = () => {
3537
}
3638
})
3739

40+
// trigger progress when webview loaded
41+
React.useEffect(()=>{
42+
send('WEBVIEW_LOADED')
43+
})
44+
3845
constvalue={
3946
state,
4047
position:data.position,
@@ -46,7 +53,7 @@ const App = () => {
4653
return(
4754
<DataContext.Providervalue={value}>
4855
<div>
49-
<Debuggervalue={value}/>
56+
{/*<Debugger value={value} /> */}
5057
<Routesstate={state}/>
5158
</div>
5259
</DataContext.Provider>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp