From 4493dc35fea9ec4ed096907b72c2d05e983a5786 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Thu, 28 Jun 2018 15:08:56 +0200 Subject: [PATCH] Only start NoSleep after the first user interaction --- src/views/Map.vue | 22 +++++++++++++++++++++- src/views/Settings.vue | 2 -- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/views/Map.vue b/src/views/Map.vue index a01667f..a5b038b 100644 --- a/src/views/Map.vue +++ b/src/views/Map.vue @@ -47,7 +47,7 @@ export default { }, created() { this.initializePositionWatching(); - this.setNoSleep(); + this.listenForFirstInteraction(); this.$store.dispatch('fetchReports'); window.addEventListener('keydown', this.hideReportDialogOnEsc); }, @@ -162,6 +162,26 @@ export default { 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); + }, }, }; diff --git a/src/views/Settings.vue b/src/views/Settings.vue index 27059e9..6acecf4 100644 --- a/src/views/Settings.vue +++ b/src/views/Settings.vue @@ -19,8 +19,6 @@