From 0028c960992d3f0a286c5203427dc3eaa6413a3f Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Wed, 27 Jul 2022 20:04:02 -0400 Subject: [PATCH] Prevent sleep in chat only mode (#157) --- lib/screens/channel/stores/chat_store.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/screens/channel/stores/chat_store.dart b/lib/screens/channel/stores/chat_store.dart index adfcf2eb..2d45a287 100644 --- a/lib/screens/channel/stores/chat_store.dart +++ b/lib/screens/channel/stores/chat_store.dart @@ -10,6 +10,7 @@ import 'package:frosty/screens/channel/stores/chat_assets_store.dart'; import 'package:frosty/screens/channel/stores/chat_details_store.dart'; import 'package:frosty/screens/settings/stores/settings_store.dart'; import 'package:mobx/mobx.dart'; +import 'package:wakelock/wakelock.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; part 'chat_store.g.dart'; @@ -116,6 +117,9 @@ abstract class ChatStoreBase with Store { required this.channelId, required this.displayName, }) { + // Enable wakelock to prevent the chat from sleeping. + Wakelock.enable(); + // Create a reaction that will reconnect to chat when logging in or out. // Closing the channel will trigger a reconnect with the new credentials. reactions.add(reaction( @@ -425,5 +429,8 @@ abstract class ChatStoreBase with Store { assetsStore.dispose(); chatDetailsStore.dispose(); + + // Disable wakelock so that the sleep timer will function properly. + Wakelock.disable(); } }