diff options
| author | xengineering <me@xengineering.eu> | 2026-03-08 16:49:16 +0100 |
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2026-03-08 16:49:42 +0100 |
| commit | ef8877ccffe0ebcc8f9f1c0bb6db372fa0886c2a (patch) | |
| tree | 9586da03ef50b2ac3c9e0ddf732a83cefd13d549 /lib/data.dart | |
| parent | 796a2b21e8b5989187bfc7d4ddb7ba648038cbca (diff) | |
| download | sia-app-ef8877ccffe0ebcc8f9f1c0bb6db372fa0886c2a.tar sia-app-ef8877ccffe0ebcc8f9f1c0bb6db372fa0886c2a.tar.zst sia-app-ef8877ccffe0ebcc8f9f1c0bb6db372fa0886c2a.zip | |
Add manual disconnect
This allows going back to the connection page and to choose a different
server. Furthermore it might be useful to force a new connection attempt
while auto-reconnect might be in a delay state.
Diffstat (limited to 'lib/data.dart')
| -rw-r--r-- | lib/data.dart | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/data.dart b/lib/data.dart index 89d8760..415e61e 100644 --- a/lib/data.dart +++ b/lib/data.dart @@ -21,11 +21,14 @@ class AppState with ChangeNotifier { MachineState.init: <MachineEvent, MachineState> { MachineEvent.connect: MachineState.disconnected, }, + MachineState.disconnected: <MachineEvent, MachineState> { + MachineEvent.disconnect: MachineState.init, + }, }; MachineState state = MachineState.init; Map<String, bool> contacts = <String, bool>{}; - late final MqttServerClient _client; + late MqttServerClient _client; bool _brokerConnected = false; bool get brokerConnected => _brokerConnected; bool _serverConnected = false; @@ -54,6 +57,10 @@ class AppState with ChangeNotifier { _initMqtt(); } + if (nextState == MachineState.init) { + _deinitMqtt(); + } + state = nextState; notifyListeners(); } @@ -91,6 +98,10 @@ class AppState with ChangeNotifier { _client.updates?.listen(_onMessage); } + void _deinitMqtt() { + _client.disconnect(); + } + void _onConnected() { _client.subscribe('$topicPrefix/contact/+/state', MqttQos.exactlyOnce); _client.subscribe('$topicPrefix/server/health', MqttQos.exactlyOnce); |
