@@ -36,6 +36,7 @@ export class CodeEditorComponent implements OnInit {
3636 public selectedService ?: ServiceDescriptor ;
3737 public pyodideState = CompilerState . Unknown
3838 public pyodideStateContent ? = ""
39+ public apiRun = false
3940
4041 public fsroot = FsService . EmptyFolder ;
4142 public fslist : FsNodeList = [ ] ;
@@ -120,10 +121,15 @@ export class CodeEditorComponent implements OnInit {
120121 if ( state == CompilerState . Ready ) {
121122 this . didStateChangeReady ( content )
122123 }
124+ if ( state == CompilerState . Success || state == CompilerState . Error || state == CompilerState . Killed ) {
125+ this . apiConnectReset ( ) ;
126+ }
123127 this . pyodideState = state
124128 this . pyodideStateContent = content
125129 console . log ( "CodeEditorComponent:didStateChange:" , state )
126- this . outputWidget . didStateChange ( state , content )
130+ if ( ! this . apiRun || state != CompilerState . Stdin ) {
131+ this . outputWidget . didStateChange ( state , content )
132+ }
127133 }
128134
129135 public didStdout ( data :string ) {
@@ -151,7 +157,7 @@ export class CodeEditorComponent implements OnInit {
151157 this . outputWidget . print ( msgs [ i ] , fromAPI ?OutputType . STDINAPI :OutputType . STDIN )
152158 this . project ?. driver . sendStdin ( msgs [ i ] )
153159 }
154- if ( fromAPI || this . pyodideState != CompilerState . Stdin ) {
160+ if ( ! fromAPI || this . pyodideState != CompilerState . Stdin ) {
155161 this . outputWidget . enableStdin ( false )
156162 }
157163 }
@@ -232,6 +238,7 @@ export class CodeEditorComponent implements OnInit {
232238 }
233239
234240 async stopAll ( ) {
241+ this . apiRun = false
235242 console . log ( "stopAll:" )
236243
237244 if ( this . cmdConnect ) { this . cmdConnect . tal . closeConnection ( ) }
@@ -241,7 +248,13 @@ export class CodeEditorComponent implements OnInit {
241248 }
242249
243250 //-------------- API CONNECT
244- public async runProject ( useAPI = false ) {
251+ public async runProjectLocal ( ) {
252+ this . apiRun = false
253+ await this . runProject ( ) ;
254+ this . apiRun = false
255+ }
256+
257+ public async runProject ( ) {
245258 console . log ( "runProject:" )
246259 this . outputWidget . clearOutput ( )
247260
@@ -265,16 +278,24 @@ export class CodeEditorComponent implements OnInit {
265278
266279
267280 public async runConnectAPI ( ) {
281+ this . apiRun = true
268282 this . outputWidget . clearOutput ( )
269283 this . saveFile ( ) ;
270284
271285
272- this . apiConnect ( ) . then ( ( ) => {
273- //TODO: on success, new files are downloaded
274- // this.fileExplorer.refreshRoot()
275- } )
286+ await this . apiConnect ( )
287+
288+ this . apiRun = false
289+ this . fileExplorer . refreshRoot ( )
276290 }
277291
292+ async apiConnectReset ( ) {
293+ this . current_output_file = undefined ;
294+ this . cmdConnect = undefined ;
295+ this . outputWidget . enableStdin ( false )
296+ console . log ( "apiConnect:didConnectData:cmdConnect:" , this . cmdConnect ) ;
297+ }
298+
278299
279300 async apiConnect ( ) {
280301 console . log ( "apiConnect" )
@@ -285,6 +306,7 @@ export class CodeEditorComponent implements OnInit {
285306 }
286307 console . log ( "apiConnect:service:ok" )
287308
309+
288310
289311 let config = await this . compiler . readConfig ( )
290312 if ( ! config ) { return false }
@@ -376,8 +398,8 @@ export class CodeEditorComponent implements OnInit {
376398 this . output_files = message ;
377399 }
378400 else {
379- this . cmdConnect = undefined ;
380- console . log ( "apiConncect:cmdConnect:value :" , this . cmdConnect ) ;
401+ this . apiConnectReset ( ) ;
402+ console . log ( "apiConnect:didConnectClose:cmdConnect :" , this . cmdConnect ) ;
381403 }
382404 }
383405
@@ -388,9 +410,9 @@ export class CodeEditorComponent implements OnInit {
388410 this . project ?. driver . writeFile ( "/" + this . current_output_file , data )
389411 } ;
390412 if ( this . current_output_file === this . output_files [ this . output_files . length - 1 ] ) {
391- this . cmdConnect = undefined ;
413+ this . apiConnectReset ( ) ;
392414 }
393- console . log ( "apiConncect:cmdConnect:value :" , this . cmdConnect ) ;
415+ console . log ( "apiConnect:didConnectData:cmdConnect :" , this . cmdConnect ) ;
394416 }
395417 else {
396418 this . sendStdin ( data , true ) ;
0 commit comments