From 810ca894dc7dff54f04e07091e79f9d2c23813f6 Mon Sep 17 00:00:00 2001 From: reasje Date: Thu, 18 Jul 2024 17:13:29 +0330 Subject: [PATCH 1/6] fix: Date parse error --- .../bluetooth/blueberry_ring/utils/blueberry_configs.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/features/common/packages/bluetooth/blueberry_ring/utils/blueberry_configs.dart b/lib/features/common/packages/bluetooth/blueberry_ring/utils/blueberry_configs.dart index e260a5b8..6dcc2e70 100644 --- a/lib/features/common/packages/bluetooth/blueberry_ring/utils/blueberry_configs.dart +++ b/lib/features/common/packages/bluetooth/blueberry_ring/utils/blueberry_configs.dart @@ -152,7 +152,8 @@ class BlueberryResolves { } int parseDate(List data) { - final parts = BlueberryCommandsUtils.radix16bcd(data); + // 200x24-0x06-0x05 0x06:0x39:0x02 + final parts = BlueberryCommandsUtils.radix16bcd(data, no0x: true); final ymd = '20${parts[0]}-${parts[1]}-${parts[2]}'; final hms = '${parts[3]}:${parts[4]}:${parts[5]}'; final date = DateTime.parse('$ymd $hms'); From 8554fa8b2dc0342c5781bac92f3ccde1e8141dc3 Mon Sep 17 00:00:00 2001 From: reasje Date: Thu, 18 Jul 2024 17:14:07 +0330 Subject: [PATCH 2/6] fix: uncomment notifications page --- .../notifications/notificaitons_page.dart | 94 +++++++++---------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/lib/features/settings/subfeatures/notifications/notificaitons_page.dart b/lib/features/settings/subfeatures/notifications/notificaitons_page.dart index 45716472..dbc3f776 100644 --- a/lib/features/settings/subfeatures/notifications/notificaitons_page.dart +++ b/lib/features/settings/subfeatures/notifications/notificaitons_page.dart @@ -289,53 +289,53 @@ class NotificationsPage extends HookConsumerWidget { notificationsState .periodicalCallData!.expectedEpochOccurrenceEnabled, ), - // const SizedBox(height: Sizes.spaceXLarge), - // MXCSwitchRowItem( - // title: translate('activity_reminder'), - // value: notificationsState - // .periodicalCallData!.activityReminderEnabled, - // onChanged: notificationsPresenter.changeActivityReminderEnabled, - // enabled: isSettingsChangeEnabled, - // textTrailingWidget: MXCInformationButton( - // texts: getBlueberryRingServiceInfo(context), - // ), - // titleStyle: FontTheme.of(context).h6(), - // ), - // const SizedBox(height: Sizes.spaceXLarge), - // MXCSwitchRowItem( - // title: translate('sleep_insight'), - // value: - // notificationsState.periodicalCallData!.sleepInsightEnabled, - // onChanged: notificationsPresenter.changeSleepInsightEnabled, - // enabled: isSettingsChangeEnabled, - // textTrailingWidget: MXCInformationButton( - // texts: getBlueberryRingServiceInfo(context), - // ), - // titleStyle: FontTheme.of(context).h6(), - // ), - // const SizedBox(height: Sizes.spaceXLarge), - // MXCSwitchRowItem( - // title: translate('heart_alert'), - // value: notificationsState.periodicalCallData!.heartAlertEnabled, - // onChanged: notificationsPresenter.changeHeartAlertEnabled, - // enabled: isSettingsChangeEnabled, - // textTrailingWidget: MXCInformationButton( - // texts: getBlueberryRingServiceInfo(context), - // ), - // titleStyle: FontTheme.of(context).h6(), - // ), - // const SizedBox(height: Sizes.spaceXLarge), - // MXCSwitchRowItem( - // title: translate('low_battery'), - // value: notificationsState.periodicalCallData!.lowBatteryEnabled, - // onChanged: notificationsPresenter.changeLowBatteryEnabled, - // enabled: isSettingsChangeEnabled, - // textTrailingWidget: MXCInformationButton( - // texts: getBlueberryRingServiceInfo(context), - // ), - // titleStyle: FontTheme.of(context).h6(), - // ), - // const SizedBox(height: Sizes.spaceXLarge), + const SizedBox(height: Sizes.spaceXLarge), + MXCSwitchRowItem( + title: translate('activity_reminder'), + value: notificationsState + .periodicalCallData!.activityReminderEnabled, + onChanged: notificationsPresenter.changeActivityReminderEnabled, + enabled: isSettingsChangeEnabled, + textTrailingWidget: MXCInformationButton( + texts: getBlueberryRingServiceInfo(context), + ), + titleStyle: FontTheme.of(context).h6(), + ), + const SizedBox(height: Sizes.spaceXLarge), + MXCSwitchRowItem( + title: translate('sleep_insight'), + value: + notificationsState.periodicalCallData!.sleepInsightEnabled, + onChanged: notificationsPresenter.changeSleepInsightEnabled, + enabled: isSettingsChangeEnabled, + textTrailingWidget: MXCInformationButton( + texts: getBlueberryRingServiceInfo(context), + ), + titleStyle: FontTheme.of(context).h6(), + ), + const SizedBox(height: Sizes.spaceXLarge), + MXCSwitchRowItem( + title: translate('heart_alert'), + value: notificationsState.periodicalCallData!.heartAlertEnabled, + onChanged: notificationsPresenter.changeHeartAlertEnabled, + enabled: isSettingsChangeEnabled, + textTrailingWidget: MXCInformationButton( + texts: getBlueberryRingServiceInfo(context), + ), + titleStyle: FontTheme.of(context).h6(), + ), + const SizedBox(height: Sizes.spaceXLarge), + MXCSwitchRowItem( + title: translate('low_battery'), + value: notificationsState.periodicalCallData!.lowBatteryEnabled, + onChanged: notificationsPresenter.changeLowBatteryEnabled, + enabled: isSettingsChangeEnabled, + textTrailingWidget: MXCInformationButton( + texts: getBlueberryRingServiceInfo(context), + ), + titleStyle: FontTheme.of(context).h6(), + ), + const SizedBox(height: Sizes.spaceXLarge), // const SizedBox(height: Sizes.spaceNormal), // MXCSwitchRowItem( // title: translate('daily_earnings'), From b18bfdf36dd3d374fce996b1f807d552cb741c6a Mon Sep 17 00:00:00 2001 From: reasje Date: Sun, 21 Jul 2024 16:03:05 +0330 Subject: [PATCH 3/6] fix: Handle bluetooth adapter being off --- .../packages/bluetooth/blue_plus/bluetooth_use_case.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/features/common/packages/bluetooth/blue_plus/bluetooth_use_case.dart b/lib/features/common/packages/bluetooth/blue_plus/bluetooth_use_case.dart index 2a9002b4..6c8f7e79 100644 --- a/lib/features/common/packages/bluetooth/blue_plus/bluetooth_use_case.dart +++ b/lib/features/common/packages/bluetooth/blue_plus/bluetooth_use_case.dart @@ -49,8 +49,13 @@ class BluetoothUseCase extends ReactiveUseCase { // usually start scanning, connecting, etc isScanningListener(); initScannerListener(); - } else { + } else if (state == BluetoothAdapterState.unauthorized || + state == BluetoothAdapterState.unavailable || + state == BluetoothAdapterState.off || + state == BluetoothAdapterState.unknown) { // show an error to the user, etc + cancelIsScanningListener(); + _cancelScannerListen(); } }); } From 24b5b2f9e5692acd32df6dbb2a4977d0883df161 Mon Sep 17 00:00:00 2001 From: reasje Date: Sun, 21 Jul 2024 16:03:43 +0330 Subject: [PATCH 4/6] fix: Disconnect blueberry when dapp closed --- .../dapps/subfeatures/open_dapp/open_dapp_presenter.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart index 28418532..f54274b6 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart @@ -85,9 +85,15 @@ class OpenDAppPresenter extends CompletePresenter { @override Future dispose() { characteriticListnerTimer?.cancel(); + closeBlueberryConnection(); return super.dispose(); } + // Disconnects from Blueberry If there a selected device. + void closeBlueberryConnection() { + state.selectedScanResult?.device.disconnect(); + } + void onWebViewCreated(InAppWebViewController controller) async { notify(() => state.webviewController = controller); updateCurrentUrl(null); From a2b7a1adca93b43d69ceb06c451aeeecafc591cb Mon Sep 17 00:00:00 2001 From: reasje Date: Sun, 21 Jul 2024 17:58:31 +0330 Subject: [PATCH 5/6] fix: callHandlerWrapper mechanism --- assets/js/bluetooth/bluetooth.js | 46 ++++++++++--------- .../open_dapp/open_dapp_presenter.dart | 31 ++++++------- packages/shared | 2 +- 3 files changed, 38 insertions(+), 41 deletions(-) diff --git a/assets/js/bluetooth/bluetooth.js b/assets/js/bluetooth/bluetooth.js index 5a1201d7..6af8e4f5 100644 --- a/assets/js/bluetooth/bluetooth.js +++ b/assets/js/bluetooth/bluetooth.js @@ -33,7 +33,7 @@ class BluetoothDevice extends EventTarget { async watchAdvertisements() { console.log("BluetoothRemoteGATTServer:watchAdvertisements "); - const response = await window.axs.callHandler( + const response = await window.axs?.callHandlerWrapper( "BluetoothDevice.watchAdvertisements" ); console.log( @@ -45,7 +45,7 @@ class BluetoothDevice extends EventTarget { async forget() { console.log("BluetoothRemoteGATTServer:forget "); - const response = await window.axs.callHandler("BluetoothDevice.forget"); + const response = await window.axs?.callHandlerWrapper("BluetoothDevice.forget"); console.log( "BluetoothRemoteGATTServer:forget ", JSON.stringify(response, null, 2) @@ -63,7 +63,7 @@ class BluetoothRemoteGATTServer extends EventTarget { async connect() { console.log("BluetoothRemoteGATTServer:connect "); - const response = await window.axs?.callHandler( + const response = await window.axs?.callHandlerWrapper( "BluetoothRemoteGATTServer.connect", {} ); @@ -78,13 +78,13 @@ class BluetoothRemoteGATTServer extends EventTarget { async disconnect() { console.log("BluetoothRemoteGATTServer:disconnect "); - await window.axs.callHandler("BluetoothRemoteGATTServer.disconnect", {}); + await window.axs?.callHandlerWrapper("BluetoothRemoteGATTServer.disconnect", {}); } async getPrimaryService(service) { console.log("BluetoothRemoteGATTServer:getPrimaryService ", service); const data = { service: service }; - const response = await window.axs?.callHandler( + const response = await window.axs?.callHandlerWrapper( "BluetoothRemoteGATTServer.getPrimaryService", data ); @@ -104,7 +104,7 @@ class BluetoothRemoteGATTServer extends EventTarget { async getPrimaryServices(service) { console.log("BluetoothRemoteGATTServer:getPrimaryServices ", service); const data = { service: service }; - const response = await window.axs.callHandler( + const response = await window.axs?.callHandlerWrapper( "BluetoothRemoteGATTServer.getPrimaryServices", data ); @@ -128,7 +128,7 @@ class BluetoothRemoteGATTCharacteristic extends EventTarget { serviceUUID: this.service.uuid, descriptor: descriptor, }; - const response = await window.axs.callHandler( + const response = await window.axs?.callHandlerWrapper( "BluetoothRemoteGATTCharacteristic.getDescriptor", data ); @@ -146,7 +146,7 @@ class BluetoothRemoteGATTCharacteristic extends EventTarget { descriptor: descriptor, }; - const response = await window.axs.callHandler( + const response = await window.axs?.callHandlerWrapper( "BluetoothRemoteGATTCharacteristic.getDescriptors", data ); @@ -156,7 +156,7 @@ class BluetoothRemoteGATTCharacteristic extends EventTarget { async readValue() { console.log("BluetoothRemoteGATTCharacteristic:readValue"); const data = { this: this.uuid, serviceUUID: this.service.uuid }; - const response = await window.axs.callHandler( + const response = await window.axs?.callHandlerWrapper( "BluetoothRemoteGATTCharacteristic.readValue", data ); @@ -182,7 +182,7 @@ class BluetoothRemoteGATTCharacteristic extends EventTarget { value: value, }; - const response = await window.axs.callHandler( + const response = await window.axs?.callHandlerWrapper( "BluetoothRemoteGATTCharacteristic.writeValue", data ); @@ -192,9 +192,7 @@ class BluetoothRemoteGATTCharacteristic extends EventTarget { JSON.stringify(response, null, 2) ); - if (response.error !== undefined && response.error === true) { - throw new Error("Error while writing value."); - } + return {}; } async writeValueWithResponse(value) { @@ -208,10 +206,12 @@ class BluetoothRemoteGATTCharacteristic extends EventTarget { value: value, }; - await window.axs.callHandler( + await window.axs?.callHandlerWrapper( "BluetoothRemoteGATTCharacteristic.writeValueWithResponse", data ); + + return {}; } async writeValueWithoutResponse(value) { @@ -225,17 +225,19 @@ class BluetoothRemoteGATTCharacteristic extends EventTarget { value: value, }; - await window.axs.callHandler( + await window.axs?.callHandlerWrapper( "BluetoothRemoteGATTCharacteristic.writeValueWithoutResponse", data ); + + return {}; } async startNotifications() { console.log("BluetoothRemoteGATTCharacteristic:startNotifications"); const data = { this: this.uuid, serviceUUID: this.service.uuid }; - await window.axs.callHandler( + await window.axs?.callHandlerWrapper( "BluetoothRemoteGATTCharacteristic.startNotifications", data ); @@ -246,7 +248,7 @@ class BluetoothRemoteGATTCharacteristic extends EventTarget { console.log("BluetoothRemoteGATTCharacteristic:stopNotifications"); const data = { this: this.uuid, serviceUUID: this.service.uuid }; - await window.axs.callHandler( + await window.axs?.callHandlerWrapper( "BluetoothRemoteGATTCharacteristic.stopNotifications", data ); @@ -273,7 +275,7 @@ class BluetoothRemoteGATTService extends EventTarget { characteristic ); let data = { this: this.uuid, characteristic: characteristic }; - const response = await window.axs?.callHandler( + const response = await window.axs?.callHandlerWrapper( "BluetoothRemoteGATTService.getCharacteristic", data ); @@ -296,7 +298,7 @@ class BluetoothRemoteGATTService extends EventTarget { "BluetoothRemoteGATTService:getCharacteristics ", characteristic ); - const response = await window.axs.callHandler( + const response = await window.axs?.callHandlerWrapper( "BluetoothRemoteGATTService.getCharacteristics", { this: "$uuid", characteristic: characteristic } ); @@ -305,7 +307,7 @@ class BluetoothRemoteGATTService extends EventTarget { async getIncludedService(service) { console.log("BluetoothRemoteGATTService:getIncludedService ", service); - const response = await window.axs.callHandler( + const response = await window.axs?.callHandlerWrapper( "BluetoothRemoteGATTService.getIncludedService", { this: "$uuid", service: service } ); @@ -314,7 +316,7 @@ class BluetoothRemoteGATTService extends EventTarget { async getIncludedServices(service) { console.log("BluetoothRemoteGATTService:getIncludedServices ", service); - const response = await window.axs.callHandler( + const response = await window.axs?.callHandlerWrapper( "BluetoothRemoteGATTService.getIncludedServices", { this: "$uuid", service: service } ); @@ -336,7 +338,7 @@ class AXSBluetooth { async requestDevice(options) { console.log("AXSBluetooth:requestDevice ", options); - const response = await window.axs?.callHandler("requestDevice", options); + const response = await window.axs?.callHandlerWrapper("requestDevice", options); const gatt = new BluetoothRemoteGATTServer( response.gatt.device, diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart index f54274b6..59546679 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart @@ -815,7 +815,8 @@ class OpenDAppPresenter extends CompletePresenter { Future> handleBluetoothRemoteGATTCharacteristicStartNotifications( Map data) async { - collectLog('handleBluetoothRemoteGATTCharacteristicStartNotifications : $data'); + collectLog( + 'handleBluetoothRemoteGATTCharacteristicStartNotifications : $data'); final selectedService = await getSelectedService(data['serviceUUID']); final selectedCharacteristic = getSelectedCharacteristic(data['this'], selectedService); @@ -832,7 +833,8 @@ class OpenDAppPresenter extends CompletePresenter { Future> handleBluetoothRemoteGATTCharacteristicStopNotifications( Map data) async { - collectLog('handleBluetoothRemoteGATTCharacteristicStopNotifications : $data'); + collectLog( + 'handleBluetoothRemoteGATTCharacteristicStopNotifications : $data'); final selectedService = await getSelectedService(data['serviceUUID']); final selectedCharacteristic = getSelectedCharacteristic(data['this'], selectedService); @@ -852,19 +854,16 @@ class OpenDAppPresenter extends CompletePresenter { final selectedService = await getSelectedService(data['serviceUUID']); final selectedCharacteristic = getSelectedCharacteristic(data['this'], selectedService); - final value = Uint8List.fromList(List.from((data['value'] as Map).values.toList())); + final value = Uint8List.fromList(List.from( + (data['value'] as Map).values.toList())); - try { - collectLog('handleWrites:value $value'); - if (withResponse) { - await selectedCharacteristic.write(value); - } else { - await selectedCharacteristic.write(value, withoutResponse: true); - } - return {}; - } catch (e) { - return {'error': 'true'}; + collectLog('handleWrites:value $value'); + if (withResponse) { + await selectedCharacteristic.write(value); + } else { + await selectedCharacteristic.write(value, withoutResponse: true); } + return {}; } Future> @@ -909,14 +908,10 @@ class OpenDAppPresenter extends CompletePresenter { blue_plus.BluetoothCharacteristic characteristic, ) async { await characteristic.setNotifyValue(true); - // characteriticListnerTimer = Timer.periodic(const Duration(seconds: 5), (timer) { - // characteristic.read(); - // }); characteristicValueStreamSubscription = characteristic.lastValueStream.listen((event) async { final uInt8List = Uint8List.fromList(event); - print(uInt8List); collectLog('characteristicValueStreamSubscription:event $event'); collectLog( 'characteristicValueStreamSubscription:uInt8List ${uInt8List.toString()}'); @@ -1012,7 +1007,7 @@ class OpenDAppPresenter extends CompletePresenter { status: AXSJSChannelResponseStatus.failed, data: null, message: e.toString()); - return response.toMap((data) => {'message': e.toString()}); + return response.toMap((data) => {'message': e}); } } diff --git a/packages/shared b/packages/shared index 7f19ffe7..09fe073a 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit 7f19ffe7fd19b885d5d297ae47cc9f3ad09b35a6 +Subproject commit 09fe073aa4e17559f95654da0e8248d307b3279c From e7879a49f6a4005624f01f8a1e5068fd866d15bc Mon Sep 17 00:00:00 2001 From: reasje Date: Sun, 21 Jul 2024 17:58:57 +0330 Subject: [PATCH 6/6] fix: Uninitialized error stream --- .../packages/bluetooth/blue_plus/bluetooth_use_case.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/features/common/packages/bluetooth/blue_plus/bluetooth_use_case.dart b/lib/features/common/packages/bluetooth/blue_plus/bluetooth_use_case.dart index 6c8f7e79..12efc251 100644 --- a/lib/features/common/packages/bluetooth/blue_plus/bluetooth_use_case.dart +++ b/lib/features/common/packages/bluetooth/blue_plus/bluetooth_use_case.dart @@ -33,9 +33,9 @@ class BluetoothUseCase extends ReactiveUseCase { final ChainConfigurationUseCase _chainConfigurationUseCase; final AuthUseCase _authUseCase; - late StreamSubscription>? scannerListener; - late StreamSubscription? stateListener; - late StreamSubscription? isScanningStateListener; + StreamSubscription>? scannerListener; + StreamSubscription? stateListener; + StreamSubscription? isScanningStateListener; late final ValueStream isScanning = reactive(false); late final ValueStream bluetoothStatus =