Only start NoSleep after the first user interaction

This commit is contained in:
Lucas Verney 2018-06-28 15:08:56 +02:00
parent a4564ad053
commit 4493dc35fe
2 changed files with 21 additions and 3 deletions

View File

@ -47,7 +47,7 @@ export default {
}, },
created() { created() {
this.initializePositionWatching(); this.initializePositionWatching();
this.setNoSleep(); this.listenForFirstInteraction();
this.$store.dispatch('fetchReports'); this.$store.dispatch('fetchReports');
window.addEventListener('keydown', this.hideReportDialogOnEsc); window.addEventListener('keydown', this.hideReportDialogOnEsc);
}, },
@ -162,6 +162,26 @@ export default {
this.dialog = false; this.dialog = false;
} }
}, },
handleFirstUserInteraction() {
this.setNoSleep();
window.removeEventListener('mousemove', this.handleFirstUserInteraction, false);
window.removeEventListener('mousedown', this.handleFirstUserInteraction, false);
window.removeEventListener('keypress', this.handleFirstUserInteraction, false);
window.removeEventListener('DOMMouseScroll', this.handleFirstUserInteraction, false);
window.removeEventListener('mousewheel', this.handleFirstUserInteraction, false);
window.removeEventListener('touchmove', this.handleFirstUserInteraction, false);
window.removeEventListener('MSPointerMove', this.handleFirstUserInteraction, false);
},
listenForFirstInteraction() {
window.addEventListener('mousemove', this.handleFirstUserInteraction, false);
window.addEventListener('mousedown', this.handleFirstUserInteraction, false);
window.addEventListener('keypress', this.handleFirstUserInteraction, false);
window.addEventListener('DOMMouseScroll', this.handleFirstUserInteraction, false);
window.addEventListener('mousewheel', this.handleFirstUserInteraction, false);
window.addEventListener('touchmove', this.handleFirstUserInteraction, false);
window.addEventListener('MSPointerMove', this.handleFirstUserInteraction, false);
},
}, },
}; };
</script> </script>

View File

@ -19,8 +19,6 @@
</template> </template>
<script> <script>
import Vue from 'vue';
import { messages } from '@/i18n'; import { messages } from '@/i18n';
import { storageAvailable } from '@/tools'; import { storageAvailable } from '@/tools';