diff --git a/activities/FractionBounce.activity/js/activity.js b/activities/FractionBounce.activity/js/activity.js index ee6ebb15a..a57b829a5 100644 --- a/activities/FractionBounce.activity/js/activity.js +++ b/activities/FractionBounce.activity/js/activity.js @@ -485,8 +485,7 @@ let app = new Vue({ this.acceleration = { x: acceleration.x, y: acceleration.y, - z: acceleration.z, - type: acceleration.type + z: acceleration.z }; this.accelerationUpdate(); }, diff --git a/activities/FractionBounce.activity/js/components/SugarDevice.js b/activities/FractionBounce.activity/js/components/SugarDevice.js index 3a3b39a19..082cdf972 100644 --- a/activities/FractionBounce.activity/js/components/SugarDevice.js +++ b/activities/FractionBounce.activity/js/components/SugarDevice.js @@ -3,14 +3,21 @@ Vue.component('sugar-device', { template: `
`, data: function () { return { - watchId: null + watchId: null, + readyToWatch: false, + frequencyExpected: 0 } }, - created: function () { - var cordovaScript = document.createElement('script'); - cordovaScript.setAttribute('type', 'text/javascript'); - cordovaScript.setAttribute('src', '../../cordova.js'); - document.head.appendChild(cordovaScript); + mounted: function () { + var vm = this; + requirejs(['domReady!'], function () { + document.addEventListener('deviceready', function() { + vm.readyToWatch = true; + if (vm.frequencyExpected > 0) { + vm.watchAcceleration(vm.frequencyExpected); + } + }, false); + }); }, methods: { isMobile() { @@ -85,13 +92,22 @@ Vue.component('sugar-device', { accelerometer.start(); } } else if (navigator.accelerometer) { - watchId = navigator.accelerometer.watchAcceleration(function () { - vm.accelerationCallback(accelerometer); - }, null, { frequency: frequency }); + if (vm.readyToWatch) { + vm.watchId = navigator.accelerometer.watchAcceleration(function (accelerometer) { + vm.accelerationCallback(accelerometer); + }, null, { frequency: frequency }); + } else { + vm.frequencyExpected = frequency; + } + } else { + vm.frequencyExpected = frequency; } }, accelerationCallback: function (acceleration) { + if (this.readyToWatch) { + this.readyToWatch = false; + } this.$emit('acceleration-callback', acceleration); },