From f8b28444c453ffaa390bd8f42fd27e6ba24e1175 Mon Sep 17 00:00:00 2001 From: _Tradam Date: Fri, 23 May 2025 00:36:49 +0900 Subject: fixed for android --- main.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/main.js b/main.js index 4a46d96..a1f91d4 100644 --- a/main.js +++ b/main.js @@ -30,14 +30,7 @@ function animate() { } renderer.setAnimationLoop(animate); -if ( location.protocol != "https:" ) { -location.href = "https:" + window.location.href.substring( window.location.protocol.length ); -} -function permission () { - if ( typeof( DeviceMotionEvent ) !== "undefined" && typeof( DeviceMotionEvent.requestPermission ) === "function" ) { - // (optional) Do something before API request prompt. - DeviceMotionEvent.requestPermission() - .then( response => { +const motionEvent = (response) => { // (optional) Do something after API prompt dismissed. if ( response == "granted" ) { window.addEventListener("deviceorientation", (e) => { @@ -76,8 +69,22 @@ function permission () { document.getElementById("info").textContent=`x: ${Math.round(cube.position.x * 10)}, y: ${Math.round(cube.position.y * 10)}`; }); } - }) +} + +if ( location.protocol != "https:" ) { +location.href = "https:" + window.location.href.substring( window.location.protocol.length ); +} +function permission () { + if ( typeof( DeviceMotionEvent ) !== "undefined") { + // (optional) Do something before API request prompt. + if(typeof( DeviceMotionEvent.requestPermission ) === "function") { + DeviceMotionEvent.requestPermission() + .then(motionEvent) .catch( console.error ) + } + else { + motionEvent("granted"); + } } else { alert( "DeviceMotionEvent is not defined" ); } -- cgit v1.2.3