@@ -462,6 +462,8 @@ async function loadEditor() {
462462
463463var editor ;
464464var currentTimeout = null ;
465+ var saveRetryCount = 0 ;
466+ const MAX_SAVE_RETRIES = 3 ;
465467
466468// Save the File Contents and update the UI
467469async function saveFileContents ( path ) {
@@ -482,16 +484,24 @@ async function saveFileContents(path) {
482484 if ( await workflow . writeFile ( path , contents , offset ) ) {
483485 setFilename ( workflow . currentFilename ) ;
484486 setSaved ( true ) ;
487+ saveRetryCount = 0 ;
485488 } else {
486- await showMessage ( `Saving file '${ workflow . currentFilename } failed.` ) ;
489+ await showMessage ( `Saving file '${ workflow . currentFilename } ' failed.` ) ;
487490 }
488491 } catch ( e ) {
489492 console . error ( "write failed" , e , e . stack ) ;
490493 unchanged = Math . min ( oldUnchanged , unchanged ) ;
491494 if ( currentTimeout != null ) {
492495 clearTimeout ( currentTimeout ) ;
493496 }
494- currentTimeout = setTimeout ( saveFileContents , 2000 ) ;
497+ saveRetryCount ++ ;
498+ if ( saveRetryCount < MAX_SAVE_RETRIES ) {
499+ console . log ( `Save retry ${ saveRetryCount } of ${ MAX_SAVE_RETRIES } ...` ) ;
500+ currentTimeout = setTimeout ( saveFileContents , 2000 ) ;
501+ } else {
502+ saveRetryCount = 0 ;
503+ await showMessage ( `Saving file '${ workflow . currentFilename } ' failed after multiple attempts. Check your connection and try again.` ) ;
504+ }
495505 }
496506}
497507
@@ -535,6 +545,11 @@ async function onTextChange(update) {
535545}
536546
537547function disconnectCallback ( ) {
548+ if ( currentTimeout != null ) {
549+ clearTimeout ( currentTimeout ) ;
550+ currentTimeout = null ;
551+ }
552+ saveRetryCount = 0 ;
538553 updateUIConnected ( false ) ;
539554}
540555
0 commit comments