From 8592499d220f76baf5c63e9f351378c5166945a1 Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Sat, 17 Feb 2024 14:17:43 +0100 Subject: [PATCH] Replace status: null with status: idle; Set status to processing immediately after receiving is done --- public/scripts/network.js | 5 +++-- public/scripts/ui.js | 23 ++++++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/public/scripts/network.js b/public/scripts/network.js index 6eada56..9afba2f 100644 --- a/public/scripts/network.js +++ b/public/scripts/network.js @@ -756,7 +756,7 @@ class Peer { if (message.reason === 'ram-exceed-ios') { Events.fire('notify-user', Localization.getTranslation('notifications.ram-exceed-ios')); } - Events.fire('set-progress', {peerId: this._peerId, progress: 0, status: null}); + Events.fire('set-progress', {peerId: this._peerId, progress: 0, status: 'idle'}); this._reset(); return; } @@ -844,7 +844,7 @@ class Peer { if (!message.success) { Logger.warn('File could not be sent'); - Events.fire('set-progress', {peerId: this._peerId, progress: 0, status: null}); + Events.fire('set-progress', {peerId: this._peerId, progress: 0, status: 'idle'}); this._reset(); return; } @@ -1024,6 +1024,7 @@ class Peer { // We are done receiving Events.fire('set-progress', {peerId: this._peerId, progress: 1, status: 'receive'}); + Events.fire('set-progress', {peerId: this._peerId, progress: 0, status: 'process'}); this._allFilesReceiveComplete(); } diff --git a/public/scripts/ui.js b/public/scripts/ui.js index d31dda8..0cc971e 100644 --- a/public/scripts/ui.js +++ b/public/scripts/ui.js @@ -423,8 +423,8 @@ class PeerUI { this._connected = false; this._currentProgress = 0; - this._currentStatus = null - this._oldStatus = null; + this._currentStatus = 'idle'; + this._oldStatus = 'idle'; this._progressQueue = []; @@ -461,8 +461,6 @@ class PeerUI { this.updateTypesClassList(); - this.setStatus("connect"); - this._evaluateShareMode(); this._bindListeners(); } @@ -602,7 +600,7 @@ class PeerUI { if (connected) { this._connected = true; - // on reconnect + // on reconnect: reset status to saved status this.setStatus(this._oldStatus); this._oldStatus = null; @@ -611,11 +609,11 @@ class PeerUI { else { this._connected = false; + // when connecting: / connection is lost: save old status if (!this._oldStatus && this._currentStatus !== "connect") { - // save old status when reconnecting this._oldStatus = this._currentStatus; + this.setStatus("connect"); } - this.setStatus("connect"); this._connectionHash = ""; } @@ -755,12 +753,12 @@ class PeerUI { return; } - if (progress === 0) { + if (progress < 0.5) { this.$progress.classList.remove('animate'); this.$progress.classList.remove('over50'); this.$progress.classList.add('animate'); } - else if (this._currentProgress === 0.5) { + else if (progress > 0.5 && this._currentProgress === 0.5) { this.$progress.classList.remove('animate'); this.$progress.classList.add('over50'); this.$progress.classList.add('animate'); @@ -773,14 +771,13 @@ class PeerUI { this.$progress.classList.remove('animate'); } - this.$progress.style.setProperty('--progress', `rotate(${360 * progress}deg)`); - if (progress === 1) { // reset progress this._progressQueue.unshift({progress: 0, status: status}); } this._currentProgress = progress; + this.$progress.style.setProperty('--progress', `rotate(${360 * progress}deg)`); this.setNextProgress(); } @@ -792,7 +789,7 @@ class PeerUI { clearTimeout(this.statusTimeout); - if (!status) { + if (status === 'idle') { this.$el.removeAttribute('status'); this.$el.querySelector('.status').innerText = ''; return; @@ -820,7 +817,7 @@ class PeerUI { if (status.endsWith("-complete") || status === "error") { this.statusTimeout = setTimeout(() => { - this.setProgress(0, null); + this.setStatus("idle"); }, 10000); } }