Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nto nt-dependency-rework
  • Loading branch information
Gold872 committed Jun 25, 2024
2 parents c28656d + 86b4f4c commit ecef2d9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion elasticlib/Elastic.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public final class Elastic {
private static final StringTopic topic = NetworkTableInstance.getDefault()
.getStringTopic("elastic/robotnotifications");
.getStringTopic("/Elastic/robotnotifications");
private static final StringPublisher publisher = topic.publish(PubSubOption.sendAll(true));
private static final ObjectMapper objectMapper = new ObjectMapper();

Expand Down
3 changes: 2 additions & 1 deletion lib/pages/dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,11 @@ class _DashboardPageState extends State<DashboardPage> with WindowListener {
fontWeight: FontWeight.bold,
),
),
toastDuration: const Duration(seconds: 3),
icon: icon,
description: Text(description),
stackedOptions: StackedOptions(
key: 'robotnotification',
key: 'robot_notification',
type: StackedType.above,
itemOffset: const Offset(0, 5),
),
Expand Down
27 changes: 20 additions & 7 deletions lib/services/robot_notifications_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,43 @@ class RobotNotificationsListener {

void listen() {
var notifications =
ntConnection.subscribeAll("elastic/robotnotifications", 0.2);
ntConnection.subscribeAll('/Elastic/robotnotifications', 0.2);
notifications.listen((alertData, alertTimestamp) {
_onAlert(alertData!, alertTimestamp);
if (alertData == null) {
return;
}
_onAlert(alertData, alertTimestamp);
});

ntConnection.addDisconnectedListener(() => _alertFirstRun = true);
}

void _onAlert(Object alertData, int timestamp) {
//prevent showing a notification when we connect to NT
// prevent showing a notification when we connect to NT
if (_alertFirstRun) {
_alertFirstRun = false;
return;
}

Map<String, dynamic> data = jsonDecode(alertData.toString());
Map<String, dynamic> data;
try {
data = jsonDecode(alertData.toString());
} catch (e) {
return;
}

if (!data.containsKey('level')) {}

Icon icon;

if (data["level"] == "INFO") {
if (data['level'] == 'INFO') {
icon = const Icon(Icons.info);
} else if (data["level"] == "WARNING") {
} else if (data['level'] == 'WARNING') {
icon = const Icon(
Icons.warning_amber,
color: Colors.orange,
);
} else if (data["level"] == "ERROR") {
} else if (data['level'] == 'ERROR') {
icon = const Icon(
Icons.error,
color: Colors.red,
Expand Down

0 comments on commit ecef2d9

Please sign in to comment.