@@ -690,11 +690,13 @@ function run(hash, dhash, msg, error) {
690690 runner . contentWindow . location . replace ( loc ) ;
691691 if ( ! ! navigator . mediaDevices && ! ! navigator . mediaDevices . getUserMedia ) {
692692 document . getElementById ( 'startRecButton' ) . style . display = '' ;
693+ document . getElementById ( 'exportAndroidButton' ) . style . display = '' ;
693694 }
694695 } else {
695696 runner . contentWindow . location . replace ( 'about:blank' ) ;
696697 document . getElementById ( 'runner' ) . style . display = 'none' ;
697698 document . getElementById ( 'startRecButton' ) . style . display = 'none' ;
699+ document . getElementById ( 'exportAndroidButton' ) . style . display = 'none' ;
698700 }
699701
700702 if ( hash || msg ) {
@@ -732,14 +734,51 @@ function goto(line, col) {
732734}
733735
734736function exportAndroid ( ) {
737+ sweetAlert ( {
738+ title : "App Information" ,
739+ text : "App Name" ,
740+ type : "input" ,
741+ showCancelButton : true ,
742+ confirmButtonText : "Build App" ,
743+ closeOnConfirm : false ,
744+ inputPlaceholder : "CodeWorld App"
745+ } ,
746+ function ( inputValue ) {
747+ if ( inputValue === false ) {
748+ return false ;
749+ }
750+ if ( inputValue === "" ) {
751+ swal . showInputError ( "Please enter a name for your app" ) ;
752+ return false ;
753+ }
754+ compileAndExportAndroid ( {
755+ appName : inputValue ,
756+ } ) ;
757+ sweetAlert ( {
758+ title : "Please Wait" ,
759+ text : "Your app is being built" ,
760+ imageUrl : "https://upload.wikimedia.org/wikipedia/commons/b/b1/Loading_icon.gif" ,
761+ showConfirmButton : false ,
762+ allowOutsideClick : false ,
763+ allowEscapeKey : false
764+ } ) ;
765+ } ) ;
766+ }
767+
768+ function compileAndExportAndroid ( appProps ) {
735769 var src = window . codeworldEditor . getValue ( ) ;
736770 var data = new FormData ( ) ;
737771 data . append ( 'source' , src ) ;
738772 data . append ( 'mode' , window . buildMode ) ;
773+ for ( var prop in appProps ) {
774+ data . append ( prop , appProps [ prop ] ) ;
775+ }
776+ document . getElementById ( 'exportAndroidButton' ) . disabled = true ;
739777
740778 sendHttp ( 'POST' , 'exportAndroid' , data , function ( request ) {
741779 if ( request . status != 200 ) {
742- alert ( "Android build FAILED" ) ;
780+ sweetAlert ( "Android Build Failed" , "Something went wrong!" , "error" ) ;
781+ document . getElementById ( 'exportAndroidButton' ) . disabled = false ;
743782 return ;
744783 }
745784 var response = JSON . parse ( request . response ) ;
@@ -748,17 +787,19 @@ function exportAndroid() {
748787 var data = new FormData ( ) ;
749788 data . append ( 'hash' , hash ) ;
750789 data . append ( 'mode' , window . buildMode ) ;
751- var props = { } ;
790+ var props = { } ;
752791 props . responseType = "blob" ;
753792
754793 sendHttpWithProps ( 'POST' , 'getAndroid' , data , props , function ( request ) {
755794 if ( request . status != 200 ) {
756- alert ( "Android fetch FAILED" ) ;
795+ sweetAlert ( "Android Fetch Failed" , "Something went wrong!" , "error" ) ;
796+ document . getElementById ( 'exportAndroidButton' ) . disabled = false ;
757797 return ;
758798 }
759- console . log ( "Success" ) ;
799+ swal ( "App Built!" , "Your CodeWorld app will now be downloaded" , "success" ) ;
800+
760801 var blob = request . response ;
761- var d = new Date ( ) ;
802+ var d = new Date ( ) ;
762803 var filename = 'codeworld_app_'
763804 + d . toDateString ( ) . split ( ' ' ) . join ( '_' ) + '_'
764805 + d . getHours ( ) + ':' + d . getMinutes ( ) + ':' + d . getSeconds ( )
@@ -774,6 +815,7 @@ function exportAndroid() {
774815 window . URL . revokeObjectURL ( url ) ;
775816
776817 a . remove ( ) ;
818+ document . getElementById ( 'exportAndroidButton' ) . disabled = false ;
777819 } ) ;
778820
779821 } ) ;
0 commit comments