diff --git a/android/app/src/main/kotlin/com/rtirl/chat/MainActivity.kt b/android/app/src/main/kotlin/com/rtirl/chat/MainActivity.kt index 3d48f0aa..bbdc619e 100644 --- a/android/app/src/main/kotlin/com/rtirl/chat/MainActivity.kt +++ b/android/app/src/main/kotlin/com/rtirl/chat/MainActivity.kt @@ -36,7 +36,6 @@ class MainActivity : FlutterActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) handleIntent() - } private fun startNotificationService() { @@ -74,7 +73,7 @@ class MainActivity : FlutterActivity() { startService(intent) result.success(true) } - "showNotification" -> { + "showNotification" -> { startNotificationService() result.success(true) } diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 238c2e3b..5a89bc9c 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -25,6 +25,7 @@ import 'package:rtchat/models/tts.dart'; import 'package:rtchat/models/user.dart'; import 'package:rtchat/notifications_plugin.dart'; import 'package:rtchat/tts_plugin.dart'; +import 'package:thermal/thermal.dart'; import 'package:wakelock_plus/wakelock_plus.dart'; class ResizableWidget extends StatefulWidget { @@ -165,6 +166,8 @@ class HomeScreen extends StatefulWidget { class _HomeScreenState extends State with TickerProviderStateMixin { final _scaffoldKey = GlobalKey(); + final _thermal = Thermal(); + @override void initState() { super.initState(); @@ -175,6 +178,7 @@ class _HomeScreenState extends State with TickerProviderStateMixin { debugPrint("Post frame callback post executed"); final model = Provider.of(context, listen: false); final ttsModel = Provider.of(context, listen: false); + final layoutModel = Provider.of(context, listen: false); NotificationsPlugin.listenToTts(ttsModel); @@ -184,8 +188,38 @@ class _HomeScreenState extends State with TickerProviderStateMixin { if (mounted) { debugPrint("Conditions passed"); model.showAudioPermissionDialog(context); + debugPrint("Directly calling listenToTTs"); + + initializeThermal(ttsModel, layoutModel); + } + }); + } + + void initializeThermal(TtsModel model, LayoutModel layoutModel) async { + _thermal.onBatteryTemperatureChanged.listen((double temperature) async { + if (temperature > 45) { + layoutModel.isShowPreview = false; + + updateChannelSubscription(""); + await TextToSpeechPlugin.speak("Text to speech disabled"); + await TextToSpeechPlugin.disableTTS(); + NotificationsPlugin.cancelNotification(); } }); + + _thermal.onThermalStatusChanged.listen((ThermalStatus state) { + if (layoutModel.isShowPreview) { + _showThermalWarning(); + } + }); + } + + void _showThermalWarning() { + final snackBar = SnackBar( + content: Text(AppLocalizations.of(context)?.streamPreviewMessage ?? ''), + ); + + ScaffoldMessenger.of(context).showSnackBar(snackBar); } @override diff --git a/pubspec.lock b/pubspec.lock index 13c6c479..58a921e5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -971,6 +971,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.2" + thermal: + dependency: "direct main" + description: + name: thermal + sha256: "1b65a235d7f52729adf10cdc2f7338ebbefd97b3a5363095c287e3ef27548524" + url: "https://pub.dev" + source: hosted + version: "1.1.5" typed_data: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 04e04a22..7f820494 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -46,6 +46,7 @@ dependencies: streaming_shared_preferences: ^2.0.0 sticky_headers: ^0.3.0+2 styled_text: ^8.1.0 + thermal: ^1.1.5 url_launcher: ^6.3.0 wakelock_plus: ^1.2.5 webview_flutter: ^4.5.0 @@ -54,9 +55,9 @@ dependencies: uuid: ^4.4.0 dev_dependencies: - flutter_lints: ^4.0.0 flutter_test: sdk: flutter + flutter_lints: ^4.0.0 flutter: uses-material-design: true