@@ -690,11 +690,13 @@ function run(hash, dhash, msg, error) {
690
690
runner . contentWindow . location . replace ( loc ) ;
691
691
if ( ! ! navigator . mediaDevices && ! ! navigator . mediaDevices . getUserMedia ) {
692
692
document . getElementById ( 'startRecButton' ) . style . display = '' ;
693
+ document . getElementById ( 'exportAndroidButton' ) . style . display = '' ;
693
694
}
694
695
} else {
695
696
runner . contentWindow . location . replace ( 'about:blank' ) ;
696
697
document . getElementById ( 'runner' ) . style . display = 'none' ;
697
698
document . getElementById ( 'startRecButton' ) . style . display = 'none' ;
699
+ document . getElementById ( 'exportAndroidButton' ) . style . display = 'none' ;
698
700
}
699
701
700
702
if ( hash || msg ) {
@@ -732,14 +734,51 @@ function goto(line, col) {
732
734
}
733
735
734
736
function 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 ) {
735
769
var src = window . codeworldEditor . getValue ( ) ;
736
770
var data = new FormData ( ) ;
737
771
data . append ( 'source' , src ) ;
738
772
data . append ( 'mode' , window . buildMode ) ;
773
+ for ( var prop in appProps ) {
774
+ data . append ( prop , appProps [ prop ] ) ;
775
+ }
776
+ document . getElementById ( 'exportAndroidButton' ) . disabled = true ;
739
777
740
778
sendHttp ( 'POST' , 'exportAndroid' , data , function ( request ) {
741
779
if ( request . status != 200 ) {
742
- alert ( "Android build FAILED" ) ;
780
+ sweetAlert ( "Android Build Failed" , "Something went wrong!" , "error" ) ;
781
+ document . getElementById ( 'exportAndroidButton' ) . disabled = false ;
743
782
return ;
744
783
}
745
784
var response = JSON . parse ( request . response ) ;
@@ -748,17 +787,19 @@ function exportAndroid() {
748
787
var data = new FormData ( ) ;
749
788
data . append ( 'hash' , hash ) ;
750
789
data . append ( 'mode' , window . buildMode ) ;
751
- var props = { } ;
790
+ var props = { } ;
752
791
props . responseType = "blob" ;
753
792
754
793
sendHttpWithProps ( 'POST' , 'getAndroid' , data , props , function ( request ) {
755
794
if ( request . status != 200 ) {
756
- alert ( "Android fetch FAILED" ) ;
795
+ sweetAlert ( "Android Fetch Failed" , "Something went wrong!" , "error" ) ;
796
+ document . getElementById ( 'exportAndroidButton' ) . disabled = false ;
757
797
return ;
758
798
}
759
- console . log ( "Success" ) ;
799
+ swal ( "App Built!" , "Your CodeWorld app will now be downloaded" , "success" ) ;
800
+
760
801
var blob = request . response ;
761
- var d = new Date ( ) ;
802
+ var d = new Date ( ) ;
762
803
var filename = 'codeworld_app_'
763
804
+ d . toDateString ( ) . split ( ' ' ) . join ( '_' ) + '_'
764
805
+ d . getHours ( ) + ':' + d . getMinutes ( ) + ':' + d . getSeconds ( )
@@ -774,6 +815,7 @@ function exportAndroid() {
774
815
window . URL . revokeObjectURL ( url ) ;
775
816
776
817
a . remove ( ) ;
818
+ document . getElementById ( 'exportAndroidButton' ) . disabled = false ;
777
819
} ) ;
778
820
779
821
} ) ;
0 commit comments