diff --git a/lib/Backend/wear_bridge.dart b/lib/Backend/wear_bridge.dart index 4eb249ba..fe066ec5 100644 --- a/lib/Backend/wear_bridge.dart +++ b/lib/Backend/wear_bridge.dart @@ -1,85 +1,57 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:typed_data'; import 'package:built_collection/built_collection.dart'; import 'package:collection/collection.dart'; -import 'package:cross_platform/cross_platform.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_wear_os_connectivity/flutter_wear_os_connectivity.dart'; import 'package:logging/logging.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; +import 'package:watch_connectivity/watch_connectivity.dart'; -import 'Bluetooth/bluetooth_manager.dart'; import 'Definitions/Action/base_action.dart'; -import 'Definitions/Device/device_definition.dart'; import 'action_registry.dart'; import 'favorite_actions.dart'; -import 'move_lists.dart'; part 'wear_bridge.g.dart'; final Logger _wearLogger = Logger('Wear'); -FlutterWearOsConnectivity _flutterWearOsConnectivity = FlutterWearOsConnectivity(); -StreamSubscription? _dataChangedStreamSubscription; -StreamSubscription? _messagereceivedStreamSubscription; -StreamSubscription? capabilityChangedStreamSubscription; +StreamSubscription>? _messageStreamSubscription; +StreamSubscription>? _contextStreamSubscription; +final _watch = WatchConnectivity(); @Riverpod(keepAlive: true) Future initWear(InitWearRef ref) async { await Future.delayed(const Duration(seconds: 5)); try { - if (!Platform.isAndroid || !await _flutterWearOsConnectivity.isSupported()) { - return; - } - _flutterWearOsConnectivity.configureWearableAPI(); - _flutterWearOsConnectivity - .getConnectedDevices() - .asStream() - .expand( - (element) => element, - ) - .listen((event) => _wearLogger.info("Connected Wear Device${event.name}, isNearby ${event.isNearby}")); - - _dataChangedStreamSubscription = _flutterWearOsConnectivity.dataChanged().expand((element) => element).listen( - (dataEvent) { - _wearLogger.info("dataChanged ${dataEvent.type}, ${dataEvent.dataItem.mapData}"); - if (!dataEvent.isDataValid || dataEvent.type != DataEventType.changed) { - return; - } - Map mapData = dataEvent.dataItem.mapData; - bool containsKey = mapData.containsKey("uuid"); - if (containsKey) { - String uuid = mapData["uuid"]; - BaseAction? action = ref.read(getActionFromUUIDProvider(uuid)); - if (action != null) { - Iterable knownDevices = ref - .read(knownDevicesProvider) - .values - .where((element) => action.deviceCategory.contains(element.baseDeviceDefinition.deviceType)) - .where((element) => element.deviceConnectionState.value == ConnectivityState.connected) - .where((element) => element.deviceState.value == DeviceState.standby); - for (BaseStatefulDevice device in knownDevices) { - runAction(action, device); - } - } - } - }, + // Get the state of device connectivity + _messageStreamSubscription = _watch.messageStream.listen( + (event) => _wearLogger.info("Watch Message: $event"), + ); + _contextStreamSubscription = _watch.contextStream.listen( + (event) => _wearLogger.info("Watch Context: $event"), ); - _messagereceivedStreamSubscription = _flutterWearOsConnectivity.messageReceived().listen( - (message) => _wearLogger.info("messageReceived $message"), - ); - capabilityChangedStreamSubscription = _flutterWearOsConnectivity.capabilityChanged(capabilityPathURI: Uri(scheme: "wear", host: "*", path: "/*")).listen( - (event) => _wearLogger.info( - "capabilityChanged $event", - ), - ); + updateWearActions(ref.read(favoriteActionsProvider), ref); } catch (e, s) { _wearLogger.severe("exception setting up Wear $e", e, s); } } +Future isReachable() { + return _watch.isReachable; +} + +Future isSupported() { + return _watch.isSupported; +} + +Future isPaired() { + return _watch.isPaired; +} + +Future> applicationContext() { + return _watch.applicationContext; +} + Future updateWearActions(BuiltList favoriteActions, Ref ref) async { try { Iterable allActions = favoriteActions @@ -94,15 +66,9 @@ Future updateWearActions(BuiltList favoriteActions, Ref re MapEntry("uuid", favoriteMap.keys.join("_")), ], ); - String msgJson = const JsonEncoder().convert(map); - List msgBytes = const Utf8Encoder().convert(msgJson); - List connectedDevices = await _flutterWearOsConnectivity.getConnectedDevices(); - for (WearOsDevice wearOsDevice in connectedDevices) { - await _flutterWearOsConnectivity.sendMessage(Uint8List.fromList(msgBytes), deviceId: wearOsDevice.id, path: "/actions"); + if (await _watch.isReachable) { + await _watch.sendMessage(map); } - - DataItem? dataItem = await _flutterWearOsConnectivity.syncData(path: "/actions", data: map, isUrgent: true); - _wearLogger.info("Message Sent successfully? ${dataItem != null}"); } catch (e, s) { _wearLogger.severe("Unable to send favorite actions to watch", e, s); } diff --git a/lib/Frontend/pages/developer/developer_menu.dart b/lib/Frontend/pages/developer/developer_menu.dart index 2a42decc..b88c4d9a 100644 --- a/lib/Frontend/pages/developer/developer_menu.dart +++ b/lib/Frontend/pages/developer/developer_menu.dart @@ -1,8 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; +import 'package:install_referrer/install_referrer.dart'; import '../../../Backend/logging_wrappers.dart'; +import '../../../Backend/wear_bridge.dart'; import '../../../constants.dart'; import '../../../main.dart'; import '../../go_router_config.dart'; @@ -117,6 +119,60 @@ class _DeveloperMenuState extends ConsumerState { }, ), ), + ListTile( + title: const Text("InstallReferrer"), + subtitle: FutureBuilder( + future: InstallReferrer.referrer, + builder: (context, snapshot) { + InstallationAppReferrer? value = snapshot.data; + String referral = value != null ? value.name : "unknown"; + return Text(referral); + }, + ), + ), + const ListTile( + title: Divider(), + ), + ListTile( + title: const Text("WatchIsReachable"), + subtitle: FutureBuilder( + future: isReachable(), + builder: (context, snapshot) { + bool value = snapshot.data ?? false; + return Text(value.toString()); + }, + ), + ), + ListTile( + title: const Text("WatchIsSupported"), + subtitle: FutureBuilder( + future: isSupported(), + builder: (context, snapshot) { + bool value = snapshot.data ?? false; + return Text(value.toString()); + }, + ), + ), + ListTile( + title: const Text("WatchIsPaired"), + subtitle: FutureBuilder( + future: isPaired(), + builder: (context, snapshot) { + bool value = snapshot.data ?? false; + return Text(value.toString()); + }, + ), + ), + ListTile( + title: const Text("WatchApplicationContext"), + subtitle: FutureBuilder( + future: applicationContext(), + builder: (context, snapshot) { + Map value = snapshot.data ?? {}; + return Text(value.toString()); + }, + ), + ), ], ), ); diff --git a/pubspec.lock b/pubspec.lock index a0f139bb..e2c0b4c0 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -587,10 +587,10 @@ packages: dependency: "direct main" description: name: flutter_foreground_task - sha256: "6e89319a66f6a022773e8c698527e9cd80a92d7508154b82fb89d33e0dd64068" + sha256: "4962ffefe4352435900eb25734925f1ad002abf48e13c1ca22c9c63391be4f94" url: "https://pub.dev" source: hosted - version: "8.6.0" + version: "8.7.0" flutter_gen_core: dependency: transitive description: @@ -716,14 +716,6 @@ packages: url: "https://pub.dev" source: hosted version: "9.1.0" - flutter_smart_watch_platform_interface: - dependency: transitive - description: - name: flutter_smart_watch_platform_interface - sha256: "66e49a77764294a5d9816be548ffab33acac54bc51292d8d01e9e07455571a2b" - url: "https://pub.dev" - source: hosted - version: "0.0.2" flutter_svg: dependency: transitive description: @@ -737,15 +729,6 @@ packages: description: flutter source: sdk version: "0.0.0" - flutter_wear_os_connectivity: - dependency: "direct main" - description: - path: "." - ref: HEAD - resolved-ref: "892502783a8428c7e001b53c36d8777c2b240054" - url: "https://github.com/Codel1417/flutter_wear_os_connectivity" - source: git - version: "1.0.0" flutter_web_plugins: dependency: transitive description: flutter @@ -1865,6 +1848,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.1" + watch_connectivity: + dependency: "direct main" + description: + name: watch_connectivity + sha256: a4257a314601c8448662d1a91421321a2e8a3207937fec4792116f1270ea8766 + url: "https://pub.dev" + source: hosted + version: "0.2.0" + watch_connectivity_platform_interface: + dependency: transitive + description: + name: watch_connectivity_platform_interface + sha256: "82e8f165eac779d71bff7f6269a8be530798311cf7f3c33f1594d93468747d11" + url: "https://pub.dev" + source: hosted + version: "0.2.0" watcher: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 0aa835d1..d39f2c9d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,15 +39,13 @@ dependencies: permission_handler: ^11.3.1 url_launcher: ^6.3.0 # Open URLS in external apps flutter_blue_plus: ^1.32.12 - flutter_foreground_task: ^8.6.0 # Keep the app running in the background on android + flutter_foreground_task: ^8.7.0 # Keep the app running in the background on android install_referrer: # Needs gradle namespace git: url: https://github.com/undreeyyy/flutter_plugin_install_referrer ref: fd87e9b8f0d5ed909e929388244456f72b9b63c7 quick_actions: ^1.0.7 # puts favorites on the home screen - flutter_wear_os_connectivity: - git: - url: https://github.com/Codel1417/flutter_wear_os_connectivity + watch_connectivity: ^0.2.0 audioplayers: ^6.1.0 firebase_testlab_detector: ^1.0.2 platform: ^3.1.5