marinara icon indicating copy to clipboard operation
marinara copied to clipboard

resume timer after the computer wake up from sleep mode

Open cytim opened this issue 2 years ago • 0 comments

Background

(Attempt to fix #296 and the related issues.)

When the computer sleeps, the timer's tickInterval and expireTimeout will be paused by the system. When the system wakes up, the timer is resumed without acknowledging the paused period. This appears to the users that the timer is frozen.

Todo

  • [x] Replace ticketInterval and expireTimeout with a single countdownInterval.
  • [x] countdownInterval runs every second to compare checkpointStartAt to track the time - the timer can tick/expire correctly as soon as the script resumes from sleep mode.
  • [ ] Fix the test cases.
  • [ ] Fix the out-synced timer sound.

Experiment

09:17:58.789 Timer.js:74 started
09:17:58.790 Timer.js:157 countdown
09:17:58.790 Timer.js:158 expireAt 2021-09-12T09:27:58.789Z
09:17:58.790 Timer.js:159 nextTickAt 2021-09-12T09:18:58.789Z
09:18:58.796 Timer.js:170 tick 1
09:18:58.800 Timer.js:173 nextTickAt 2021-09-12T09:19:58.785Z
09:19:58.795 Timer.js:170 tick 2
09:19:58.798 Timer.js:173 nextTickAt 2021-09-12T09:20:58.786Z
09:20:58.799 Timer.js:170 tick 3
09:20:58.804 Timer.js:173 nextTickAt 2021-09-12T09:21:58.784Z
09:26:06.911 Timer.js:170 tick 4
09:26:07.307 Timer.js:173 nextTickAt 2021-09-12T09:26:58.393Z
09:26:59.099 Timer.js:170 tick 5
09:26:59.102 Timer.js:173 nextTickAt 2021-09-12T09:27:58.786Z
09:27:59.101 Timer.js:167 expire 6

The computer slept after tick 3 at around 09:20:58. When the computer resumed at around 09:26:06, tick 4 happened immediately and updated nextTickAt to the correct time. Finally, the timer expired at 09:27:59 as expected.

cytim avatar Sep 12 '21 10:09 cytim