Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resume timer after the computer wake up from sleep mode #400

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cytim
Copy link

@cytim cytim commented Sep 12, 2021

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

  • Replace ticketInterval and expireTimeout with a single countdownInterval.
  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timer doesn't work when mac goes into sleep mode (Worked fine previously)
1 participant