From 2d8c896ad40d440be372ccbae94211f2b0ffdeaa Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Wed, 31 Aug 2022 11:46:51 -0600 Subject: [PATCH] Handle node status views when client disconnects --- core/wfc.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/core/wfc.js b/core/wfc.js index 682db2de..5933a356 100644 --- a/core/wfc.js +++ b/core/wfc.js @@ -1,6 +1,7 @@ // ENiGMA½ const { MenuModule } = require('./menu_module'); const stringFormat = require('./string_format'); +const Events = require('./events'); const { getActiveConnectionList, @@ -77,6 +78,7 @@ exports.getModule = class WaitingForCallerModule extends MenuModule { } this.selectedNodeStatusIndex = -1; // no selection + this.refreshing = false; this.menuMethods = { toggleAvailable: (formData, extraArgs, cb) => { @@ -224,6 +226,10 @@ exports.getModule = class WaitingForCallerModule extends MenuModule { enter() { this.client.stopIdleMonitor(); this._applyOpVisibility(); + Events.on( + Events.getSystemEvents().ClientDisconnected, + this._clientDisconnected.bind(this) + ); super.enter(); } @@ -232,6 +238,11 @@ exports.getModule = class WaitingForCallerModule extends MenuModule { return stream.name === 'wfc-ringbuffer'; }); + Events.removeListener( + Events.getSystemEvents().ClientDisconnected, + this._clientDisconnected + ); + this._restoreOpVisibility(); this._stopRefreshing(); @@ -375,7 +386,38 @@ exports.getModule = class WaitingForCallerModule extends MenuModule { } } + _clientDisconnected() { + const nodeStatusSelectionView = this.getView( + 'main', + MciViewIds.main.selectedNodeStatusInfo + ); + if (nodeStatusSelectionView) { + nodeStatusSelectionView.setText(''); + } + + this.selectedNodeStatusIndex = 0; // will select during refresh + this._refreshAll(); + + // have to update the selection view here + if (nodeStatusSelectionView) { + const nodeStatusView = this.getView('main', MciViewIds.main.nodeStatus); + if (nodeStatusView) { + const item = nodeStatusView.getItems()[this.selectedNodeStatusIndex]; + this._updateNodeStatusSelection(nodeStatusSelectionView, item); + } + } + } + _refreshAll(cb) { + if (this.refreshing) { + if (cb) { + return cb(null); + } + return; + } + + this.refreshing = true; + async.series( [ callback => { @@ -397,6 +439,7 @@ exports.getModule = class WaitingForCallerModule extends MenuModule { }, ], err => { + this.refreshing = false; if (cb) { return cb(err); }