Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed multiple devices not showing up. #239

Merged
merged 2 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Version 1.3.1+11

- (Android) Fixed multiple devices not showing up.
- (Android) Fixed device state not reporting correctly in the ui (only for the second device somehow).

# Version 1.3.0+10 08-12-2023

- (Android) Update to support new features from 12, 13, and 14.
Expand Down
15 changes: 4 additions & 11 deletions lib/lighthouse_provider/widgets/lighthouse_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,14 @@ class LighthouseWidget extends StatefulWidget {
required this.selecting,
this.nickname,
this.sleepState = LighthousePowerState.sleep,
super.key})
: statefulDevice = lighthouseDevice is StatefulLighthouseDevice;
super.key});

final LighthouseDevice lighthouseDevice;
final VoidCallback onSelected;
final bool selected;
final String? nickname;
final LighthousePowerState sleepState;
final bool selecting;
final bool statefulDevice;

@override
State<StatefulWidget> createState() {
Expand All @@ -219,22 +217,17 @@ class LighthouseWidget extends StatefulWidget {
}

class LighthouseWidgetState extends State<LighthouseWidget> {
Stream<int>? _powerStateStream;

@override
void initState() {
super.initState();
if (widget.statefulDevice) {
_powerStateStream =
(widget.lighthouseDevice as StatefulLighthouseDevice).powerState;
}
}

@override
Widget build(final BuildContext context) {
if (widget.statefulDevice) {
if (widget.lighthouseDevice is StatefulLighthouseDevice) {
return StreamBuilder<int>(
stream: _powerStateStream,
stream:
(widget.lighthouseDevice as StatefulLighthouseDevice).powerState,
builder: (final BuildContext context,
final AsyncSnapshot<int> powerStateSnapshot) {
final powerStateData = powerStateSnapshot.data ?? 0xFF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ class FlutterBluePlusLighthouseBackEnd extends BLELighthouseBackEnd {
await blue_plus.FlutterBluePlus.startScan(
androidScanMode: blue_plus.AndroidScanMode.lowLatency,
timeout: timeout,
oneByOne: true,
//TODO: use the extra features
oneByOne: false,
withKeywords:
providers.map((final e) => e.namePrefix).toList(growable: false),
);
} on PlatformException catch (e, s) {
if (e.code == "bluetooth_unavailable") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ mixin StatefulLighthouseDevice on LighthouseDevice {
}
} catch (e, s) {
lighthouseLogger.severe(
"Could not get state, maybe the device is already disconnected",
"Could not get state from $name, maybe the device is already disconnected",
e,
s);
await disconnect();
Expand All @@ -138,18 +138,19 @@ mixin StatefulLighthouseDevice on LighthouseDevice {
}
} else {
if (retryCount++ > 5) {
lighthouseLogger.shout("Unable to get power state because the "
"mutex has been locked for a while ($retryCount)."
"\nLocked by: ${transactionMutex.lockTrace?.toString()}");
lighthouseLogger
.shout("Unable to get power state from $name because the "
"mutex has been locked for a while ($retryCount)."
"\nLocked by: ${transactionMutex.lockTrace?.toString()}");
}
}
} else {
lighthouseLogger.info("Cleaning-up old subscription!");
lighthouseLogger.info("Cleaning-up old subscription! For $name");
disconnect();
}
});
powerStateSubscription.onDone(() {
lighthouseLogger.info("Cleaning-up power state subscription!");
lighthouseLogger.info("Cleaning-up power state subscription! For $name");
_powerStateSubscription = null;
});
_powerStateSubscription = powerStateSubscription;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.3.0+10
version: 1.3.1-beta2+11

environment:
sdk: ">=2.19.0 <3.0.0"
Expand Down
29 changes: 29 additions & 0 deletions scripts/build-release-apks-fat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

cd "$SCRIPT_DIR/../" || exit

flutter build apk --release --no-obfuscate \
--flavor=defaultVersion \
--dart-define=includeGooglePlayInAppPurchases=false \
--dart-define=includeSupportButtons=true \
--dart-define=includeSupportPage=true \
--dart-define=includePaypal=true \
--dart-define=includeGithubSponsor=true \
--target-platform=android-arm,android-arm64,android-x64

EXIT_CODE=$?

if [ $EXIT_CODE != 0 ]; then
echo 'Could not build'
exit $EXIT_CODE
fi

set -e

mkdir -p "$SCRIPT_DIR/../output"

VERSION=$(grep -oP 'version: \K\d+\.\d+\.\d+(-.+)?\+\d+' "${SCRIPT_DIR}/../pubspec.yaml")

cp -vrf "${SCRIPT_DIR}/../build/app/outputs/flutter-apk/app-defaultversion-release.apk" "${SCRIPT_DIR}/../output/lighthouse_pm-${VERSION}.fat.apk"
2 changes: 1 addition & 1 deletion scripts/build-release-apks-github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ set -e

mkdir -p "$SCRIPT_DIR/../output"

VERSION=$(grep -oP 'version: \K\d+\.\d+\.\d+\+\d+' "${SCRIPT_DIR}/../pubspec.yaml")
VERSION=$(grep -oP 'version: \K\d+\.\d+\.\d+(-.+)?\+\d+' "${SCRIPT_DIR}/../pubspec.yaml")

function copy_result() {
VERSION=$1
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-release-bundle-playstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ set -e

mkdir -p "$SCRIPT_DIR/../output"

VERSION=$(grep -oP 'version: \K\d+\.\d+\.\d+\+\d+' "${SCRIPT_DIR}/../pubspec.yaml")
VERSION=$(grep -oP 'version: \K\d+\.\d+\.\d+(-.+)?\+\d+' "${SCRIPT_DIR}/../pubspec.yaml")

cp -vrf "${SCRIPT_DIR}/../build/app/outputs/bundle/googlePlayRelease/app-googlePlay-release.aab" "$SCRIPT_DIR/../output/googlePlay-${VERSION}.aab"