From c68a7ad987a4b99c72213052711e9c197d0c3f40 Mon Sep 17 00:00:00 2001 From: RobinLinus Date: Tue, 12 Mar 2019 23:37:50 +0100 Subject: [PATCH] Show a basic notification when user is offline --- client/scripts/ui.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/client/scripts/ui.js b/client/scripts/ui.js index 64f2a86..f54be6a 100644 --- a/client/scripts/ui.js +++ b/client/scripts/ui.js @@ -414,6 +414,25 @@ class Notifications { } } + +class NetworkStatusUI{ + + constructor() { + window.addEventListener('offline', e => this._showOfflineMessage(), false); + window.addEventListener('online', e => this._showOnlineMessage(), false); + if(!navigator.onLine) this._showOfflineMessage(); + } + + _showOfflineMessage(){ + Events.fire('notify-user','You are offline'); + } + + _showOnlineMessage(){ + Events.fire('notify-user','You are back online'); + } +} + + class Snapdrop { constructor() { const server = new ServerConnection(); @@ -425,6 +444,7 @@ class Snapdrop { const receiveTextDialog = new ReceiveTextDialog(); const toast = new Toast(); const notifications = new Notifications(); + const networkStatusUI = new NetworkStatusUI(); }) } }