@@ -29,6 +29,7 @@ workflows[CONNTYPE.Web] = new WebWorkflow();
2929
3030let workflow = null ;
3131let unchanged = 0 ;
32+ let connectionPromise = null ;
3233
3334const btnRestart = document . querySelector ( '.btn-restart' ) ;
3435const btnClear = document . querySelector ( '.btn-clear' ) ;
@@ -253,8 +254,10 @@ function setFilename(path) {
253254}
254255
255256async function chooseConnection ( ) {
257+ // Don't allow more than one dialog
258+ if ( connectionPromise ) return ;
256259 // Get the promise first
257- let p = connectionType . open ( ) ;
260+ connectionPromise = connectionType . open ( ) ;
258261
259262 // Disable any buttons in validBackends, but not in workflows
260263 let modal = connectionType . getModal ( ) ;
@@ -266,7 +269,8 @@ async function chooseConnection() {
266269 } ;
267270
268271 // Wait for the user to click a button
269- let connType = await p ;
272+ let connType = await connectionPromise ;
273+ connectionPromise = null
270274 if ( isValidBackend ( connType ) ) {
271275 return getBackendWorkflow ( connType ) ;
272276 }
@@ -507,7 +511,7 @@ editor = new EditorView({
507511 parent : document . querySelector ( '#editor' )
508512} ) ;
509513
510- function setupXterm ( ) {
514+ async function setupXterm ( ) {
511515 state . terminal = new Terminal ( {
512516 theme : {
513517 background : '#333' ,
@@ -522,8 +526,10 @@ function setupXterm() {
522526 state . terminal . loadAddon ( new WebLinksAddon ( ) ) ;
523527
524528 state . terminal . open ( document . getElementById ( 'terminal' ) ) ;
525- state . terminal . onData ( ( data ) => {
526- workflow . serialTransmit ( data ) ;
529+ state . terminal . onData ( ( data ) => async function ( e ) {
530+ if ( await checkConnected ( ) ) {
531+ workflow . serialTransmit ( data ) ;
532+ }
527533 } ) ;
528534}
529535
@@ -547,7 +553,7 @@ function loadParameterizedContent() {
547553}
548554
549555document . addEventListener ( 'DOMContentLoaded' , async ( event ) => {
550- setupXterm ( ) ;
556+ await setupXterm ( ) ;
551557 btnConnect . forEach ( ( element ) => {
552558 element . addEventListener ( 'click' , async function ( e ) {
553559 e . preventDefault ( ) ;
0 commit comments