diff options
| author | xengineering <me@xengineering.eu> | 2026-04-06 17:03:46 +0200 |
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2026-04-06 17:03:46 +0200 |
| commit | 877a39e186699164e68ea969012a4f1ec6840ef8 (patch) | |
| tree | 92932f23c5b1d2798a9e63467b0ad4de70caa39f /lib/data.dart | |
| parent | 1809a88c679fcd17f29c13ddd47732bb65db96b2 (diff) | |
| parent | fcfb2a17733a38b690f4e034c78bc414be5527ef (diff) | |
| download | sia-app-877a39e186699164e68ea969012a4f1ec6840ef8.tar sia-app-877a39e186699164e68ea969012a4f1ec6840ef8.tar.zst sia-app-877a39e186699164e68ea969012a4f1ec6840ef8.zip | |
Merge persisting server fully qualified domain name
This allows to save the server fully qualified domain name (FQDN). The
user does not have to insert this on every app start.
Saved is the value of the corresponding text field on the last press on
the connect button.
Diffstat (limited to 'lib/data.dart')
| -rw-r--r-- | lib/data.dart | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/data.dart b/lib/data.dart index 365f5bc..ca350e5 100644 --- a/lib/data.dart +++ b/lib/data.dart @@ -1,7 +1,12 @@ +import 'dart:io'; +import 'dart:async'; + import 'package:flutter/foundation.dart'; import 'package:mqtt_client/mqtt_client.dart'; import 'package:mqtt_client/mqtt_server_client.dart'; +import 'db.dart'; + const int brokerPort = 1883; const String topicPrefix = 'sia'; @@ -22,6 +27,8 @@ enum MachineEvent { } class AppState with ChangeNotifier { + final DB db = DB(); + static const Map<MachineState, Map<MachineEvent, MachineState>> machine = <MachineState, Map<MachineEvent, MachineState>> { MachineState.init: <MachineEvent, MachineState> { MachineEvent.connect: MachineState.disconnected, @@ -46,9 +53,25 @@ class AppState with ChangeNotifier { Map<String, bool> contacts = <String, bool>{}; late MqttServerClient _client; + late Directory supportDir; String fqdn = ''; - AppState(); + AppState() { + unawaited(loadPersistence()); + } + + Future<void> loadPersistence() async { + await db.connect(); + String? dbFqdn = await db.getServerFqdn(); + if (dbFqdn == null) return; + fqdn = dbFqdn; + notifyListeners(); + } + + void setFqdn(String value) { + fqdn = value; + unawaited(db.setServerFqdn(value)); + } void process(MachineEvent event) { MachineState lastState = state; @@ -103,7 +126,7 @@ class AppState with ChangeNotifier { _client.onAutoReconnected = _onAutoReconnected; try { - _client.connect(); + unawaited(_client.connect()); } catch (e) { _client.disconnect(); return; |
