mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-22 07:46:17 -04:00
fix background animation speeding up uncontrollably
This commit is contained in:
parent
e611ed13d0
commit
516e1ddf59
1 changed files with 10 additions and 5 deletions
|
@ -25,7 +25,7 @@ class PeersUI {
|
||||||
Events.on('peers', e => this._onPeers(e.detail));
|
Events.on('peers', e => this._onPeers(e.detail));
|
||||||
Events.on('file-progress', e => this._onFileProgress(e.detail));
|
Events.on('file-progress', e => this._onFileProgress(e.detail));
|
||||||
Events.on('paste', e => this._onPaste(e));
|
Events.on('paste', e => this._onPaste(e));
|
||||||
Events.on('ws-disconnected', _ => this._clearPeers());
|
Events.on('ws-disconnected', _ => this._clearPeers('all', false));
|
||||||
Events.on('secret-room-deleted', _ => this._clearPeers('secret'));
|
Events.on('secret-room-deleted', _ => this._clearPeers('secret'));
|
||||||
this.peers = {};
|
this.peers = {};
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ class PeersUI {
|
||||||
$peer.ui.setProgress(progress.progress);
|
$peer.ui.setProgress(progress.progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
_clearPeers(roomType = 'all') {
|
_clearPeers(roomType = 'all', restartAnimation = true) {
|
||||||
for (const peerId in this.peers) {
|
for (const peerId in this.peers) {
|
||||||
if (roomType === 'all' || this.peers[peerId].roomType === roomType) {
|
if (roomType === 'all' || this.peers[peerId].roomType === roomType) {
|
||||||
const peerNode = $(peerId);
|
const peerNode = $(peerId);
|
||||||
|
@ -107,7 +107,7 @@ class PeersUI {
|
||||||
delete this.peers[peerId];
|
delete this.peers[peerId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($$('x-peers').innerHTML === '') {
|
if (restartAnimation && $$('x-peers').innerHTML === '') {
|
||||||
setTimeout(_ => window.animateBackground(true), 1750); // Start animation again
|
setTimeout(_ => window.animateBackground(true), 1750); // Start animation again
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1254,19 +1254,24 @@ Events.on('load', () => {
|
||||||
let loading = true;
|
let loading = true;
|
||||||
|
|
||||||
function animate() {
|
function animate() {
|
||||||
if (loading || step % dw < dw - 5) {
|
if (loading || !finished()) {
|
||||||
requestAnimationFrame(function() {
|
requestAnimationFrame(function() {
|
||||||
drawCircles();
|
drawCircles();
|
||||||
animate();
|
animate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function finished() {
|
||||||
|
return step % dw >= dw - 5;
|
||||||
|
}
|
||||||
|
|
||||||
window.animateBackground = function(l) {
|
window.animateBackground = function(l) {
|
||||||
if (!l) {
|
if (!l) {
|
||||||
loading = false;
|
loading = false;
|
||||||
} else if (!loading) {
|
} else if (!loading) {
|
||||||
loading = true;
|
loading = true;
|
||||||
animate();
|
if (finished()) animate();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
init();
|
init();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue