Skip to content

"Keep Screen On" Feature Not Working When Pre-meditation Delay is Disabled #20

@Peter5Chiou

Description

@Peter5Chiou

Bug Report: "Keep Screen On" Feature Not Working When Pre-meditation Delay is Disabled

Environment

  • App Version: 1.5.0+17
  • Platform: Android
  • Flutter Version: 3.5.3+
  • Device: Redmi Note 10 Pro

Bug Description

The "Keep Screen On" setting does not work when the "Pre-meditation delay" option is disabled. The screen turns off after approximately 2 minutes of meditation, even when the "Keep Screen On" checkbox is enabled in settings.

Steps to Reproduce

  1. Open the app settings
  2. Enable "Keep Screen On" option
  3. Ensure "Pre-meditation delay" is disabled (unchecked)
  4. Start a meditation timer (any duration > 2 minutes)
  5. Wait for about 2 minutes
  6. Expected: Screen stays on throughout the meditation
  7. Actual: Screen turns off after ~2 minutes

Root Cause Analysis

The issue is in the onMeditationStart() function in lib/timer.dart (lines 395-408).

Current problematic logic:

bool wakelockEnabled = await WakelockPlus.enabled;
if (Settings.getValue<bool>('screen-wakelock') == true) {
  if (wakelockEnabled) {
    // wakelock was already setup in onTimerStart
    log.i('maintaining screen wakelock for meditation');
  } else {
    log.e('wakelock is not enabled but was supposed to be'); // ❌ Only logs error, doesn't enable wakelock
  }
}

The problem:

  • When "Pre-meditation delay" is disabled, the app skips onTimerStart() and goes directly to onMeditationStart()
  • In onTimerStart(), wakelock is only enabled for the delay phase (line 364): WakelockPlus.enable();
  • When there's no delay, wakelock is never enabled, so wakelockEnabled remains false
  • The current code only logs an error but doesn't actually enable the wakelock

When it works correctly:

  • If "Pre-meditation delay" is enabled, wakelock gets enabled in onTimerStart() during the delay phase
  • Then onMeditationStart() finds wakelock already enabled and maintains it

Proposed Fix

Replace the error logging with actual wakelock enablement:

bool wakelockEnabled = await WakelockPlus.enabled;
if (Settings.getValue<bool>('screen-wakelock') == true) {
  if (wakelockEnabled) {
    // wakelock was already setup in onTimerStart
    log.i('maintaining screen wakelock for meditation');
  } else {
    // enable wakelock if user has enabled "Keep Screen On" but wakelock isn't active
    log.i('enabling screen wakelock for meditation');
    WakelockPlus.enable(); // ✅ Actually enable wakelock
  }
} else {
  if (wakelockEnabled) {
    log.i('disabling screen wakelock for meditation');
    WakelockPlus.disable();
  }
}

Impact

  • Severity: Medium - Core functionality doesn't work in common usage scenario
  • Users Affected: All users who enable "Keep Screen On" but don't use "Pre-meditation delay"
  • Workaround: Enable "Pre-meditation delay" as a temporary workaround

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions