From eee8883a05b9c78d7fa65b45e7d3e987a32b3c2c Mon Sep 17 00:00:00 2001 From: Codel1417 Date: Mon, 2 Sep 2024 12:42:50 -0400 Subject: [PATCH] change wear library --- lib/Backend/wear_bridge.dart | 92 ++++++------------- .../pages/developer/developer_menu.dart | 56 +++++++++++ pubspec.lock | 45 +++++---- pubspec.yaml | 10 +- 4 files changed, 111 insertions(+), 92 deletions(-) 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 a995bd99..9284e455 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -546,10 +546,10 @@ packages: dependency: "direct main" description: name: flutter_adaptive_scaffold - sha256: fe16ddead74e728c88aa33e3d0cef611a556b27194639f9e9ec4a0e32400d87e + sha256: "93d20f0a4fbded8755571cc1f11a05a116cdc401ebaa15293ea2f87618fa2d18" url: "https://pub.dev" source: hosted - version: "0.2.3" + version: "0.2.4" flutter_android_volume_keydown: dependency: "direct main" description: @@ -571,10 +571,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: @@ -700,14 +700,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: @@ -721,15 +713,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 @@ -1765,10 +1748,10 @@ packages: dependency: "direct main" description: name: uuid - sha256: "83d37c7ad7aaf9aa8e275490669535c8080377cfa7a7004c24dfac53afffaa90" + sha256: f33d6bb662f0e4f79dcd7ada2e6170f3b3a2530c28fc41f49a411ddedd576a77 url: "https://pub.dev" source: hosted - version: "4.4.2" + version: "4.5.0" vector_graphics: dependency: transitive description: @@ -1841,6 +1824,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 29921254..bcca4374 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: vector_math: ^2.1.4 # used for joystick collection: ^1.18.0 # Priority Queue intl: #pinned to flutter version? - uuid: ^4.4.2 # Used to generate UUID v4 ids for custom actions & move lists + uuid: ^4.5.0 # Used to generate UUID v4 ids for custom actions & move lists json_annotation: ^4.9.0 crypto: ^3.0.5 # used for md5 hash checking during ota download circular_buffer: ^0.11.0 # Used for serial console @@ -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 @@ -60,7 +58,7 @@ dependencies: flutter_screen_lock: ^9.1.0 # used to hide dev mode toggle introduction_screen: ^3.1.14 # Onboarding flex_color_picker: ^3.5.1 - flutter_adaptive_scaffold: ^0.2.3 + flutter_adaptive_scaffold: ^0.2.4 animate_do: ^3.3.4 fl_chart: ^0.69.0 # Used for the battery graph chart_sparkline: ^1.1.1 # used for the move easing visual