Skip to content

Commit a6112f3

Browse files
committed
Enhance debug logging for development builds, update build mode to debug, and improve Bluetooth connection handling
1 parent ed9abea commit a6112f3

File tree

6 files changed

+42
-5
lines changed

6 files changed

+42
-5
lines changed

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"Bash(flutter build:*)",
1313
"Bash(flutter doctor:*)",
1414
"Bash(flutter create:*)",
15-
"Bash(find:*)"
15+
"Bash(find:*)",
16+
"Bash(grep:*)"
1617
]
1718
}
1819
}

android/local.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
sdk.dir=/opt/homebrew/share/android-commandlinetools
22
flutter.sdk=/opt/homebrew/share/flutter
3-
flutter.buildMode=release
3+
flutter.buildMode=debug
44
flutter.versionName=1.0.0
5-
flutter.versionCode=1769177495
5+
flutter.versionCode=1

lib/providers/app_state_provider.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ class AppStateProvider extends ChangeNotifier {
284284
_autoPingTimer = AutoPingTimer(_statusMessageService);
285285
_rxWindowTimer = RxWindowTimer(_statusMessageService);
286286

287+
// Auto-enable debug logging for development builds
288+
await _autoEnableDebugLogsIfDevelopmentBuild();
289+
287290
// Initialize channel service with Public channel only (regional channels added after auth)
288291
await ChannelService.initializePublicChannel();
289292
debugLog('[APP] Channel service initialized (Public channel only)');
@@ -1807,6 +1810,24 @@ class AppStateProvider extends ChangeNotifier {
18071810
// Debug File Logging (Mobile Only)
18081811
// ============================================
18091812

1813+
/// Auto-enable debug file logging for development builds
1814+
Future<void> _autoEnableDebugLogsIfDevelopmentBuild() async {
1815+
if (kIsWeb) return; // File logging not available on web
1816+
1817+
if (AppConstants.isDevelopmentBuild) {
1818+
debugLog('[INIT] Development build detected (${AppConstants.appVersion}), auto-enabling debug logs');
1819+
try {
1820+
await DebugFileLogger.enable();
1821+
_debugLogsEnabled = true;
1822+
await _refreshDebugLogFiles();
1823+
} catch (e) {
1824+
debugError('[INIT] Failed to auto-enable debug logs: $e');
1825+
}
1826+
} else {
1827+
debugLog('[INIT] Release build (${AppConstants.appVersion}), debug logs disabled by default');
1828+
}
1829+
}
1830+
18101831
/// Enable debug file logging
18111832
///
18121833
/// Creates a new log file and starts writing debug output to it.

lib/screens/settings_screen.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
490490
),
491491
subtitle: Text(
492492
appState.debugLogsEnabled
493-
? 'Writing logs to file'
493+
? AppConstants.isDevelopmentBuild
494+
? 'Auto-enabled for development build'
495+
: 'Writing logs to file'
494496
: 'Enable to save debug logs to device',
495497
),
496498
value: appState.debugLogsEnabled,

lib/services/bluetooth/mobile_bluetooth.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ class MobileBluetoothService implements BluetoothService {
235235

236236
// Connect to GATT server FIRST (before subscribing to state changes)
237237
print('[BLE] Connecting to GATT...');
238-
await _bleDevice!.connect(timeout: const Duration(seconds: 15));
238+
await _bleDevice!.connect(
239+
timeout: const Duration(seconds: 15),
240+
mtu: null, // Disable automatic MTU negotiation to avoid race condition errors on Android
241+
);
239242
print('[BLE] GATT connected');
240243

241244
// NOW subscribe to connection state changes (after we're connected)

lib/utils/constants.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ class AppConstants {
1414
? _buildVersion
1515
: 'APP-${DateTime.now().millisecondsSinceEpoch ~/ 1000}';
1616

17+
/// Returns true if the app version is a development build (EPOCH format)
18+
/// Development builds: APP-<unix_epoch_seconds> (e.g., APP-1705273849) - digits only
19+
/// Release builds: APP-<x.y.z> (e.g., APP-1.2.3) - contains dots
20+
static bool get isDevelopmentBuild {
21+
// EPOCH format: APP- followed by digits only (no dots)
22+
// Release format: APP- followed by semantic version with dots (e.g., APP-1.2.3)
23+
final epochPattern = RegExp(r'^APP-\d+$');
24+
return epochPattern.hasMatch(appVersion);
25+
}
26+
1727
/// Application name
1828
static const String appName = 'MeshMapper';
1929

0 commit comments

Comments
 (0)