Skip to content

Commit

Permalink
Fix command widget lockup (#90)
Browse files Browse the repository at this point in the history
If the command button is pressed too frequently, it can get stuck in the
"running" state
  • Loading branch information
Gold872 authored Sep 1, 2024
1 parent ba22ca9 commit 0d95edd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/widgets/nt_widgets/multi-topic/command_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<bool>() ??
false;

model.ntConnection
.updateDataFromTopic(model.runningTopic!, !running);
},
Expand Down

0 comments on commit 0d95edd

Please sign in to comment.