Skip to content

Commit 1da1bae

Browse files
committed
fix: auto-start advertising on launch and optimize BLE packet for better discovery
1 parent 4151091 commit 1da1bae

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

lib/src/core/background_service.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ Future<void> _startServiceLogic(
8686
ServiceInstance service,
8787
BLEAdvertiser advertiser,
8888
) async {
89-
await Future.delayed(const Duration(seconds: 1));
9089
final prefs = await SharedPreferences.getInstance();
9190
String currentName = prefs.getString('advertising_name_v2') ?? "BLE Node";
9291
bool advertisingOn = false;

lib/src/features/discovery/data/ble_advertiser.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class BLEAdvertiser {
2424
static const messageCharUuid = '12345678-90ab-cdef-1234-567890abcdef';
2525

2626
static const int manufacturerId = MeshConstants.manufacturerId;
27-
static const int maxNameLength = 13;
27+
static const int maxNameLength = 10;
2828

2929
static bool _initialized = false,
3030
_servicesAdded = false,
@@ -209,7 +209,7 @@ class BLEAdvertiser {
209209
manufacturerId: manufacturerId,
210210
data: manufacturerData,
211211
),
212-
addManufacturerDataInScanResponse: false, // Move StableId to primary packet
212+
addManufacturerDataInScanResponse: true, // Allow OS to balance between packets
213213
scanResponseManufacturerData: ManufacturerData(
214214
manufacturerId: manufacturerId,
215215
data: scanResponseData,

lib/src/features/onboarding/presentation/onboarding_controller.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ class OnboardingController extends _$OnboardingController {
1717
final user = await ref.watch(profileControllerProvider.future);
1818
final isOnboarded = user?.isOnboarded ?? false;
1919
if (isOnboarded) {
20-
_log.info('User already onboarded, ensuring service is running');
21-
await initializeBackgroundService().catchError((e) {
20+
_log.info('User already onboarded, ensuring service is running and advertising is active');
21+
await initializeBackgroundService().then((_) {
22+
if (user != null) {
23+
FlutterBackgroundService().invoke("startAdvertising", {"name": user.username});
24+
}
25+
}).catchError((e) {
2226
_log.severe('Failed to auto-start background service: $e');
2327
});
2428
}

0 commit comments

Comments
 (0)