From bb0493d0717148d0bde0299599ace6ad2e6c2175 Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Fri, 3 Mar 2023 17:03:10 +0100 Subject: [PATCH] Make user notifications and document titles more concise. --- public/scripts/network.js | 5 ++++- public/scripts/ui.js | 17 ++++++++--------- public_included_ws_fallback/scripts/network.js | 5 ++++- public_included_ws_fallback/scripts/ui.js | 17 ++++++++--------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/public/scripts/network.js b/public/scripts/network.js index 8e27f21..41916a8 100644 --- a/public/scripts/network.js +++ b/public/scripts/network.js @@ -36,6 +36,7 @@ class ServerConnection { _onOpen() { console.log('WS: server connected'); Events.fire('ws-connected'); + if (this._isReconnect) Events.fire('notify-user', 'Connected.'); } _sendRoomSecrets(roomSecrets) { @@ -145,15 +146,17 @@ class ServerConnection { this._socket.close(); this._socket = null; Events.fire('ws-disconnected'); + this._isReconnect = true; } } _onDisconnect() { console.log('WS: server disconnected'); - Events.fire('notify-user', 'No server connection. Retry in 5s...'); + Events.fire('notify-user', 'Connecting..'); clearTimeout(this._reconnectTimer); this._reconnectTimer = setTimeout(_ => this._connect(), 5000); Events.fire('ws-disconnected'); + this._isReconnect = true; } _onVisibilityChange() { diff --git a/public/scripts/ui.js b/public/scripts/ui.js index 1eff336..cc0a476 100644 --- a/public/scripts/ui.js +++ b/public/scripts/ui.js @@ -662,7 +662,7 @@ class ReceiveFileDialog extends ReceiveDialog { this.createPreviewElement(files[0]).finally(_ => { document.title = files.length === 1 ? 'File received - PairDrop' - : `(${files.length}) Files received - PairDrop`; + : `${files.length} Files received - PairDrop`; document.changeFavicon("images/favicon-96x96-notification.png"); Events.fire('set-progress', {peerId: peerId, progress: 1, status: 'process'}) this.show(); @@ -1143,7 +1143,7 @@ class ReceiveTextDialog extends Dialog { _setDocumentTitleMessages() { document.title = !this._receiveTextQueue.length ? 'Message Received - PairDrop' - : `(${this._receiveTextQueue.length + 1}) Messages Received - PairDrop`; + : `${this._receiveTextQueue.length + 1} Messages Received - PairDrop`; } async _onCopy() { @@ -1424,7 +1424,7 @@ class NetworkStatusUI { constructor() { Events.on('offline', _ => this._showOfflineMessage()); Events.on('online', _ => this._showOnlineMessage()); - Events.on('ws-connected', _ => this._showOnlineMessage()); + Events.on('ws-connected', _ => this._onWsConnected()); Events.on('ws-disconnected', _ => this._onWsDisconnected()); if (!navigator.onLine) this._showOfflineMessage(); } @@ -1435,17 +1435,16 @@ class NetworkStatusUI { } _showOnlineMessage() { - window.animateBackground(true); - if (!this.firstConnect) { - this.firstConnect = true; - return; - } Events.fire('notify-user', 'You are back online'); + window.animateBackground(true); + } + + _onWsConnected() { + window.animateBackground(true); } _onWsDisconnected() { window.animateBackground(false); - if (!this.firstConnect) this.firstConnect = true; } } diff --git a/public_included_ws_fallback/scripts/network.js b/public_included_ws_fallback/scripts/network.js index bcd7df6..2e0f1ef 100644 --- a/public_included_ws_fallback/scripts/network.js +++ b/public_included_ws_fallback/scripts/network.js @@ -34,6 +34,7 @@ class ServerConnection { _onOpen() { console.log('WS: server connected'); Events.fire('ws-connected'); + if (this._isReconnect) Events.fire('notify-user', 'Connected.'); } _sendRoomSecrets(roomSecrets) { @@ -155,15 +156,17 @@ class ServerConnection { this._socket.close(); this._socket = null; Events.fire('ws-disconnected'); + this._isReconnect = true; } } _onDisconnect() { console.log('WS: server disconnected'); - Events.fire('notify-user', 'No server connection. Retry in 5s...'); + Events.fire('notify-user', 'Connecting..'); clearTimeout(this._reconnectTimer); this._reconnectTimer = setTimeout(_ => this._connect(), 5000); Events.fire('ws-disconnected'); + this._isReconnect = true; } _onVisibilityChange() { diff --git a/public_included_ws_fallback/scripts/ui.js b/public_included_ws_fallback/scripts/ui.js index 3270f2d..82b0eab 100644 --- a/public_included_ws_fallback/scripts/ui.js +++ b/public_included_ws_fallback/scripts/ui.js @@ -663,7 +663,7 @@ class ReceiveFileDialog extends ReceiveDialog { this.createPreviewElement(files[0]).finally(_ => { document.title = files.length === 1 ? 'File received - PairDrop' - : `(${files.length}) Files received - PairDrop`; + : `${files.length} Files received - PairDrop`; document.changeFavicon("images/favicon-96x96-notification.png"); Events.fire('set-progress', {peerId: peerId, progress: 1, status: 'process'}) this.show(); @@ -1144,7 +1144,7 @@ class ReceiveTextDialog extends Dialog { _setDocumentTitleMessages() { document.title = !this._receiveTextQueue.length ? 'Message Received - PairDrop' - : `(${this._receiveTextQueue.length + 1}) Messages Received - PairDrop`; + : `${this._receiveTextQueue.length + 1} Messages Received - PairDrop`; } async _onCopy() { @@ -1425,7 +1425,7 @@ class NetworkStatusUI { constructor() { Events.on('offline', _ => this._showOfflineMessage()); Events.on('online', _ => this._showOnlineMessage()); - Events.on('ws-connected', _ => this._showOnlineMessage()); + Events.on('ws-connected', _ => this._onWsConnected()); Events.on('ws-disconnected', _ => this._onWsDisconnected()); if (!navigator.onLine) this._showOfflineMessage(); } @@ -1436,17 +1436,16 @@ class NetworkStatusUI { } _showOnlineMessage() { - window.animateBackground(true); - if (!this.firstConnect) { - this.firstConnect = true; - return; - } Events.fire('notify-user', 'You are back online'); + window.animateBackground(true); + } + + _onWsConnected() { + window.animateBackground(true); } _onWsDisconnected() { window.animateBackground(false); - if (!this.firstConnect) this.firstConnect = true; } }