@@ -477,6 +477,8 @@ async function loadEditor() {
477477
478478var editor ;
479479var currentTimeout = null ;
480+ var saveRetryCount = 0 ;
481+ const MAX_SAVE_RETRIES = 3 ;
480482
481483// Save the File Contents and update the UI
482484async function saveFileContents ( path ) {
@@ -497,16 +499,24 @@ async function saveFileContents(path) {
497499 if ( await workflow . writeFile ( path , contents , offset ) ) {
498500 setFilename ( workflow . currentFilename ) ;
499501 setSaved ( true ) ;
502+ saveRetryCount = 0 ;
500503 } else {
501- await showMessage ( `Saving file '${ workflow . currentFilename } failed.` ) ;
504+ await showMessage ( `Saving file '${ workflow . currentFilename } ' failed.` ) ;
502505 }
503506 } catch ( e ) {
504507 console . error ( "write failed" , e , e . stack ) ;
505508 unchanged = Math . min ( oldUnchanged , unchanged ) ;
506509 if ( currentTimeout != null ) {
507510 clearTimeout ( currentTimeout ) ;
508511 }
509- currentTimeout = setTimeout ( await saveFileContents ( path ) , 2000 ) ;
512+ saveRetryCount ++ ;
513+ if ( saveRetryCount < MAX_SAVE_RETRIES ) {
514+ console . log ( `Save retry ${ saveRetryCount } of ${ MAX_SAVE_RETRIES } ...` ) ;
515+ currentTimeout = setTimeout ( await saveFileContents ( path ) , 2000 ) ;
516+ } else {
517+ saveRetryCount = 0 ;
518+ await showMessage ( `Saving file '${ workflow . currentFilename } ' failed after multiple attempts. Check your connection and try again.` ) ;
519+ }
510520 }
511521}
512522
@@ -550,6 +560,11 @@ async function onTextChange(update) {
550560}
551561
552562function disconnectCallback ( ) {
563+ if ( currentTimeout != null ) {
564+ clearTimeout ( currentTimeout ) ;
565+ currentTimeout = null ;
566+ }
567+ saveRetryCount = 0 ;
553568 updateUIConnected ( false ) ;
554569}
555570
0 commit comments