Merge pull request #161 from tommyxchow/157-chat-prevent-sleep
Add option to prevent sleep in chat-only mode
This commit is contained in:
commit
9aebbed1ae
5 changed files with 74 additions and 34 deletions
|
|
@ -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.
|
||||
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.
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,14 +40,6 @@ class _ChatSettingsState extends State<ChatSettings> {
|
|||
),
|
||||
),
|
||||
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<ChatSettings> {
|
|||
],
|
||||
),
|
||||
),
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -20,8 +20,9 @@ SettingsStore _$SettingsStoreFromJson(Map<String, dynamic> 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<String, dynamic> _$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},
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue