Handle node status views when client disconnects

This commit is contained in:
Bryan Ashby 2022-08-31 11:46:51 -06:00
parent 8e17897954
commit 2d8c896ad4
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
1 changed files with 43 additions and 0 deletions

View File

@ -1,6 +1,7 @@
// ENiGMA½ // ENiGMA½
const { MenuModule } = require('./menu_module'); const { MenuModule } = require('./menu_module');
const stringFormat = require('./string_format'); const stringFormat = require('./string_format');
const Events = require('./events');
const { const {
getActiveConnectionList, getActiveConnectionList,
@ -77,6 +78,7 @@ exports.getModule = class WaitingForCallerModule extends MenuModule {
} }
this.selectedNodeStatusIndex = -1; // no selection this.selectedNodeStatusIndex = -1; // no selection
this.refreshing = false;
this.menuMethods = { this.menuMethods = {
toggleAvailable: (formData, extraArgs, cb) => { toggleAvailable: (formData, extraArgs, cb) => {
@ -224,6 +226,10 @@ exports.getModule = class WaitingForCallerModule extends MenuModule {
enter() { enter() {
this.client.stopIdleMonitor(); this.client.stopIdleMonitor();
this._applyOpVisibility(); this._applyOpVisibility();
Events.on(
Events.getSystemEvents().ClientDisconnected,
this._clientDisconnected.bind(this)
);
super.enter(); super.enter();
} }
@ -232,6 +238,11 @@ exports.getModule = class WaitingForCallerModule extends MenuModule {
return stream.name === 'wfc-ringbuffer'; return stream.name === 'wfc-ringbuffer';
}); });
Events.removeListener(
Events.getSystemEvents().ClientDisconnected,
this._clientDisconnected
);
this._restoreOpVisibility(); this._restoreOpVisibility();
this._stopRefreshing(); 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) { _refreshAll(cb) {
if (this.refreshing) {
if (cb) {
return cb(null);
}
return;
}
this.refreshing = true;
async.series( async.series(
[ [
callback => { callback => {
@ -397,6 +439,7 @@ exports.getModule = class WaitingForCallerModule extends MenuModule {
}, },
], ],
err => { err => {
this.refreshing = false;
if (cb) { if (cb) {
return cb(err); return cb(err);
} }