From 0cff83fc38e30bcefc2be42baacab5c0a0fefd5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E7=BF=94=E5=AE=87?= Date: Thu, 30 Apr 2026 11:23:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20v0.2.0=20=E2=80=94=20sleep-aware=20time?= =?UTF-8?q?rs=20+=20auto-loop=20pomodoro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Core change: both timers stop lying when the Mac sleeps or the user walks away. Old code measured wallclock from a stored "start" timestamp, so 4 hours of lid-closed showed up as 4 hours of "sitting" and a 25-minute focus could quietly stretch across multiple hours because Timer.scheduledTimer pauses during sleep. What changed: - Sit timer now reads CGEventSource HID idle to count only seconds with real input activity. New Sources/engine/SystemIdle.swift iterates the user-input event types and takes the min. Idle ≥ 5 min resets the accumulator (counts as a real break). Tick-gap > 30 s flags a sleep/wake and clears too — covers the case where the user unlocks and idle resets to ~0 instantly. - Pomodoro switched from "decrement counter every second" to a wallclock end-time. Persisted to UserDefaults so quit/relaunch recovers correctly: still-running phases keep counting; phases whose end-time has already passed get caught up (one focus credited if missed) and the timer returns to idle. - Auto-loop with classic 4-pack rhythm: focus → short break → focus → … on the 4th focus a long break (default 15 min) replaces the short break, then the cycle resets. Default ON; toggle pill in the settings row turns it off when the user wants manual restarts. - New cycle-progress dot row (●●○○) next to the phase badge so the user can see where they are in the 4-pack at a glance. - SitView tip text rewritten to reflect the new semantics: "只统计 你真正在键盘前的时间。离开 5 分钟以上自动归零,午休/会议不会被 算进去。" User-facing wins: - Closing the lid for lunch no longer fakes 90 minutes of sitting. - A 25-min focus that survives a sleep cycle ends accurately. - Start a focus once, the rhythm runs all morning. --- Info.plist | 4 +- Sources/WorkerPlugin.swift | 2 +- Sources/engine/SystemIdle.swift | 36 ++++ Sources/engine/WorkerStore.swift | 351 ++++++++++++++++++++++++++----- Sources/ui/PomodoroView.swift | 79 ++++++- Sources/ui/SitView.swift | 3 +- 6 files changed, 410 insertions(+), 65 deletions(-) create mode 100644 Sources/engine/SystemIdle.swift diff --git a/Info.plist b/Info.plist index ec79107..aa32838 100644 --- a/Info.plist +++ b/Info.plist @@ -15,9 +15,9 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 0.1.0 + 0.2.0 CFBundleVersion - 1 + 2 NSPrincipalClass WorkerPlugin.WorkerPlugin