@@ -18,9 +18,8 @@ import {
1818 TurnNavigationStart ,
1919 TurnNavigationStop ,
2020} from '@/actions/Actions'
21- import Dispatcher , { Action } from '@/stores/Dispatcher'
22- import NoSleep from '@/turnNavigation/nosleep.js'
23- import Api , { ApiImpl } from '@/api/Api'
21+ import Dispatcher , { Action } from '@/stores/Dispatcher'
22+ import Api , { ApiImpl } from '@/api/Api'
2423import {
2524 calcDist ,
2625 calcOrientation ,
@@ -29,13 +28,13 @@ import {
2928 toDegrees ,
3029 toNorthBased ,
3130} from '@/turnNavigation/GeoMethods'
32- import { Instruction , Path , RoutingArgs } from '@/api/graphhopper'
33- import { tr } from '@/translation/Translation'
34- import { SpeechSynthesizer } from '@/SpeechSynthesizer'
35- import { Pixel } from 'ol/pixel'
31+ import { Instruction , Path , RoutingArgs } from '@/api/graphhopper'
32+ import { tr } from '@/translation/Translation'
33+ import { SpeechSynthesizer } from '@/SpeechSynthesizer'
34+ import { Pixel } from 'ol/pixel'
3635import SettingsStore from '@/stores/SettingsStore'
37- import { meterToFt , meterToMiles } from '@/Converters'
38- import { Coordinate } from '@/utils'
36+ import { meterToFt , meterToMiles } from '@/Converters'
37+ import { Coordinate } from '@/utils'
3938
4039export interface TurnNavigationStoreState {
4140 // TODO replace "showUI" with a composite state depending on activePath, coordinate and instruction
@@ -96,7 +95,7 @@ export default class TurnNavigationStore extends Store<TurnNavigationStoreState>
9695 private readonly api : Api
9796 private watchId : any = undefined
9897 private interval : any
99- private noSleep : NoSleep | null = null
98+ private wakeLockSentinel : WakeLockSentinel | null = null ;
10099 private readonly speechSynthesizer : SpeechSynthesizer
101100 private readonly cs : MapCoordinateSystem
102101 private readonly settingsStore : SettingsStore
@@ -131,7 +130,7 @@ export default class TurnNavigationStore extends Store<TurnNavigationStoreState>
131130 syncView : true ,
132131 soundEnabled : Number . isNaN ( fakeGPSDelta ) ,
133132 forceVectorTiles : true ,
134- fullScreen : true ,
133+ fullScreen : false ,
135134 } as TNSettingsState ,
136135 instruction : { } as TNInstructionState ,
137136 thenInstructionSign : null ,
@@ -495,13 +494,7 @@ export default class TurnNavigationStore extends Store<TurnNavigationStoreState>
495494
496495 private async initFake ( ) {
497496 if ( this . state . settings . fullScreen )
498- try {
499- let el = document . documentElement
500- let requestFullscreenFct = el . requestFullscreen
501- requestFullscreenFct . call ( el )
502- } catch ( e ) {
503- console . log ( 'error requesting full screen ' + JSON . stringify ( e ) )
504- }
497+ this . requestFullscreen ( )
505498
506499 console . log ( 'started fake GPS injection' )
507500
@@ -596,7 +589,7 @@ export default class TurnNavigationStore extends Store<TurnNavigationStoreState>
596589 currentIndex ++
597590 } , 1000 )
598591
599- this . doNoSleep ( )
592+ this . requestWakeLock ( )
600593 }
601594
602595 private async createFixedPathFromAPICall ( ) {
@@ -615,11 +608,38 @@ export default class TurnNavigationStore extends Store<TurnNavigationStoreState>
615608 return response . paths [ 0 ]
616609 }
617610
618- private doNoSleep ( ) {
619- if ( ! this . noSleep ) this . noSleep = new NoSleep ( )
620- this . noSleep . enable ( ) . catch ( err => {
621- console . warn ( "NoSleep.js couldn't be initialized: " + JSON . stringify ( err ) )
622- } )
611+ private requestFullscreen ( ) {
612+ ( document . documentElement as any ) . requestFullscreen ?.( )
613+ . then ( ( ) => console . log ( 'requestFullscreen' ) )
614+ . catch ( ( err : any ) => {
615+ console . error ( `${ err . name } , ${ err . message } ` ) ;
616+ throw err ;
617+ } ) ;
618+ }
619+
620+ private requestWakeLock ( ) {
621+ if ( ! navigator . wakeLock ) return
622+ navigator . wakeLock . request ( "screen" )
623+ . then ( ( wakeLock : WakeLockSentinel ) => {
624+ this . wakeLockSentinel = wakeLock ;
625+ console . log ( "Wake Lock active." ) ;
626+ } )
627+ . catch ( ( err : any ) => {
628+ console . error ( `${ err . name } , ${ err . message } ` ) ;
629+ throw err ;
630+ } ) ;
631+ }
632+
633+ private releaseWakeLock ( ) {
634+ if ( ! this . wakeLockSentinel ) return
635+ this . wakeLockSentinel . release ( )
636+ . then ( ( ) => {
637+ this . wakeLockSentinel = null ;
638+ console . log ( "Wake Lock released." ) ;
639+ } )
640+ . catch ( ( err ) => {
641+ console . error ( "Failed to release Wake Lock:" , err . name , err . message ) ;
642+ } ) ;
623643 }
624644
625645 private locationUpdate ( pos : any ) {
@@ -636,13 +656,7 @@ export default class TurnNavigationStore extends Store<TurnNavigationStoreState>
636656 if ( this . watchId !== undefined ) navigator . geolocation . clearWatch ( this . watchId )
637657
638658 if ( this . state . settings . fullScreen )
639- try {
640- let el = document . documentElement
641- let requestFullscreenFct = el . requestFullscreen
642- requestFullscreenFct . call ( el )
643- } catch ( e ) {
644- console . log ( 'error requesting full screen ' + JSON . stringify ( e ) )
645- }
659+ this . requestFullscreen ( )
646660
647661 this . watchId = navigator . geolocation . watchPosition (
648662 this . locationUpdate . bind ( this ) ,
@@ -659,7 +673,7 @@ export default class TurnNavigationStore extends Store<TurnNavigationStoreState>
659673 )
660674
661675 // initialize and enable after potential fullscreen change
662- this . doNoSleep ( )
676+ this . requestWakeLock ( ) ;
663677 }
664678 }
665679
@@ -671,6 +685,6 @@ export default class TurnNavigationStore extends Store<TurnNavigationStoreState>
671685
672686 if ( this . watchId !== undefined ) navigator . geolocation . clearWatch ( this . watchId )
673687
674- if ( this . noSleep ) this . noSleep . disable ( )
688+ if ( this . wakeLockSentinel ) this . releaseWakeLock ( )
675689 }
676690}
0 commit comments