Skip to content

Commit

Permalink
Fix intel#66 - reset orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
kenchris committed Sep 21, 2018
1 parent 64c8821 commit 5ab0970
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion sensor-tester/build/bundled/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sensor-tester/build/bundled/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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","07378b4d70197ddaa5d4f2432c2dc29f"],["manifest.json","c207e76d6dc3a3b0ce2e74c61ffe1256"]];
var cacheName = 'sw-precache-v3--' + (self.registration ? self.registration.scope : '');


Expand Down
20 changes: 14 additions & 6 deletions sensor-tester/src/orientation-changer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.shadowRoot.querySelector('#one').checked = true;
}

async lock(orientation) {
screen.orientation.removeEventListener('change', this.reset);
this._requestFullScreen.call(document.documentElement);
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.unlock();
};
screen.orientation.addEventListener('change', this.reset);
}

unlock() {
this._orientation.unlock();
// Exiting fullscreen, unlocks screen.
this._cancelFullScreen.call(document);
this.shadowRoot.querySelector('#one').checked = true;
}

render() {
Expand Down
6 changes: 6 additions & 0 deletions sensor-tester/src/sensor-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class SensorTester extends LitElement {

const parts = pathname.slice(1).split('/');
this.page = parts[parts.length - 1] || 'accelerometer';
if (screen.orientation) {
screen.orientation.unlock();
const exit = document.exitFullscreen || document.webkitExitFullscreen
|| document.mozCancelFullScreen || document.msExitFullscreen;
exit();
}
if (this.drawer && !this.drawer.persistent) {
this.drawer.close();
}
Expand Down
2 changes: 1 addition & 1 deletion sensor-tester/src/sensor-tests-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class SensorTestsPage extends LitElement {
<div class="${classMap({'hidden': this.isSupported})}">Sensor is not supported by the browser or the device.</div>
<div class="${classMap({'hidden': !this.isSupported})}">
<div class="${this.referenceFrame}">
<div class="${classMap({'hidden': this.referenceFrame === 'device' || !screen.orientation})}">
<orientation-changer></orientation-changer>
</div>
Expand Down

0 comments on commit 5ab0970

Please sign in to comment.