Skip to content

Commit

Permalink
fix: ensure screen stays awake during file transfer by periodically c…
Browse files Browse the repository at this point in the history
…alling wakeLockPlus.enable() (localsend#2022)
  • Loading branch information
anishkargaonkar authored Nov 9, 2024
1 parent 3b143fd commit 17262cc
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/lib/pages/progress_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 ??
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 17262cc

Please sign in to comment.