Linting and remove duplicate code

This commit is contained in:
2021-05-10 09:41:47 +00:00
parent f342c20b91
commit f4ca95d436
14 changed files with 1356 additions and 3754 deletions

View File

@@ -1,59 +1,70 @@
export const FullyKioskMixin = (C) => class extends C {
export const FullyKioskMixin = (C) =>
class extends C {
get isFully() {
return window.fully !== undefined;
return window.fully !== undefined;
}
constructor() {
super();
super();
if (!this.isFully) return;
if (!this.isFully) return;
this._fullyMotion = false;
this._motionTimeout = undefined;
this._fullyMotion = false;
this._motionTimeout = undefined;
for (const ev of ["screenOn", "screenOff", "pluggedAC", "pluggedUSB", "onBatteryLevelChanged", "unplugged", "networkReconnect", "onMotion"]) {
window.fully.bind(ev, `window.browser_mod.fully_update("${ev}");`);
}
for (const ev of [
"screenOn",
"screenOff",
"pluggedAC",
"pluggedUSB",
"onBatteryLevelChanged",
"unplugged",
"networkReconnect",
"onMotion",
]) {
window.fully.bind(ev, `window.browser_mod.fully_update("${ev}");`);
}
this._keepingAlive = false;
this._keepingAlive = false;
}
fully_update(event) {
if(!this.isFully) return
if(event === "screenOn") {
window.clearTimeout(this._keepAliveTimer);
if(!this._keepingAlive)
this.screen_update();
} else if (event === "screenOff") {
this.screen_update();
this._keepingAlive = false;
if(this.config.force_stay_awake) {
this._keepAliveTimer = window.setTimeout(() => {
this._keepingAlive = true;
window.fully.turnScreenOn();
window.fully.turnScreenOff();
}, 270000);
}
} else if (event === "onMotion") {
this.fullyMotionTriggered();
if (!this.isFully) return;
if (event === "screenOn") {
window.clearTimeout(this._keepAliveTimer);
if (!this._keepingAlive) this.screen_update();
} else if (event === "screenOff") {
this.screen_update();
this._keepingAlive = false;
if (this.config.force_stay_awake) {
this._keepAliveTimer = window.setTimeout(() => {
this._keepingAlive = true;
window.fully.turnScreenOn();
window.fully.turnScreenOff();
}, 270000);
}
} else if (event === "onMotion") {
this.fullyMotionTriggered();
}
this.sendUpdate({fully: {
battery: window.fully.getBatteryLevel(),
charging: window.fully.isPlugged(),
motion: this._fullyMotion,
ip: window.fully.getIp4Address(),
}})
this.sendUpdate({
fully: {
battery: window.fully.getBatteryLevel(),
charging: window.fully.isPlugged(),
motion: this._fullyMotion,
ip: window.fully.getIp4Address(),
},
});
}
fullyMotionTriggered() {
if(this._keepingAlive) return;
this._fullyMotion = true;
clearTimeout(this._motionTimeout);
this._motionTimeout = setTimeout(() => {
this._fullyMotion = false;
this.fully_update();
}, 5000);
if (this._keepingAlive) return;
this._fullyMotion = true;
clearTimeout(this._motionTimeout);
this._motionTimeout = setTimeout(() => {
this._fullyMotion = false;
this.fully_update();
}, 5000);
this.fully_update();
}
}
};