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

fix: thermal warnings #1203

Closed
wants to merge 16 commits into from
3 changes: 1 addition & 2 deletions android/app/src/main/kotlin/com/rtirl/chat/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class MainActivity : FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
handleIntent()

}

private fun startNotificationService() {
Expand Down Expand Up @@ -74,7 +73,7 @@ class MainActivity : FlutterActivity() {
startService(intent)
result.success(true)
}
"showNotification" -> {
"showNotification" -> {
startNotificationService()
result.success(true)
}
Expand Down
34 changes: 34 additions & 0 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -165,6 +166,8 @@ class HomeScreen extends StatefulWidget {
class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
final _scaffoldKey = GlobalKey<ScaffoldState>();

final _thermal = Thermal();

@override
void initState() {
super.initState();
Expand All @@ -175,6 +178,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
debugPrint("Post frame callback post executed");
final model = Provider.of<AudioModel>(context, listen: false);
final ttsModel = Provider.of<TtsModel>(context, listen: false);
final layoutModel = Provider.of<LayoutModel>(context, listen: false);

NotificationsPlugin.listenToTts(ttsModel);

Expand All @@ -184,8 +188,38 @@ class _HomeScreenState extends State<HomeScreen> 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
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading