Files
meshcore-sar_android/lib/services/build_info_service.dart
Janez T 4577dec95a feat: Implement Windows runner for Flutter application
- Added FlutterWindow class to manage the Flutter view within a Win32 window.
- Created main entry point in main.cpp to initialize and run the Flutter application.
- Implemented utility functions for console attachment and command line argument parsing.
- Added resource management for application icon and manifest.
- Enhanced Win32Window class for DPI awareness and theme management.
- Included necessary headers and resource files for building the Windows runner.
2025-11-14 09:52:00 +01:00

55 lines
1.8 KiB
Dart

import 'dart:io' show Platform;
import 'package:flutter/services.dart';
import 'package:flutter/foundation.dart';
/// Service for accessing build information from native platform code
/// Currently supports Android only - returns "unknown" for other platforms
class BuildInfoService {
static final BuildInfoService _instance = BuildInfoService._internal();
factory BuildInfoService() => _instance;
BuildInfoService._internal();
static const MethodChannel _channel = MethodChannel('com.meshcore.sar/build_info');
String? _cachedCommitHash;
/// Get the commit hash that was embedded during build time
/// Returns "unknown" if:
/// - Not running on Android
/// - Platform channel call fails
/// - Build was not configured with COMMIT_HASH
Future<String> getCommitHash() async {
// Return cached value if available
if (_cachedCommitHash != null) {
return _cachedCommitHash!;
}
// Only Android has the platform channel implementation
if (!Platform.isAndroid) {
debugPrint('[BuildInfoService] Not on Android platform, returning "unknown"');
_cachedCommitHash = 'unknown';
return _cachedCommitHash!;
}
try {
final String commitHash = await _channel.invokeMethod('getCommitHash');
_cachedCommitHash = commitHash;
debugPrint('[BuildInfoService] Commit hash: $commitHash');
return commitHash;
} on PlatformException catch (e) {
debugPrint('[BuildInfoService] Failed to get commit hash: ${e.message}');
_cachedCommitHash = 'unknown';
return _cachedCommitHash!;
} catch (e) {
debugPrint('[BuildInfoService] Unexpected error getting commit hash: $e');
_cachedCommitHash = 'unknown';
return _cachedCommitHash!;
}
}
/// Clear cached commit hash (useful for testing)
void clearCache() {
_cachedCommitHash = null;
}
}