@@ -81,6 +81,7 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
8181 private _css : ReadiumCSS ;
8282 private _preferencesEditor : EpubPreferencesEditor | null = null ;
8383 private _injector : Injector | null = null ;
84+ private _isNavigating = false ;
8485 private readonly _readiumRulesPromise : Promise < IInjectableRule [ ] > ;
8586 private readonly _injectablesConfig : IInjectablesConfig ;
8687 private readonly _contentProtection : IContentProtectionConfig ;
@@ -758,33 +759,45 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
758759 }
759760
760761 public goBackward ( _ : boolean , cb : ( ok : boolean ) => void ) : void {
762+ if ( this . _isNavigating ) { cb ( false ) ; return ; }
763+ this . _isNavigating = true ;
761764 if ( this . _layout === Layout . fixed ) {
762- this . changeResource ( - 1 ) ;
763- cb ( true ) ;
765+ this . changeResource ( - 1 ) . then ( ( ok ) => {
766+ this . _isNavigating = false ;
767+ cb ( ok ) ;
768+ } ) ;
764769 } else {
765770 this . _cframes [ 0 ] ?. msg ?. send ( "go_prev" , undefined , async ( ack ) => {
766- if ( ack )
767- // OK
771+ if ( ack ) {
772+ this . _isNavigating = false ;
768773 cb ( true ) ;
769- else
770- // Need to change resources because we're at the beginning of the current one
771- cb ( await this . changeResource ( - 1 ) ) ;
774+ } else {
775+ const ok = await this . changeResource ( - 1 ) ;
776+ this . _isNavigating = false ;
777+ cb ( ok ) ;
778+ }
772779 } ) ;
773780 }
774781 }
775782
776783 public goForward ( _ : boolean , cb : ( ok : boolean ) => void ) : void {
784+ if ( this . _isNavigating ) { cb ( false ) ; return ; }
785+ this . _isNavigating = true ;
777786 if ( this . _layout === Layout . fixed ) {
778- this . changeResource ( 1 ) ;
779- cb ( true ) ;
787+ this . changeResource ( 1 ) . then ( ( ok ) => {
788+ this . _isNavigating = false ;
789+ cb ( ok ) ;
790+ } ) ;
780791 } else {
781792 this . _cframes [ 0 ] ?. msg ?. send ( "go_next" , undefined , async ( ack ) => {
782- if ( ack )
783- // OK
793+ if ( ack ) {
794+ this . _isNavigating = false ;
784795 cb ( true ) ;
785- else
786- // Need to change resources because we're at the end of the current one
787- cb ( await this . changeResource ( 1 ) ) ;
796+ } else {
797+ const ok = await this . changeResource ( 1 ) ;
798+ this . _isNavigating = false ;
799+ cb ( ok ) ;
800+ }
788801 } ) ;
789802 }
790803 }
@@ -907,8 +920,14 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
907920 return cb ( this . listeners . handleLocator ( locator ) ) ;
908921 }
909922
923+ if ( this . _isNavigating ) { cb ( false ) ; return ; }
924+ this . _isNavigating = true ;
925+
910926 this . currentLocation = this . positions . find ( p => p . href === link ! . href ) ! ;
911- this . apply ( ) . then ( ( ) => this . loadLocator ( locator , ( ok ) => cb ( ok ) ) ) . then ( ( ) => {
927+ this . apply ( ) . then ( ( ) => this . loadLocator ( locator , ( ok ) => {
928+ this . _isNavigating = false ;
929+ cb ( ok ) ;
930+ } ) ) . then ( ( ) => {
912931 // Now that we've gone to the right locator, we can attach the listeners.
913932 // Doing this only at this stage reduces janky UI with multiple locator updates.
914933 this . attachListener ( ) ;
0 commit comments