From 7c50a9313191fa6a97b3e673f0aef5d05b181477 Mon Sep 17 00:00:00 2001 From: Gold872 Date: Sun, 10 Dec 2023 22:23:17 -0500 Subject: [PATCH] Prevent shuffleboard widgets from being added when NT is disconnected --- lib/services/shuffleboard_nt_listener.dart | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/services/shuffleboard_nt_listener.dart b/lib/services/shuffleboard_nt_listener.dart index 0261d86f..16c12b8a 100644 --- a/lib/services/shuffleboard_nt_listener.dart +++ b/lib/services/shuffleboard_nt_listener.dart @@ -44,6 +44,14 @@ class ShuffleboardNTListener { previousSelection = data; }); + // Also clear data when connected in case if threads auto populate json after disconnection + // Chances are low since the timing has to be just right but you never know + nt4Connection.addConnectedListener(() { + currentJsonData.clear(); + shuffleboardTreeRoot.clearRows(); + previousSelection = null; + }); + nt4Connection.addDisconnectedListener(() { currentJsonData.clear(); shuffleboardTreeRoot.clearRows(); @@ -368,7 +376,9 @@ class ShuffleboardNTListener { ? Settings.defaultPeriod : Settings.defaultGraphPeriod); - onWidgetAdded?.call(currentJsonData[jsonKey]!); + if (nt4Connection.isNT4Connected) { + onWidgetAdded?.call(currentJsonData[jsonKey]!); + } widget?.unSubscribe(); widget?.dispose(deleting: true); @@ -467,8 +477,9 @@ class ShuffleboardNTListener { widget?.unSubscribe(); widget?.dispose(deleting: true); } - - onWidgetAdded?.call(currentJsonData[jsonKey]!); + if (nt4Connection.isNT4Connected) { + onWidgetAdded?.call(currentJsonData[jsonKey]!); + } }); }