mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-04-20 22:13:48 +00:00
Added response code for exporting contacts and implement frame listener in contacts_screen.dart
This commit is contained in:
parent
c37abb63e3
commit
641307a316
2 changed files with 22 additions and 0 deletions
|
|
@ -159,6 +159,7 @@ const int respCodeContactMsgRecv = 7;
|
|||
const int respCodeChannelMsgRecv = 8;
|
||||
const int respCodeCurrTime = 9;
|
||||
const int respCodeNoMoreMessages = 10;
|
||||
const int respCodeExportContact = 11;
|
||||
const int respCodeBattAndStorage = 12;
|
||||
const int respCodeDeviceInfo = 13;
|
||||
const int respCodeContactMsgRecvV3 = 16;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
|
|
@ -53,16 +54,20 @@ class _ContactsScreenState extends State<ContactsScreen>
|
|||
List<ContactGroup> _groups = [];
|
||||
Timer? _searchDebounce;
|
||||
|
||||
StreamSubscription<Uint8List>? _frameSubscription;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadGroups();
|
||||
_setupFrameListener();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchDebounce?.cancel();
|
||||
_searchController.dispose();
|
||||
_frameSubscription?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
|
@ -78,6 +83,22 @@ class _ContactsScreenState extends State<ContactsScreen>
|
|||
await _groupStore.saveGroups(_groups);
|
||||
}
|
||||
|
||||
void _setupFrameListener() {
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
// Listen for incoming text messages from the repeater
|
||||
_frameSubscription = connector.receivedFrames.listen((frame) {
|
||||
if (frame.isEmpty) return;
|
||||
final frameBuffer = BufferReader(frame);
|
||||
final code = frameBuffer.readUInt8();
|
||||
|
||||
if (code == respCodeExportContact) {
|
||||
final advertPacket = frameBuffer.readRemainingBytes();
|
||||
final hexString = pubKeyToHex(advertPacket);
|
||||
Clipboard.setData(ClipboardData(text: "meshcore://$hexString"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _contactExport(Uint8List pubKey) async {
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final exportContactFrame = buildExportContactFrame(pubKey);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue