notifications: ooify toasts and better server connection notifications
This commit is contained in:
parent
0ab3d76dd7
commit
28f3c53018
5 changed files with 77 additions and 33 deletions
|
|
@ -66,6 +66,12 @@ class Ipc extends EventEmitter {
|
|||
}, hearbeatTimeout)
|
||||
}, hearbeatInterval)
|
||||
|
||||
if (notifications) notifications.add({
|
||||
icon: 'wifi',
|
||||
message: locales('server_connected'),
|
||||
id: 'ipc_state'
|
||||
})
|
||||
|
||||
this.trigger('connect')
|
||||
this.flush()
|
||||
|
||||
|
|
@ -88,7 +94,13 @@ class Ipc extends EventEmitter {
|
|||
this.hearbeat = clearInterval(this.hearbeat)
|
||||
this.hearbeatTimeout = clearTimeout(this.hearbeatTimeout)
|
||||
this.dieTimeout = clearTimeout(this.dieTimeout)
|
||||
|
||||
notifications.add({
|
||||
icon: 'wifi',
|
||||
class: 'error',
|
||||
message: locales('server_disconnected'),
|
||||
id: 'ipc_state',
|
||||
duration: Infinity
|
||||
})
|
||||
if (!this.reconnect) {
|
||||
this.reconnect = setInterval(()=>{
|
||||
this.open()
|
||||
|
|
@ -127,12 +139,6 @@ 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'
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ module.exports = {
|
|||
fs_addtohome: 'You must add this page to your home screen to launch it in fullscreen',
|
||||
|
||||
// server
|
||||
server_unreachable: 'The server is currently unreachable',
|
||||
server_disconnected: 'The connection to the server has been interrupted',
|
||||
server_connected: 'The connection to the server has been restored',
|
||||
|
||||
// session
|
||||
session_browse: 'Browse...',
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ module.exports = {
|
|||
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',
|
||||
server_disconnected: 'La connexion avec le serveur a été interrompue',
|
||||
server_connected: 'La connexion avec le serveur a été rétablie',
|
||||
|
||||
// session
|
||||
session_browse: 'Parcourir...',
|
||||
|
|
|
|||
|
|
@ -32,8 +32,9 @@ module.exports = { // @https://github.com/suhr
|
|||
fs_addtohome: 'Необходимо добавить эту страницу на главный экран чтобы запустить её в полноэкранном режиме',
|
||||
|
||||
// server
|
||||
server_unreachable: 'The server is currently unreachable',
|
||||
|
||||
server_disconnected: 'The connection to the server has been interrupted',
|
||||
server_connected: 'The connection to the server has been restored',
|
||||
|
||||
// session
|
||||
session_browse: 'Обзор...',
|
||||
session_new: 'Новая сессия',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,55 @@
|
|||
var html = require('nanohtml')
|
||||
var html = require('nanohtml'),
|
||||
morph = require('nanomorph')
|
||||
|
||||
var DURATION = 3500
|
||||
|
||||
var DEFAULT_DURATION = 3500
|
||||
|
||||
class Toast {
|
||||
|
||||
constructor(data) {
|
||||
|
||||
this.id = data.id || Date.now()
|
||||
this.update(data)
|
||||
|
||||
}
|
||||
|
||||
update(data) {
|
||||
|
||||
this.expires = Date.now() + (data.duration || DEFAULT_DURATION)
|
||||
|
||||
var html = html`
|
||||
<div class="toast ${data.class || ''}">
|
||||
<i class="fa fa-fw fa-${data.icon || (data.class === 'error' ? 'exclamation' : 'bell')}"></i>
|
||||
<div class="content">
|
||||
${data.message}
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
if (this.html) {
|
||||
morph(this.html, html)
|
||||
} else {
|
||||
this.html = html
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
appendTo(el) {
|
||||
|
||||
el.appendChild(this.html)
|
||||
this.html.style.height = this.html.offsetHeight + 'px'
|
||||
|
||||
}
|
||||
|
||||
removeFrom(el) {
|
||||
|
||||
this.html.classList.add('remove')
|
||||
setTimeout(()=>{
|
||||
el.removeChild(this.html)
|
||||
}, 200)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Notifications {
|
||||
|
||||
|
|
@ -18,23 +67,13 @@ class Notifications {
|
|||
if (data.id) {
|
||||
var match = this.toasts.filter(x => x.id === data.id)
|
||||
if (match.length) {
|
||||
match[0].date = Date.now()
|
||||
return
|
||||
return match[0].update(data)
|
||||
}
|
||||
}
|
||||
|
||||
var toast = html`
|
||||
<div class="toast ${data.class || ''}">
|
||||
<i class="fa fa-fw fa-${data.icon || (data.class === 'error' ? 'exclamation' : 'bell')}"></i>
|
||||
<div class="content">
|
||||
${data.message}
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
toast.date = Date.now()
|
||||
if (data.id) toast.id = data.id
|
||||
this.container.appendChild(toast)
|
||||
toast.style.height = toast.offsetHeight + 'px'
|
||||
var toast = new Toast(data)
|
||||
|
||||
toast.appendTo(this.container)
|
||||
this.toasts.push(toast)
|
||||
|
||||
this.startLoop()
|
||||
|
|
@ -43,12 +82,8 @@ class Notifications {
|
|||
|
||||
remove(toast) {
|
||||
|
||||
toast.removeFrom(this.container)
|
||||
this.toasts.splice(this.toasts.indexOf(toast), 1)
|
||||
toast.classList.add('remove')
|
||||
toast.classList.add('remove')
|
||||
setTimeout(()=>{
|
||||
this.container.removeChild(toast)
|
||||
}, 200)
|
||||
|
||||
if (this.toasts.length === 0) this.stopLoop()
|
||||
|
||||
|
|
@ -60,7 +95,7 @@ class Notifications {
|
|||
|
||||
this.loop = setInterval(()=>{
|
||||
for (var i = this.toasts.length - 1; i > -1; i--) {
|
||||
if (Date.now() - this.toasts[i].date > DURATION) {
|
||||
if (Date.now() > this.toasts[i].expires) {
|
||||
this.remove(this.toasts[i])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue