From c2320c845e8f661b00d4454e0a873ececa6971bd Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Wed, 27 Jul 2022 20:03:42 -0400 Subject: [PATCH 1/3] Add `wakelock` package (#157) --- pubspec.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 3bd686cb..ecf855a2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,7 +29,7 @@ environment: dependencies: flutter: sdk: flutter - json_annotation: ^4.5.0 + json_annotation: ^4.6.0 # The following adds the Cupertino Icons font to your application. @@ -55,6 +55,7 @@ dependencies: flutter_cache_manager: ^3.3.0 device_info_plus: ^4.0.0 floating: ^1.1.0 + wakelock: ^0.6.2 dev_dependencies: flutter_test: From 0028c960992d3f0a286c5203427dc3eaa6413a3f Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Wed, 27 Jul 2022 20:04:02 -0400 Subject: [PATCH 2/3] 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(); } } From 8984efa4ed465145de16227cc6e8d3cc8651f07c Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Wed, 27 Jul 2022 21:03:28 -0400 Subject: [PATCH 3/3] Add option to prevent chat sleep (#157) --- lib/screens/channel/stores/chat_store.dart | 2 +- .../settings/sections/chat_settings.dart | 22 ++++--- .../settings/stores/settings_store.dart | 18 ++++-- .../settings/stores/settings_store.g.dart | 58 +++++++++++++------ 4 files changed, 66 insertions(+), 34 deletions(-) diff --git a/lib/screens/channel/stores/chat_store.dart b/lib/screens/channel/stores/chat_store.dart index 2d45a287..80f4a961 100644 --- a/lib/screens/channel/stores/chat_store.dart +++ b/lib/screens/channel/stores/chat_store.dart @@ -118,7 +118,7 @@ abstract class ChatStoreBase with Store { required this.displayName, }) { // Enable wakelock to prevent the chat from sleeping. - Wakelock.enable(); + if (settings.chatOnlyPreventSleep) 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. diff --git a/lib/screens/settings/sections/chat_settings.dart b/lib/screens/settings/sections/chat_settings.dart index 9827a778..e9f7bcc3 100644 --- a/lib/screens/settings/sections/chat_settings.dart +++ b/lib/screens/settings/sections/chat_settings.dart @@ -40,14 +40,6 @@ class _ChatSettingsState extends State { ), ), children: [ - SwitchListTile.adaptive( - isThreeLine: true, - title: const Text('Autocomplete'), - subtitle: const Text('Shows a bar that suggests matching emotes and mentions while typing.'), - value: settingsStore.autocomplete, - onChanged: settingsStore.showBottomBar ? (newValue) => settingsStore.autocomplete = newValue : null, - ), - const SizedBox(height: 15.0), ListTile( title: Row( children: [ @@ -71,6 +63,20 @@ class _ChatSettingsState extends State { ], ), ), + SwitchListTile.adaptive( + isThreeLine: true, + title: const Text('Prevent sleep in chat-only mode'), + subtitle: const Text('Requires restarting the chat in order to take effect.'), + value: settingsStore.chatOnlyPreventSleep, + onChanged: !settingsStore.showVideo ? (newValue) => settingsStore.chatOnlyPreventSleep = newValue : null, + ), + SwitchListTile.adaptive( + isThreeLine: true, + title: const Text('Autocomplete'), + subtitle: const Text('Shows a bar that suggests matching emotes and mentions while typing.'), + value: settingsStore.autocomplete, + onChanged: settingsStore.showBottomBar ? (newValue) => settingsStore.autocomplete = newValue : null, + ), const SectionHeader( 'Layout', padding: sectionPadding, diff --git a/lib/screens/settings/stores/settings_store.dart b/lib/screens/settings/stores/settings_store.dart index c31d58cc..7a0cb183 100644 --- a/lib/screens/settings/stores/settings_store.dart +++ b/lib/screens/settings/stores/settings_store.dart @@ -85,8 +85,9 @@ abstract class _SettingsStoreBase with Store { } // * Chat Settings - static const defaultAutocomplete = true; static const defaultChatDelay = 0.0; + static const defaultChatOnlyPreventSleep = true; + static const defaultAutocomplete = true; static const defaultShowBottomBar = true; static const defaultLandscapeChatLeftSide = false; @@ -106,14 +107,18 @@ abstract class _SettingsStoreBase with Store { static const defaultMessageSpacing = 10.0; static const defaultFontSize = 12.0; - @JsonKey(defaultValue: defaultAutocomplete) - @observable - var autocomplete = defaultAutocomplete; - @JsonKey(defaultValue: defaultChatDelay) @observable var chatDelay = defaultChatDelay; + @JsonKey(defaultValue: defaultChatOnlyPreventSleep) + @observable + var chatOnlyPreventSleep = defaultChatOnlyPreventSleep; + + @JsonKey(defaultValue: defaultAutocomplete) + @observable + var autocomplete = defaultAutocomplete; + @JsonKey(defaultValue: defaultShowBottomBar) @observable var showBottomBar = defaultShowBottomBar; @@ -172,8 +177,9 @@ abstract class _SettingsStoreBase with Store { @action void resetChatSettings() { - autocomplete = defaultAutocomplete; chatDelay = defaultChatDelay; + chatOnlyPreventSleep = defaultChatOnlyPreventSleep; + autocomplete = defaultAutocomplete; showBottomBar = defaultShowBottomBar; landscapeChatLeftSide = defaultLandscapeChatLeftSide; chatWidth = defaultChatWidth; diff --git a/lib/screens/settings/stores/settings_store.g.dart b/lib/screens/settings/stores/settings_store.g.dart index 54e4b839..40304e30 100644 --- a/lib/screens/settings/stores/settings_store.g.dart +++ b/lib/screens/settings/stores/settings_store.g.dart @@ -20,8 +20,9 @@ SettingsStore _$SettingsStoreFromJson(Map json) => ..toggleableOverlay = json['toggleableOverlay'] as bool? ?? false ..pictureInPicture = json['pictureInPicture'] as bool? ?? false ..overlayOpacity = (json['overlayOpacity'] as num?)?.toDouble() ?? 0.5 - ..autocomplete = json['autocomplete'] as bool? ?? true ..chatDelay = (json['chatDelay'] as num?)?.toDouble() ?? 0.0 + ..chatOnlyPreventSleep = json['chatOnlyPreventSleep'] as bool? ?? true + ..autocomplete = json['autocomplete'] as bool? ?? true ..showBottomBar = json['showBottomBar'] as bool? ?? true ..landscapeChatLeftSide = json['landscapeChatLeftSide'] as bool? ?? false ..chatWidth = (json['chatWidth'] as num?)?.toDouble() ?? 0.3 @@ -58,8 +59,9 @@ Map _$SettingsStoreToJson(SettingsStore instance) => 'toggleableOverlay': instance.toggleableOverlay, 'pictureInPicture': instance.pictureInPicture, 'overlayOpacity': instance.overlayOpacity, - 'autocomplete': instance.autocomplete, 'chatDelay': instance.chatDelay, + 'chatOnlyPreventSleep': instance.chatOnlyPreventSleep, + 'autocomplete': instance.autocomplete, 'showBottomBar': instance.showBottomBar, 'landscapeChatLeftSide': instance.landscapeChatLeftSide, 'chatWidth': instance.chatWidth, @@ -260,22 +262,6 @@ mixin _$SettingsStore on _SettingsStoreBase, Store { }); } - late final _$autocompleteAtom = - Atom(name: '_SettingsStoreBase.autocomplete', context: context); - - @override - bool get autocomplete { - _$autocompleteAtom.reportRead(); - return super.autocomplete; - } - - @override - set autocomplete(bool value) { - _$autocompleteAtom.reportWrite(value, super.autocomplete, () { - super.autocomplete = value; - }); - } - late final _$chatDelayAtom = Atom(name: '_SettingsStoreBase.chatDelay', context: context); @@ -292,6 +278,39 @@ mixin _$SettingsStore on _SettingsStoreBase, Store { }); } + late final _$chatOnlyPreventSleepAtom = + Atom(name: '_SettingsStoreBase.chatOnlyPreventSleep', context: context); + + @override + bool get chatOnlyPreventSleep { + _$chatOnlyPreventSleepAtom.reportRead(); + return super.chatOnlyPreventSleep; + } + + @override + set chatOnlyPreventSleep(bool value) { + _$chatOnlyPreventSleepAtom.reportWrite(value, super.chatOnlyPreventSleep, + () { + super.chatOnlyPreventSleep = value; + }); + } + + late final _$autocompleteAtom = + Atom(name: '_SettingsStoreBase.autocomplete', context: context); + + @override + bool get autocomplete { + _$autocompleteAtom.reportRead(); + return super.autocomplete; + } + + @override + set autocomplete(bool value) { + _$autocompleteAtom.reportWrite(value, super.autocomplete, () { + super.autocomplete = value; + }); + } + late final _$showBottomBarAtom = Atom(name: '_SettingsStoreBase.showBottomBar', context: context); @@ -667,8 +686,9 @@ showOverlay: ${showOverlay}, toggleableOverlay: ${toggleableOverlay}, pictureInPicture: ${pictureInPicture}, overlayOpacity: ${overlayOpacity}, -autocomplete: ${autocomplete}, chatDelay: ${chatDelay}, +chatOnlyPreventSleep: ${chatOnlyPreventSleep}, +autocomplete: ${autocomplete}, showBottomBar: ${showBottomBar}, landscapeChatLeftSide: ${landscapeChatLeftSide}, chatWidth: ${chatWidth},