ipc: add notification when server is unreachable (add unique notification to avoid spamming)

This commit is contained in:
jean-emmanuel 2019-01-05 18:08:07 +01:00
parent 679acfab79
commit e1aaaf8ddb
5 changed files with 33 additions and 2 deletions

View file

@ -1,5 +1,12 @@
var EventEmitter = require('../events/event-emitter'),
uuid = require('nanoid/generate')('0123456789abcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXYZ', 10)
uuid = require('nanoid/generate')('0123456789abcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXYZ', 10),
notifications,
locales
setTimeout(()=>{
notifications = require('../ui/notifications')
locales = require('../locales')
})
var reconnectInterval = 5000,
hearbeatInterval = 25000,
@ -120,6 +127,12 @@ class Ipc extends EventEmitter {
this.socket.send(packet)
} else {
this.queue.push(packet)
notifications.add({
icon: 'wifi',
class: 'error',
message: locales('server_unreachable'),
id: 'server_unreachable'
})
}
}

View file

@ -31,6 +31,9 @@ module.exports = {
fs_unnavailable: 'Fullscreen not available',
fs_addtohome: 'You must add this page to your home screen to launch it in fullscreen',
// server
server_unreachable: 'The server is currently unreachable',
// session
session_browse: 'Browse...',
session_new: 'New session',

View file

@ -31,6 +31,9 @@ module.exports = {
fs_unnavailable: 'Plein écran indisponible',
fs_addtohome: 'Vous devez ajouter cette page à votre écran d\'accueil pour pouvoir l\'ouvrir en plein écran.',
// server
server_unreachable: 'La connexion avec le serveur a été interrompue',
// session
session_browse: 'Parcourir...',
session_new: 'Nouvelle session',

View file

@ -31,6 +31,9 @@ module.exports = { // @https://github.com/suhr
fs_unnavailable: 'Полный экран не доступен',
fs_addtohome: 'Необходимо добавить эту страницу на главный экран чтобы запустить её в полноэкранном режиме',
// server
server_unreachable: 'The server is currently unreachable',
// session
session_browse: 'Обзор...',
session_new: 'Новая сессия',
@ -57,7 +60,7 @@ module.exports = { // @https://github.com/suhr
state_storesuccess: 'State saved',
state_recallsuccess: 'State recalled',
state_sendsuccess: 'State sent',
// traversing
traversing_on: 'Вкл',
traversing_smart: 'Умный',

View file

@ -15,6 +15,14 @@ class Notifications {
add(data) {
if (data.id) {
var match = this.toasts.filter(x => x.id === data.id)
if (match.length) {
match[0].date = Date.now()
return
}
}
var toast = html`
<div class="toast ${data.class || ''}">
<i class="fa fa-fw fa-${data.icon || (data.class === 'error' ? 'exclamation' : 'bell')}"></i>
@ -24,6 +32,7 @@ class Notifications {
</div>
`
toast.date = Date.now()
if (data.id) toast.id = data.id
this.container.appendChild(toast)
toast.style.height = toast.offsetHeight + 'px'
this.toasts.push(toast)