implemented NoSleep.js as suggested in this issue: https://github.com/RobinLinus/snapdrop/issues/412

This commit is contained in:
schlagmichdoch 2023-01-17 14:19:51 +01:00
parent 474eb9290f
commit 168d10a898
4 changed files with 31 additions and 2 deletions

View file

@ -288,12 +288,13 @@
</symbol>
</svg>
<!-- Scripts -->
<script src="scripts/zip.min.js" async></script>
<script src="scripts/util.js"></script>
<script src="scripts/network.js"></script>
<script src="scripts/qrcode.js" async></script>
<script src="scripts/ui.js"></script>
<script src="scripts/theme.js" async></script>
<script src="scripts/qrcode.js" async></script>
<script src="scripts/zip.min.js" async></script>
<script src="scripts/NoSleep.min.js" async></script>
<!-- Sounds -->
<audio id="blop" autobuffer="true">
<source src="/sounds/blop.mp3" type="audio/mpeg">

2
public/scripts/NoSleep.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -284,6 +284,8 @@ class PeerUI {
_bindListeners(el) {
if(!window.pasteMode.activated) {
el.querySelector('input').addEventListener('change', e => this._onFilesSelected(e));
el.addEventListener('click', _ => NoSleepUI.enable());
el.addEventListener('touchstart', _ => NoSleepUI.enable());
el.addEventListener('drop', e => this._onDrop(e));
el.addEventListener('dragend', e => this._onDragEnd(e));
el.addEventListener('dragleave', e => this._onDragEnd(e));
@ -435,6 +437,7 @@ class ReceiveDialog extends Dialog {
}
}
}
class ReceiveFileDialog extends ReceiveDialog {
constructor() {
@ -642,6 +645,7 @@ class ReceiveRequestDialog extends ReceiveDialog {
this.requestingPeerId = null;
if (accepted) {
Events.fire('set-progress', {peerId: this._peerId, progress: 0, status: 'wait'});
NoSleepUI.enable();
}
}
@ -1145,6 +1149,26 @@ class WebShareTargetUI {
}
}
class NoSleepUI {
constructor() {
NoSleepUI._nosleep = new NoSleep();
}
static enable() {
if (!this._interval) {
NoSleepUI._nosleep.enable();
NoSleepUI._interval = setInterval(_ => NoSleepUI.disable(), 10000);
}
}
static disable() {
if ($$('x-peer[status]') === null) {
clearInterval(NoSleepUI._interval);
NoSleepUI._nosleep.disable();
}
}
}
class PersistentStorage {
constructor() {
if (!('indexedDB' in window)) {
@ -1337,6 +1361,7 @@ class PairDrop {
const notifications = new Notifications();
const networkStatusUI = new NetworkStatusUI();
const webShareTargetUI = new WebShareTargetUI();
const noSleepUI = new NoSleepUI();
});
}
}

View file

@ -8,6 +8,7 @@ var urlsToCache = [
'scripts/util.js',
'scripts/qrcode.js',
'scripts/zip.min.js',
'scripts/NoSleep.min.js',
'scripts/theme.js',
'sounds/blop.mp3',
'images/favicon-96x96.png'