fix: ensure screen stays awake during file transfer by periodically calling wakeLockPlus.enable() (#2022)

This commit is contained in:
Anish Kargaonkar
2024-11-09 05:46:56 +05:30
committed by GitHub
parent 3b143fd56f
commit 17262cc19a
+10 -1
View File
@@ -54,6 +54,7 @@ class _ProgressPageState extends State<ProgressPage> with Refena {
// If [autoFinish] is enabled, we wait a few seconds before automatically closing the session.
int _finishCounter = 3;
Timer? _finishTimer;
Timer? _wakelockPlusTimer;
bool _advanced = false;
@@ -64,9 +65,16 @@ class _ProgressPageState extends State<ProgressPage> with Refena {
// init
WidgetsBinding.instance.addPostFrameCallback((_) {
try {
WakelockPlus.enable(); // ignore: discarded_futures
unawaited(WakelockPlus.enable());
} catch (_) {}
// Periodically call WakelockPlus.enable() to keep the screen awake
_wakelockPlusTimer = Timer.periodic(const Duration(seconds: 30), (timer) {
try {
unawaited(WakelockPlus.enable());
} catch (_) {}
});
if (ref.read(settingsProvider).autoFinish) {
_finishTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
final finished = ref.read(serverProvider)?.session?.files.values.map((e) => e.status).isFinishedOrSkipped ??
@@ -148,6 +156,7 @@ class _ProgressPageState extends State<ProgressPage> with Refena {
void dispose() {
super.dispose();
_finishTimer?.cancel();
_wakelockPlusTimer?.cancel();
TaskbarHelper.clearProgressBar(); // ignore: discarded_futures
try {
WakelockPlus.disable(); // ignore: discarded_futures