Skip to content

Commit

Permalink
fix: reconnect when emit error
Browse files Browse the repository at this point in the history
  • Loading branch information
VidocqH committed Mar 6, 2023
1 parent a73f424 commit 8462f74
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,16 @@ function subscribeAllSymbols(trayTickerSymbols) {
}
tray.setTitle(generateTrayTitleForTickers(symbolsMap.values()))
}
socket.onerror = (err) => {
console.error(err)
socket.close()
}
}

function subscribeAndUpdateTray() {
async function subscribeAndUpdateTray() {
if (socket) {
await socket.close()
}
if (config.trayTickerSymbols.length <= 1) {
subscribeSingleSymbol(config.trayTickerSymbols[0])
} else {
Expand Down Expand Up @@ -191,7 +198,6 @@ const createWindow = () => {

// Renderer funcs exposure
ipcMain.on('update-ticker', (event, tickers) => {
socket.close()
config.trayTickerSymbols = tickers
subscribeAndUpdateTray()
})
Expand All @@ -209,10 +215,10 @@ const createWindow = () => {
})

setInterval(() => {
if (socket.readyState === WebSocket.CLOSED) {
if (socket === undefined || (socket && socket.readyState === WebSocket.CLOSED)) {
subscribeAndUpdateTray()
}
}, 5000)
}, 10000)
}

const toggleWindow = () => {
Expand Down

0 comments on commit 8462f74

Please sign in to comment.