@@ -877,48 +877,59 @@ function openCodeSharingPanel(){
877877
878878// end here
879879
880+ function isCurrentFileSaved ( ) {
881+ // if(file.path != undefined) return true
882+ var data = editor . getValue ( ) ;
883+ // console.log(file.path);
884+ ipc . send ( 'save-data' , data , file . path ) ;
885+ if ( file . path != undefined ) return true ;
886+ else return false ;
887+ }
888+
880889// code sharing function
881890
882891function shareCode ( ) {
883- $ ( '#code-sharing-box' ) . html ( '<h5>Waiting...</h5>' ) ;
884- app . listen ( 4000 , function ( ) {
885- // console.log('listening at 4000');
886- var tunnel = localtunnel ( 4000 , function ( err , tunnel ) {
887- if ( err ) {
888- // console.log(err);
892+ if ( isCurrentFileSaved ( ) ) {
893+ $ ( '#code-sharing-box' ) . html ( '<h5>Waiting...</h5>' ) ;
894+ app . listen ( 4000 , function ( ) {
895+ // console.log('listening at 4000');
896+ var tunnel = localtunnel ( 4000 , function ( err , tunnel ) {
897+ if ( err ) {
898+ // console.log(err);
899+ $ ( '#code-sharing-box' ) . html ( err ) ;
900+ }
901+
902+ // the assigned public url for your tunnel
903+ // i.e. https://abcdefgjhij.localtunnel.me
904+ $ ( '#code-sharing-box' ) . html ( '<h5>Share this url with whome you want to share</h5><br>' ) ;
905+ $ ( '#code-sharing-box' ) . append ( '<h5>' + tunnel . url + '</h5><br>' ) ;
906+ $ ( '#code-sharing-box' ) . append ( '<button class = "btn" id = "commit-changes-sender" onclick="commitChangesSender()">Commit Changes</button><br><br>' ) ;
907+ $ ( '#code-sharing-box' ) . append ( '<button class = "btn" id = "disconnect" onclick="disconnect()">Disconnect</button>' ) ;
908+ // console.log(tunnel.url);
909+ } ) ;
910+ tunnel . on ( 'error' , function ( err ) {
889911 $ ( '#code-sharing-box' ) . html ( err ) ;
890- }
891-
892- // the assigned public url for your tunnel
893- // i.e. https://abcdefgjhij.localtunnel.me
894- $ ( '#code-sharing-box' ) . html ( '<h5>Share this url with whome you want to share</h5><br>' ) ;
895- $ ( '#code-sharing-box' ) . append ( '<h5>' + tunnel . url + '</h5><br>' ) ;
896- $ ( '#code-sharing-box' ) . append ( '<button class = "btn" id = "commit-changes-sender" onclick="commitChangesSender()">Commit Changes</button>' ) ;
897- $ ( '#code-sharing-box' ) . append ( '<button class = "btn" id = "disconnect" onclick="disconnect()">Disconnect</button><br><br>' ) ;
898- // console.log(tunnel.url);
912+ } ) ;
899913 } ) ;
900- tunnel . on ( 'error' , function ( err ) {
901- $ ( '#code-sharing-box' ) . html ( err ) ;
914+ // console.log(file);
915+ io . on ( 'connection' , function ( socket ) {
916+ clients . push ( socket ) ;
917+ socket . emit ( 'file' , { id : file . id , name :file . name , remote_path :file . path , data :file . editor . getValue ( ) } ) ;
918+ socket . on ( 'commit-changes' , function ( data ) {
919+ // console.log('hello');
920+ if ( file . id == data . id && file . path == data . path ) {
921+ file . editor . setValue ( data . data ) ;
922+ editor . setValue ( data . data ) ;
923+ }
924+ files [ '#' + data . id ] . editor . setValue ( data . data ) ;
925+ } ) ;
902926 } ) ;
903- } ) ;
904- // console.log(file);
905- io . on ( 'connection' , function ( socket ) {
906- clients . push ( socket ) ;
907- socket . emit ( 'file' , { id : file . id , name :file . name , remote_path :file . path , data :file . editor . getValue ( ) } ) ;
908- socket . on ( 'commit-changes' , function ( data ) {
909- // console.log('hello');
910- if ( file . id == data . id && file . path == data . path ) {
911- file . editor . setValue ( data . data ) ;
912- editor . setValue ( data . data ) ;
913- }
914- files [ '#' + data . id ] . editor . setValue ( data . data ) ;
915- } ) ;
916- } ) ;
927+ }
917928}
918929
919930function connect ( flag ) {
920931 if ( ! flag ) {
921- $ ( '#code-sharing-box' ) . html ( '<input class = "input-field" id = "url"><br> <br><button class ="btn" onclick = "connect(true)">Connect</button>' ) ;
932+ $ ( '#code-sharing-box' ) . html ( '<input placeholder = "URL" class = "input-field" id = "url"><br> <br><button class ="btn" onclick = "connect(true)">Connect</button>' ) ;
922933 } else {
923934 let url = $ ( '#url' ) . val ( ) ;
924935 $ ( '#code-sharing-box' ) . html ( '<h5>Waiting...</h5>' ) ;
@@ -927,7 +938,7 @@ function connect(flag){
927938 remoteFile = data ;
928939 // newFileCount++;
929940 // newTab(undefined, newFileCount, path.basename(data.remote_path), data.data);
930- openFile ( data . data , undefined , path . basename ( data . remote_path ) , data . remote_path ) ;
941+ openFile ( data . data , undefined , data . name , data . remote_path ) ;
931942 // console.log(data);
932943 // socket.emit('my other event', { my: 'data' });
933944 $ ( '#code-sharing-box' ) . html ( '<button class = "btn" id = "commit_changes" onclick="commitChanges()">Commit Changes</button><br><br>' ) ;
@@ -949,6 +960,9 @@ function connect(flag){
949960 }
950961 }
951962 } ) ;
963+ socket . on ( 'error' , function ( error ) {
964+ $ ( '#code-sharing-box' ) . html ( error ) ;
965+ } ) ;
952966 }
953967}
954968
0 commit comments