From 0d95eddd6222856548e154ab5cb9d5cb4d31ed57 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Sun, 1 Sep 2024 19:06:52 -0400 Subject: [PATCH] Fix command widget lockup (#90) If the command button is pressed too frequently, it can get stuck in the "running" state --- lib/widgets/nt_widgets/multi-topic/command_widget.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/widgets/nt_widgets/multi-topic/command_widget.dart b/lib/widgets/nt_widgets/multi-topic/command_widget.dart index 2937ff46..9779af07 100644 --- a/lib/widgets/nt_widgets/multi-topic/command_widget.dart +++ b/lib/widgets/nt_widgets/multi-topic/command_widget.dart @@ -123,7 +123,7 @@ class CommandWidget extends NTWidget { onTapUp: (_) { bool publishTopic = model.runningTopic == null; - model.runningTopic = + model.runningTopic ??= model.ntConnection.getTopicFromName(model.runningTopicName); if (model.runningTopic == null) { @@ -134,6 +134,12 @@ class CommandWidget extends NTWidget { model.ntConnection.publishTopic(model.runningTopic!); } + // Prevents widget from locking up if double pressed fast enough + bool running = model.ntConnection + .getLastAnnouncedValue(model.runningTopicName) + ?.tryCast() ?? + false; + model.ntConnection .updateDataFromTopic(model.runningTopic!, !running); },