mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-30 07:18:45 +10:00
Added response code for exporting contacts and implement frame listener in contacts_screen.dart
This commit is contained in:
@@ -159,6 +159,7 @@ const int respCodeContactMsgRecv = 7;
|
|||||||
const int respCodeChannelMsgRecv = 8;
|
const int respCodeChannelMsgRecv = 8;
|
||||||
const int respCodeCurrTime = 9;
|
const int respCodeCurrTime = 9;
|
||||||
const int respCodeNoMoreMessages = 10;
|
const int respCodeNoMoreMessages = 10;
|
||||||
|
const int respCodeExportContact = 11;
|
||||||
const int respCodeBattAndStorage = 12;
|
const int respCodeBattAndStorage = 12;
|
||||||
const int respCodeDeviceInfo = 13;
|
const int respCodeDeviceInfo = 13;
|
||||||
const int respCodeContactMsgRecvV3 = 16;
|
const int respCodeContactMsgRecvV3 = 16;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'dart:async';
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../connector/meshcore_connector.dart';
|
import '../connector/meshcore_connector.dart';
|
||||||
@@ -53,16 +54,20 @@ class _ContactsScreenState extends State<ContactsScreen>
|
|||||||
List<ContactGroup> _groups = [];
|
List<ContactGroup> _groups = [];
|
||||||
Timer? _searchDebounce;
|
Timer? _searchDebounce;
|
||||||
|
|
||||||
|
StreamSubscription<Uint8List>? _frameSubscription;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_loadGroups();
|
_loadGroups();
|
||||||
|
_setupFrameListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_searchDebounce?.cancel();
|
_searchDebounce?.cancel();
|
||||||
_searchController.dispose();
|
_searchController.dispose();
|
||||||
|
_frameSubscription?.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +83,22 @@ class _ContactsScreenState extends State<ContactsScreen>
|
|||||||
await _groupStore.saveGroups(_groups);
|
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 {
|
Future<void> _contactExport(Uint8List pubKey) async {
|
||||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||||
final exportContactFrame = buildExportContactFrame(pubKey);
|
final exportContactFrame = buildExportContactFrame(pubKey);
|
||||||
|
|||||||
Reference in New Issue
Block a user