@@ -12,21 +12,43 @@ import State from "./state";
1212import { Capacitor } from "@capacitor/core" ;
1313
1414const addListeners = ( ) => {
15+ const longPressDelay = 700 ;
16+ let longPressTimerId = null ;
17+ let suppressClickUntil = 0 ;
18+
19+ const clearLongPressTimer = ( ) => {
20+ if ( longPressTimerId !== null ) {
21+ clearTimeout ( longPressTimerId ) ;
22+ longPressTimerId = null ;
23+ }
24+ } ;
25+
26+ const startLongPress = ( ) => {
27+ clearLongPressTimer ( ) ;
28+ longPressTimerId = setTimeout ( ( ) => {
29+ suppressClickUntil = Date . now ( ) + 600 ;
30+ Location . disableLocationListeningCompletely ( ) ;
31+ clearLongPressTimer ( ) ;
32+ } , longPressDelay ) ;
33+ } ;
1534
1635 // Bouton Geolocalisation
17- DOM . $geolocateBtn . addEventListener ( "click" , ( ) => { Location . locationOnOff ( ) ; } ) ;
36+ DOM . $geolocateBtn . addEventListener ( "click" , ( ) => {
37+ if ( Date . now ( ) < suppressClickUntil ) {
38+ return ;
39+ }
40+ Location . locationOnOff ( ) ;
41+ } ) ;
42+ DOM . $geolocateBtn . addEventListener ( "mousedown" , startLongPress ) ;
43+ DOM . $geolocateBtn . addEventListener ( "touchstart" , startLongPress , { passive : true } ) ;
44+ DOM . $geolocateBtn . addEventListener ( "mouseup" , clearLongPressTimer ) ;
45+ DOM . $geolocateBtn . addEventListener ( "mouseleave" , clearLongPressTimer ) ;
46+ DOM . $geolocateBtn . addEventListener ( "touchend" , clearLongPressTimer ) ;
47+ DOM . $geolocateBtn . addEventListener ( "touchcancel" , clearLongPressTimer ) ;
1848 // HACK: ios
1949 if ( Capacitor . getPlatform ( ) === "ios" ) {
2050 DOM . $geolocateBtn . addEventListener ( "click" , ( ) => {
21- if ( typeof DeviceOrientationEvent !== "undefined" && typeof DeviceOrientationEvent . requestPermission === "function" ) {
22- DeviceOrientationEvent . requestPermission ( )
23- . then ( permissionState => {
24- if ( permissionState === "granted" ) {
25- window . addEventListener ( "deviceorientation" , Location . getOrientation ) ;
26- }
27- } )
28- . catch ( console . error ) ;
29- }
51+ Location . requestOrientationPermission ( ) ;
3052 } ) ;
3153 }
3254
0 commit comments