@@ -161,7 +161,7 @@ class InstallationSuccessView {
161
161
closeBtn . className = 'gm-btn' ;
162
162
closeBtn . onclick = ( ) => {
163
163
this . plugin . closeWidget ( ) ;
164
- this . plugin . setView ( 'InitialView' ) ;
164
+ this . plugin . viewAtNextopening = 'InitialView' ;
165
165
} ;
166
166
167
167
const restartBtn = document . createElement ( 'button' ) ;
@@ -174,7 +174,7 @@ class InstallationSuccessView {
174
174
} ;
175
175
this . plugin . instance . sendEvent ( json ) ;
176
176
this . plugin . closeWidget ( ) ;
177
- this . plugin . setView ( 'InitialView' ) ;
177
+ this . plugin . viewAtNextopening = 'InitialView' ;
178
178
} ;
179
179
180
180
actionsSection . appendChild ( closeBtn ) ;
@@ -243,7 +243,7 @@ class InstallationFailedView {
243
243
closeBtn . className = 'gm-btn' ;
244
244
closeBtn . onclick = ( ) => {
245
245
this . plugin . closeWidget ( ) ;
246
- this . plugin . setView ( 'InitialView' ) ;
246
+ this . plugin . viewAtNextopening = 'InitialView' ;
247
247
} ;
248
248
249
249
actionsSection . appendChild ( closeBtn ) ;
@@ -347,6 +347,10 @@ class InitialView {
347
347
this . i18n = plugin . i18n ;
348
348
this . fileUploadWorker = null ;
349
349
350
+ this . removeListenerDragAndDropOver = null ;
351
+ this . removeListenerDragAndDropLeave = null ;
352
+ this . removeListenerDragAndDropDrop = null ;
353
+
350
354
try {
351
355
this . fileUploadWorker = this . plugin . instance . createFileUploadWorker ( ) ;
352
356
this . fileUploadWorker . onmessage = ( event ) => {
@@ -374,6 +378,16 @@ class InitialView {
374
378
case 'PROGRESS' :
375
379
this . fileUploaderComponent . updateProgress ( msg . value * 100 , msg . uploadedSize , msg . fileSize ) ;
376
380
break ;
381
+ case 'SOCKET_FAIL' :
382
+ this . fileUploaderComponent . showUploadError (
383
+ this . i18n . FILE_UPLOAD_CONNECTION_FAILED ||
384
+ 'Something went wrong while connecting to the server.'
385
+ ) ;
386
+ this . fileUploaderComponent . setEnabled ( false ) ;
387
+ break ;
388
+ case 'SOCKET_SUCCESS' :
389
+ this . fileUploaderComponent . reset ( ) ;
390
+ break ;
377
391
default :
378
392
break ;
379
393
}
@@ -483,7 +497,6 @@ class InitialView {
483
497
dragDropText : this . i18n . DRAG_DROP_TEXT || 'DRAG & DROP APK FILE TO INSTALL' ,
484
498
browseButtonText : this . i18n . BROWSE_BUTTON_TEXT || 'BROWSE' ,
485
499
accept : '.apk' ,
486
- maxFileSize : 900 ,
487
500
classes : 'gm-apk-uploader' ,
488
501
i18n : this . plugin . i18n ,
489
502
} ) ;
@@ -496,6 +509,28 @@ class InitialView {
496
509
container . appendChild ( separator2 ) ;
497
510
container . appendChild ( apkSection ) ;
498
511
512
+ // Attach the drag and drop events on root to handle the drag of an apk
513
+ if ( this . instance . store . state . isDragAndDropForUploadFileEnabled ) {
514
+ this . fileUploaderComponent . setEnabled ( true ) ;
515
+ this . addListenerOnRoot ( ) ;
516
+ } else {
517
+ this . fileUploaderComponent . setEnabled ( false ) ;
518
+ this . removeListenerOnRoot ( ) ;
519
+ }
520
+
521
+ this . instance . store . subscribe (
522
+ ( { isDragAndDropForUploadFileEnabled} ) => {
523
+ if ( isDragAndDropForUploadFileEnabled ) {
524
+ this . fileUploaderComponent . setEnabled ( true ) ;
525
+ this . addListenerOnRoot ( ) ;
526
+ } else {
527
+ this . fileUploaderComponent . setEnabled ( false ) ;
528
+ this . removeListenerOnRoot ( ) ;
529
+ }
530
+ } ,
531
+ [ 'isDragAndDropForUploadFileEnabled' ] ,
532
+ ) ;
533
+
499
534
return container ;
500
535
}
501
536
@@ -511,6 +546,36 @@ class InitialView {
511
546
const msg = { type : 'upload' , file} ;
512
547
this . fileUploadWorker . postMessage ( msg ) ;
513
548
}
549
+
550
+ addListenerOnRoot ( ) {
551
+ this . removeListenerDragAndDropOver = this . instance . addListener ( this . instance . root , 'dragover' , ( event ) => {
552
+ event . preventDefault ( ) ;
553
+ event . stopPropagation ( ) ;
554
+ } ) ;
555
+
556
+ this . removeListenerDragAndDropLeave =
557
+ this . instance . addListener ( this . instance . root , 'dragleave' , ( event ) => {
558
+ event . preventDefault ( ) ;
559
+ event . stopPropagation ( ) ;
560
+ } ) ;
561
+
562
+ this . removeListenerDragAndDropDrop =
563
+ this . instance . addListener ( this . instance . root , 'drop' , ( event ) => {
564
+ event . preventDefault ( ) ;
565
+ event . stopPropagation ( ) ;
566
+
567
+ const file = event . dataTransfer . files [ 0 ] ;
568
+ if ( file && file . name && file . name . toLowerCase ( ) . endsWith ( '.apk' ) ) {
569
+ this . fileUploaderComponent . startUpload ( file ) ;
570
+ }
571
+ } ) ;
572
+ }
573
+
574
+ removeListenerOnRoot ( ) {
575
+ this . removeListenerDragAndDropOver ?. ( ) ;
576
+ this . removeListenerDragAndDropDrop ?. ( ) ;
577
+ this . removeListenerDragAndDropLeave ?. ( ) ;
578
+ }
514
579
}
515
580
516
581
// Plugin main class
@@ -526,6 +591,7 @@ module.exports = class GAPPSInstall extends OverlayPlugin {
526
591
this . instance . gappsInstall = this ;
527
592
this . instanciatedViews = new Map ( ) ; // Store rendered elements by view type
528
593
this . currentViewType = null ;
594
+ this . viewAtNextopening = null ;
529
595
this . GAPPSInstalled = false ;
530
596
531
597
this . registerToolbarButton ( ) ;
@@ -684,6 +750,10 @@ module.exports = class GAPPSInstall extends OverlayPlugin {
684
750
}
685
751
686
752
toggleWidget ( ) {
753
+ // if widget is opening laod the right view is needed
754
+ if ( this . viewAtNextopening && ! this . instance . store . getters . isWidgetOpened ( this . overlayID ) ) {
755
+ this . setView ( this . viewAtNextopening ) ;
756
+ }
687
757
super . toggleWidget ( ) ;
688
758
}
689
759
} ;
0 commit comments