Fix strange behavior with loading screens showing when they should not etc

pull/2/head
Ondřej Hruška 7 years ago
parent 18ece41390
commit f5dd70a6f3
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 11
      js/term/connection.js
  2. 36
      js/term/index.js
  3. 9
      js/term/screen.js
  4. 2
      js/term/screen_parser.js

@ -19,12 +19,18 @@ module.exports = class TermConnection extends EventEmitter {
this.pageShown = false this.pageShown = false
this.disconnectTimeout = null
document.addEventListener('visibilitychange', () => { document.addEventListener('visibilitychange', () => {
if (document.hidden === true) { if (document.hidden === true) {
console.info('Window lost focus, freeing socket') console.info('Window lost focus, freeing socket')
// Delayed, avoid disconnecting if the background time is short
this.disconnectTimeout = setTimeout(() => {
this.closeSocket() this.closeSocket()
clearTimeout(this.heartbeatTimeout) clearTimeout(this.heartbeatTimeout)
}, 1000)
} else { } else {
clearTimeout(this.disconnectTimeout)
console.info('Window got focus, re-connecting') console.info('Window got focus, re-connecting')
this.init() this.init()
} }
@ -80,7 +86,6 @@ module.exports = class TermConnection extends EventEmitter {
break break
default: default:
this.emit('load')
this.screen.load(evt.data) this.screen.load(evt.data)
if (!this.pageShown) { if (!this.pageShown) {
window.showPage() window.showPage()
@ -118,7 +123,7 @@ module.exports = class TermConnection extends EventEmitter {
console.error('Socket not ready') console.error('Socket not ready')
return false return false
} }
if (typeof message != 'string') { if (typeof message !== 'string') {
message = JSON.stringify(message) message = JSON.stringify(message)
} }
this.ws.send(message) this.ws.send(message)
@ -161,7 +166,7 @@ module.exports = class TermConnection extends EventEmitter {
heartbeat () { heartbeat () {
clearTimeout(this.heartbeatTimeout) clearTimeout(this.heartbeatTimeout)
this.heartbeatTimeout = setTimeout(() => this.onHeartbeatFail(), 2000) this.heartbeatTimeout = setTimeout(() => this.onHeartbeatFail(), 2500)
} }
onHeartbeatFail () { onHeartbeatFail () {

@ -14,33 +14,47 @@ module.exports = function (opts) {
const input = TermInput(conn, screen) const input = TermInput(conn, screen)
const termUpload = TermUpload(conn, input, screen) const termUpload = TermUpload(conn, input, screen)
screen.input = input screen.input = input
screen.conn = conn
input.termUpload = termUpload input.termUpload = termUpload
// we delay the display of "connecting" to avoid flash when changing tabs with the terminal open let showSplashTimeout = null
let showConnectingTimeout = -1 let showSplash = (obj, delay = 250) => {
clearTimeout(showSplashTimeout)
showSplashTimeout = setTimeout(() => {
screen.window.statusScreen = obj
}, delay)
}
conn.on('open', () => { conn.on('open', () => {
showConnectingTimeout = setTimeout(() => { // console.log('*open')
screen.window.statusScreen = { title: 'Connecting', loading: true } showSplash({ title: 'Connecting', loading: true })
}, 250)
}) })
conn.on('connect', () => { conn.on('connect', () => {
clearTimeout(showConnectingTimeout) // console.log('*connect')
screen.window.statusScreen = { title: 'Waiting for content', loading: true } showSplash({ title: 'Waiting for content', loading: true })
}) })
conn.on('load', () => { conn.on('load', () => {
// console.log('*load')
clearTimeout(showSplashTimeout)
if (screen.window.statusScreen) screen.window.statusScreen = null if (screen.window.statusScreen) screen.window.statusScreen = null
}) })
conn.on('disconnect', () => { conn.on('disconnect', () => {
clearTimeout(showConnectingTimeout) // console.log('*disconnect')
screen.window.statusScreen = { title: 'Disconnected' } showSplash({ title: 'Disconnected' })
screen.screen = [] screen.screen = []
screen.screenFG = [] screen.screenFG = []
screen.screenBG = [] screen.screenBG = []
screen.screenAttrs = [] screen.screenAttrs = []
}) })
conn.on('silence', () => { screen.window.statusScreen = { title: 'Waiting for server', loading: true } }) conn.on('silence', () => {
// console.log('*silence')
showSplash({ title: 'Waiting for server', loading: true }, 0)
})
// conn.on('ping-fail', () => { screen.window.statusScreen = { title: 'Disconnected' } }) // conn.on('ping-fail', () => { screen.window.statusScreen = { title: 'Disconnected' } })
conn.on('ping-success', () => { screen.window.statusScreen = { title: 'Re-connecting', loading: true } }) conn.on('ping-success', () => {
// console.log('*ping-success')
showSplash({ title: 'Re-connecting', loading: true }, 0)
})
conn.init() conn.init()
input.init(opts) input.init(opts)

@ -30,6 +30,15 @@ module.exports = class TermScreen extends EventEmitter {
return () => console.warn('TermScreen#input not set!') return () => console.warn('TermScreen#input not set!')
} }
}) })
// dummy. Handle for Conn
this.conn = new Proxy({}, {
get () {
return () => console.warn('TermScreen#conn not set!')
},
set (a, b) {
return () => console.warn('TermScreen#conn not set!')
}
})
this.cursor = { this.cursor = {
x: 0, x: 0,

@ -199,7 +199,7 @@ module.exports = class ScreenParser {
if (this.screen.window.debug) console.log(`Blinky cells: ${this.screen.blinkingCellCount}`) if (this.screen.window.debug) console.log(`Blinky cells: ${this.screen.blinkingCellCount}`)
this.screen.renderer.scheduleDraw('load', 16) this.screen.renderer.scheduleDraw('load', 16)
this.screen.emit('load') this.screen.conn.emit('load')
} }
/** /**

Loading…
Cancel
Save