mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-06-26 04:12:57 +10:00
fix foreground service and add notification nav
wraps MaterialApp in WithForegroundService to keep alive when swiped away persists last connected device and clears on manual disconnect to allow reconnect after kill added lifecycle tracking to iOS and keep android notification alive with heartbeat add notification navigation change screen tests to be less brittle address PR commnets
This commit is contained in:
@@ -8,6 +8,7 @@ import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../services/notification_service.dart';
|
||||
import '../utils/contact_search.dart';
|
||||
import '../utils/platform_info.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
@@ -31,6 +32,20 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
DiscoverySortOption discoverySortOption = DiscoverySortOption.lastSeen;
|
||||
Timer? _searchDebounce;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_clearAdvertNotifications();
|
||||
}
|
||||
|
||||
void _clearAdvertNotifications() {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final ids = connector.allContacts.map((c) => c.publicKeyHex).toList();
|
||||
final ns = NotificationService();
|
||||
ns.clearAllAdvertNotifications();
|
||||
ns.clearAdvertNotifications(ids);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:provider/provider.dart';
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../services/linux_ble_error_classifier.dart';
|
||||
import '../services/notification_service.dart';
|
||||
import '../utils/app_logger.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/device_tile.dart';
|
||||
@@ -43,6 +44,10 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||
isCurrentRoute &&
|
||||
!_changedNavigation) {
|
||||
_changedNavigation = true;
|
||||
// Prompt for notification permission on first
|
||||
// connect so notifications work out of the box
|
||||
// on Android 13+.
|
||||
NotificationService().requestPermissions();
|
||||
if (mounted) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (context) => const ContactsScreen()),
|
||||
@@ -53,6 +58,12 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||
|
||||
_connector.addListener(_connectionListener);
|
||||
|
||||
// If the app was killed (swipe-away) and relaunched, try to reconnect
|
||||
// to the last known device so the user doesn't have to scan again.
|
||||
if (_connector.state == MeshCoreConnectionState.disconnected) {
|
||||
_connector.tryAutoReconnect();
|
||||
}
|
||||
|
||||
_bluetoothStateSubscription = FlutterBluePlus.adapterState.listen(
|
||||
(state) {
|
||||
if (mounted) {
|
||||
|
||||
Reference in New Issue
Block a user