Skip to content

Commit a5c349a

Browse files
Merge branch 'main' into main
2 parents e5250be + 62d35d8 commit a5c349a

File tree

6 files changed

+96
-17
lines changed

6 files changed

+96
-17
lines changed

.github/workflows/firebase-hosting-pull-request.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ permissions:
88
contents: read
99
pull-requests: write
1010
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Get flutter version
16+
run: echo "flutter_version=`cat .flutter_version`" >> $GITHUB_ENV
17+
id: flutter_version
18+
- uses: subosito/flutter-action@v2
19+
with:
20+
channel: "stable"
21+
cache: true
22+
flutter-version: ${{ env.flutter_version }}
23+
- run: flutter analyze
24+
- run: (cd example && flutter build web --dart-define=BUILD_COMMIT=$(git
25+
rev-parse --short HEAD) --dart-define=BUILD_BRANCH=$(git rev-parse
26+
--abbrev-ref HEAD))
1127
build_and_preview:
1228
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
1329
runs-on: ubuntu-latest

example/lib/main.dart

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22

33
import 'package:example/widgets/button_state_widget.dart';
44
import 'package:example/widgets/fota/firmware_update.dart';
5+
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
56
import 'package:open_earable_flutter/open_earable_flutter.dart';
67
import 'package:example/global_theme.dart';
78
import 'package:flutter/material.dart';
@@ -152,9 +153,30 @@ class MyAppState extends State<MyApp> {
152153
trailing: _buildTrailingWidget(device.id,
153154
Theme.of(context).colorScheme.secondary),
154155
onTap: () async {
155-
Wearable wearable = await _wearableManager
156-
.connectToDevice(device);
157-
provider.setSelectedPeripheral(wearable);
156+
try {
157+
Wearable wearable = await _wearableManager
158+
.connectToDevice(device);
159+
provider.setSelectedPeripheral(wearable);
160+
} catch (e) {
161+
String message = _wearableManager
162+
.deviceErrorMessage(e, device.name);
163+
if (context.mounted) {
164+
showPlatformDialog(
165+
context: context,
166+
builder: (context) => PlatformAlertDialog(
167+
title: PlatformText('Connection Error'),
168+
content: PlatformText(message),
169+
actions: [
170+
PlatformDialogAction(
171+
onPressed: () =>
172+
Navigator.of(context).pop(),
173+
child: PlatformText('OK'),
174+
),
175+
],
176+
),
177+
);
178+
}
179+
}
158180
},
159181
),
160182
if (index != discoveredDevices.length - 1)
@@ -246,7 +268,8 @@ class MyAppState extends State<MyApp> {
246268
if (_connectedDevice is ButtonManager)
247269
GroupedBox(
248270
title: "Button State",
249-
child: ButtonStateWidget(buttonManager: _connectedDevice as ButtonManager),
271+
child: ButtonStateWidget(
272+
buttonManager: _connectedDevice as ButtonManager),
250273
),
251274
if (_connectedDevice is FrequencyPlayer)
252275
GroupedBox(

example/pubspec.lock

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ packages:
4545
dependency: transitive
4646
description:
4747
name: characters
48-
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
48+
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
4949
url: "https://pub.dev"
5050
source: hosted
51-
version: "1.4.0"
51+
version: "1.4.1"
5252
clock:
5353
dependency: transitive
5454
description:
@@ -190,6 +190,14 @@ packages:
190190
url: "https://pub.dev"
191191
source: hosted
192192
version: "6.0.0"
193+
flutter_platform_widgets:
194+
dependency: "direct main"
195+
description:
196+
name: flutter_platform_widgets
197+
sha256: "22a86564cb6cc0b93637c813ca91b0b1f61c2681a31e0f9d77590c1fa9f12020"
198+
url: "https://pub.dev"
199+
source: hosted
200+
version: "9.0.0"
193201
flutter_plugin_android_lifecycle:
194202
dependency: transitive
195203
description:
@@ -308,18 +316,18 @@ packages:
308316
dependency: transitive
309317
description:
310318
name: matcher
311-
sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
319+
sha256: "12956d0ad8390bbcc63ca2e1469c0619946ccb52809807067a7020d57e647aa6"
312320
url: "https://pub.dev"
313321
source: hosted
314-
version: "0.12.17"
322+
version: "0.12.18"
315323
material_color_utilities:
316324
dependency: transitive
317325
description:
318326
name: material_color_utilities
319-
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
327+
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
320328
url: "https://pub.dev"
321329
source: hosted
322-
version: "0.11.1"
330+
version: "0.13.0"
323331
mcumgr_flutter:
324332
dependency: "direct main"
325333
description:
@@ -568,10 +576,10 @@ packages:
568576
dependency: transitive
569577
description:
570578
name: test_api
571-
sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
579+
sha256: "19a78f63e83d3a61f00826d09bc2f60e191bf3504183c001262be6ac75589fb8"
572580
url: "https://pub.dev"
573581
source: hosted
574-
version: "0.7.4"
582+
version: "0.7.8"
575583
tuple:
576584
dependency: transitive
577585
description:

example/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ dependencies:
4242
# Use with the CupertinoIcons class for iOS style icons.
4343
cupertino_icons: ^1.0.2
4444
flutter_colorpicker: ^1.1.0
45+
flutter_platform_widgets: ^9.0.0
4546
meta: ^1.16.0
4647
bloc: ^9.1.0
4748
flutter_svg: ^2.0.17

lib/open_earable_flutter.dart

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'dart:async';
55
import 'package:logger/logger.dart';
66
import 'package:meta/meta.dart';
77
import 'package:open_earable_flutter/src/managers/exg/exg_factory.dart';
8+
import 'package:open_earable_flutter/src/exceptions/device_exception.dart';
89
import 'package:open_earable_flutter/src/models/devices/cosinuss_one_factory.dart';
910
import 'package:open_earable_flutter/src/models/devices/esense_factory.dart';
1011
import 'package:open_earable_flutter/src/models/devices/open_earable_factory.dart';
@@ -195,7 +196,7 @@ class WearableManager {
195196
}) async {
196197
if (_connectedIds.contains(device.id)) {
197198
logger.w('Device ${device.id} is already connected');
198-
throw Exception('Device is already connected');
199+
throw AlreadyConnectedException();
199200
}
200201
_connectingStreamController.add(device);
201202

@@ -228,9 +229,9 @@ class WearableManager {
228229
}
229230
_connectedIds.remove(device.id);
230231
await _bleManager.disconnect(device.id);
231-
throw Exception('Device is currently not supported');
232+
throw UnsupportedDeviceException();
232233
} else {
233-
throw Exception('Failed to connect to device');
234+
throw ConnectionFailedException();
234235
}
235236
}
236237

@@ -254,12 +255,25 @@ class WearableManager {
254255
);
255256
connectedWearables.add(wearable);
256257
} catch (e) {
257-
logger.e('Failed to connect to system device ${device.id}: $e');
258+
logger.e(
259+
'Failed to connect to system device ${device.id}: ${deviceErrorMessage(e, device.name)}',
260+
);
258261
}
259262
}
260263
return connectedWearables;
261264
}
262265

266+
String deviceErrorMessage(dynamic e, String deviceName) {
267+
return switch (e) {
268+
UnsupportedDeviceException _ => 'Device "$deviceName" is not supported.',
269+
AlreadyConnectedException _ =>
270+
'Device "$deviceName" is already connected.',
271+
ConnectionFailedException _ =>
272+
'Failed to connect to device "$deviceName". Please try again.',
273+
_ => e.toString(),
274+
};
275+
}
276+
263277
void addPairingRule(PairingRule rule) {
264278
_pairingManager.addRule(rule);
265279
}
@@ -294,7 +308,9 @@ class WearableManager {
294308
try {
295309
await connectToDevice(discoveredDevice);
296310
} catch (e) {
297-
logger.e('Error auto connecting device ${discoveredDevice.id}: $e');
311+
logger.e(
312+
'Error auto connecting device ${discoveredDevice.id}: ${deviceErrorMessage(e, discoveredDevice.name)}',
313+
);
298314
}
299315
}
300316
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
sealed class DeviceException implements Exception {
2+
const DeviceException();
3+
}
4+
5+
class UnsupportedDeviceException extends DeviceException {
6+
const UnsupportedDeviceException();
7+
}
8+
9+
class AlreadyConnectedException extends DeviceException {
10+
const AlreadyConnectedException();
11+
}
12+
13+
class ConnectionFailedException extends DeviceException {
14+
const ConnectionFailedException();
15+
}

0 commit comments

Comments
 (0)