From 322bf33191da8693ac13662de0a4cf84938f083f Mon Sep 17 00:00:00 2001 From: Kenneth Rohde Christiansen Date: Fri, 21 Sep 2018 11:23:18 +0000 Subject: [PATCH] Fix #66 - reset orientation --- sensor-tester/build/bundled/index.html | 2 +- sensor-tester/build/bundled/service-worker.js | 2 +- sensor-tester/src/orientation-changer.js | 22 +++++++++++++------ sensor-tester/src/sensor-tester.js | 3 +++ sensor-tester/src/sensor-tests-page.js | 2 +- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/sensor-tester/build/bundled/index.html b/sensor-tester/build/bundled/index.html index 489153e6..366905b8 100644 --- a/sensor-tester/build/bundled/index.html +++ b/sensor-tester/build/bundled/index.html @@ -1 +1 @@ -Sensor tester \ No newline at end of file +Sensor tester \ No newline at end of file diff --git a/sensor-tester/build/bundled/service-worker.js b/sensor-tester/build/bundled/service-worker.js index c6313528..3a551235 100644 --- a/sensor-tester/build/bundled/service-worker.js +++ b/sensor-tester/build/bundled/service-worker.js @@ -37,7 +37,7 @@ /* eslint-disable indent, no-unused-vars, no-multiple-empty-lines, max-nested-callbacks, space-before-function-paren, quotes, comma-spacing */ 'use strict'; -var precacheConfig = [["images/app-icon-128.png","5c67806f6bd216fe041c9fc4d9a7fc8a"],["images/app-icon-144.png","aea337293cc66ce854f5f20e54b5197f"],["images/app-icon-192.png","c9d515ce9875b4fcf765e4fb1c59d700"],["images/app-icon-48.png","7894f4722aa34a56a6edbb22318ec6d1"],["index.html","d1d1517fcf921adf56b5502167c5cff7"],["manifest.json","c207e76d6dc3a3b0ce2e74c61ffe1256"]]; +var precacheConfig = [["images/app-icon-128.png","5c67806f6bd216fe041c9fc4d9a7fc8a"],["images/app-icon-144.png","aea337293cc66ce854f5f20e54b5197f"],["images/app-icon-192.png","c9d515ce9875b4fcf765e4fb1c59d700"],["images/app-icon-48.png","7894f4722aa34a56a6edbb22318ec6d1"],["index.html","73e437568d9af372e09bb722f504cc34"],["manifest.json","c207e76d6dc3a3b0ce2e74c61ffe1256"]]; var cacheName = 'sw-precache-v3--' + (self.registration ? self.registration.scope : ''); diff --git a/sensor-tester/src/orientation-changer.js b/sensor-tester/src/orientation-changer.js index c254029c..dc74515e 100644 --- a/sensor-tester/src/orientation-changer.js +++ b/sensor-tester/src/orientation-changer.js @@ -12,23 +12,31 @@ export class OrientationChanger extends LitElement { || docEl.mozRequestFullScreen || docEl.msRequestFullscreen; this._cancelFullScreen = document.exitFullscreen || document.webkitExitFullscreen || document.mozCancelFullScreen || document.msExitFullscreen; - this._orientation = screen.msOrientation || (screen.orientation || screen.mozOrientation || {}); + this.reset = this.reset.bind(this); + + screen.orientation.addEventListener('change', this.reset); + } + + reset() { + this._cancelFullScreen.call(document); + this.shadowRoot.querySelector('#one').checked = true; } async lock(orientation) { this._requestFullScreen.call(document.documentElement); + screen.orientation.removeEventListener('change', this.reset); try { - await this._orientation.lock(orientation); + await screen.orientation.lock(orientation); } catch(err) { - console.log("screen.orientation.lock() is not available on this device."); - this._cancelFullScreen.call(document); + console.log("Cannot lock to the requested orientation."); + this.reset(); }; + screen.orientation.addEventListener('change', this.reset); } unlock() { - this._orientation.unlock(); - this._cancelFullScreen.call(document); - this.shadowRoot.querySelector('#one').checked = true; + screen.orientation.unlock(); + this.reset(); } render() { diff --git a/sensor-tester/src/sensor-tester.js b/sensor-tester/src/sensor-tester.js index 081cebd6..16adfe69 100644 --- a/sensor-tester/src/sensor-tester.js +++ b/sensor-tester/src/sensor-tester.js @@ -25,6 +25,9 @@ class SensorTester extends LitElement { const parts = pathname.slice(1).split('/'); this.page = parts[parts.length - 1] || 'accelerometer'; + if (screen.orientation) { + screen.orientation.unlock(); + } if (this.drawer && !this.drawer.persistent) { this.drawer.close(); } diff --git a/sensor-tester/src/sensor-tests-page.js b/sensor-tester/src/sensor-tests-page.js index 4b731985..35582918 100644 --- a/sensor-tester/src/sensor-tests-page.js +++ b/sensor-tester/src/sensor-tests-page.js @@ -243,7 +243,7 @@ class SensorTestsPage extends LitElement {
Sensor is not supported by the browser or the device.
-
+