Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ iTimer 是一个 macOS 菜单栏计时器,用 SwiftUI 写,Swift Package 管
swift test # 核心逻辑测试
```

界面自测在 `Sources/ITimer/SelfTest.swift`。`goal`、`workflow`、`record`、`drawer` 几个场景支持 background 模式:不激活 App,事件直接发给窗口,不占用前台和鼠标。
界面自测在 `Sources/ITimer/SelfTest.swift`。`goal`、`workflow`、`record`、`drawer`、`update` 几个场景支持 background 模式:不激活 App,事件直接发给窗口,不占用前台和鼠标。

`update` 场景用环境变量 `ITIMER_UPDATE_FEED` 指向本地的 releases JSON(可以用 `file://`),会真的下载、校验并替换正在运行的应用包,所以只对复制出来的应用跑(例如 `open -n -g --env ITIMER_UPDATE_FEED=file:///tmp/feed/releases.json /tmp/copy/iTimer.app`)。`ITIMER_UPDATE_RELAUNCH_PROBE` 可以指定一个代替 iTimer 被重新打开的探针应用,避免新开的 iTimer 读到真实数据。
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@

## [未发布]

## [1.12.0] - 2026-10-19

### 新增

- 软件更新:启动时和之后每天检查一次 GitHub 上有没有新版本,只读取版本信息;可以在「设置 › 软件更新」里关掉自动检查。
- 可以随时在菜单栏「iTimer › 检查更新…」或「设置 › 软件更新」里手动检查更新。
- 有新版本时,菜单栏面板底部出现「新版本 x.y.z」按钮,主窗口图标栏的设置图标亮一个小圆点;设置里列出新版本的更新内容,落后几个版本时一起列出。
- 在设置里点「下载并安装」,下载这台 Mac 芯片对应的安装包,校验 SHA-256 后替换当前的 iTimer 并自动重新打开,正在计时的任务照常计时;下载中途可以取消。在 Apple 芯片上运行的 Intel 版会换成 Apple Silicon 版。
- iTimer 所在的位置没有写入权限时,改为打开下载好的安装包,把 iTimer 拖到「应用程序」即可。

## [1.11.0] - 2026-10-19

### 新增
Expand Down Expand Up @@ -211,7 +221,8 @@

- 在面板里暂停、完成任务时,面板不再塌掉或自己关上:面板开着时冻结菜单栏文字,并锁定面板高度。

[未发布]: https://github.com/DueGin/iTimer/compare/v1.11.0...HEAD
[未发布]: https://github.com/DueGin/iTimer/compare/v1.12.0...HEAD
[1.12.0]: https://github.com/DueGin/iTimer/compare/v1.11.0...v1.12.0
[1.11.0]: https://github.com/DueGin/iTimer/compare/v1.10.5...v1.11.0
[1.10.5]: https://github.com/DueGin/iTimer/compare/v1.10.4...v1.10.5
[1.10.4]: https://github.com/DueGin/iTimer/compare/v1.10.3...v1.10.4
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

当前安装包使用临时签名,尚未经过 Apple Developer ID 签名和公证。首次打开如被 macOS 拦截,请在「系统设置 › 隐私与安全性」中选择「仍要打开」。

装好之后,以后的版本可以直接在应用里更新:有新版本时,菜单栏面板底部会出现「新版本 x.y.z」按钮,在「设置 › 软件更新」里点「下载并安装」即可,详见下文「软件更新」。

## 定位

| | |
Expand Down Expand Up @@ -104,7 +106,9 @@

**提醒**:进入脑裂时发通知,建议用「只做这个」收拢线程;单个任务连续计时 3 小时会提醒你是不是忘了暂停;工作流里完成一步时,告诉你哪些下一步已经自动开始、哪些可以开始了。这几种提醒都能在设置里关掉。

**设置(⌘,)**:脑裂线、提醒开关、日历同步、登录时启动、打开数据文件所在位置。
**软件更新**:启动时和之后每天查一次 GitHub Releases 上有没有新版本,只读取版本信息,可以在设置里关掉;也可以在菜单栏「iTimer › 检查更新…」或设置里手动检查。有新版本时,菜单栏面板底部出现「新版本 x.y.z」按钮,主窗口图标栏的设置图标亮一个小圆点。设置里列出新版本的更新内容(落后几个版本时一起列出),点「下载并安装」,iTimer 会下载这台 Mac 芯片对应的安装包,按 Release 附带的 SHA-256 校验,替换当前的 iTimer 并自动重新打开,正在计时的任务照常计时。如果 iTimer 所在的位置没有写入权限,会改为打开下载好的安装包,拖到「应用程序」即可。

**设置(⌘,)**:脑裂线、提醒开关、日历同步、登录时启动、打开数据文件所在位置、软件更新。

## 设计原则

Expand Down Expand Up @@ -138,6 +142,8 @@ git push origin v1.8.3

[发版流水线](.github/workflows/release.yml) 会检查 tag 与应用版本号是否一致,以及 CHANGELOG 是否有对应版本的更新内容;在 Apple Silicon 和 Intel runner 上分别运行核心测试、构建应用并打包。两边都成功后,自动创建 GitHub Release,上传两个 DMG 和 `SHA256SUMS`,更新说明取自该版本的 CHANGELOG。

应用内更新按 `iTimer-x.y.z-macos-<架构>.dmg` 这个文件名找安装包,用附件的 SHA-256(或 `SHA256SUMS`)校验,更新说明同样取自 Release 正文,所以不要手动改附件名或删掉 `SHA256SUMS`。

流水线使用 GitHub 自带的 `GITHUB_TOKEN`,发布 job 有 `contents: write` 权限,无需配置额外 Secret。上传附件时先创建草稿,全部上传成功再公开;失败后可在 Actions 中重新运行,继续上传草稿中的附件。已公开的 Release 不会被覆盖。

如果 tag 推送后没有出现运行记录,可在 Actions ›「构建与发布 iTimer」› Run workflow 中选择 `main`,填入已有的版本 tag(如 `v1.8.2`)。手动运行会检出该 tag 的代码,并执行相同的版本检查、双架构构建和发布流程。
Expand Down
6 changes: 6 additions & 0 deletions Sources/ITimer/ITimerApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ struct ITimerApp: App {
.windowResizability(.contentMinSize)
.windowToolbarStyle(.unifiedCompact)
.commands {
CommandGroup(after: .appInfo) {
UpdateCommands()
}
CommandGroup(replacing: .newItem) {
NewItemCommands(store: .shared)
}
Expand Down Expand Up @@ -54,6 +57,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
CalendarManager.shared.attach(to: TaskStore.shared)
startClock()
SelfTest.runIfRequested()
if DebugLaunchFile.current == nil {
Updater.shared.startAutomaticChecks()
}
}
startNudges()
}
Expand Down
10 changes: 9 additions & 1 deletion Sources/ITimer/MainRail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ struct MainRail: View {
Spacer(minLength: 12)
SettingsLink {
icon("gearshape", selected: false)
.overlay(alignment: .topTrailing) {
if Updater.shared.offer != nil {
Circle()
.fill(Color.accentColor)
.frame(width: 7, height: 7)
.offset(x: -5, y: 5)
}
}
}
.buttonStyle(railStyle(selected: false))
.help("设置(⌘,)")
.help(Updater.shared.offer.map { "设置(⌘,)· 新版本 \($0.version.description) 可以更新了" } ?? "设置(⌘,)")
.accessibilityLabel("设置")
.accessibilityIdentifier("rail-settings")
}
Expand Down
11 changes: 11 additions & 0 deletions Sources/ITimer/MenuBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,17 @@ struct MenuBarView: View {
NSApp.activate(ignoringOtherApps: true)
openSettings()
}
if let offer = Updater.shared.offer {
Button {
NSApp.activate(ignoringOtherApps: true)
openSettings()
} label: {
Label("新版本 \(offer.version.description)", systemImage: "arrow.down.circle.fill")
}
.buttonStyle(PillButtonStyle(tint: .accentColor))
.help("iTimer \(offer.version.description) 可以更新了,在设置里查看更新内容并安装")
.accessibilityIdentifier("update-badge")
}
Spacer()
footerButton("退出", systemImage: "power", id: "quit-app") { NSApp.terminate(nil) }
}
Expand Down
107 changes: 107 additions & 0 deletions Sources/ITimer/SelfTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum SelfTest {
case "milestone": passed = await exerciseMilestoneExpansion()
case "record": passed = await exerciseRecordTimes()
case "drawer": passed = await exerciseDrawer()
case "update": passed = await exerciseUpdate()
default: passed = await exercise()
}
note(passed ? "PASS" : "FAIL")
Expand Down Expand Up @@ -725,6 +726,112 @@ enum SelfTest {
}
}

// MARK: - Software update

extension SelfTest {
/// 设置 › 软件更新 against a local feed (`ITIMER_UPDATE_FEED`): finds the
/// newer release, shows it in 设置 and the panel footer, then downloads,
/// checks and swaps this very bundle. `ITIMER_UPDATE_RELAUNCH_PROBE`
/// names an app for the relaunch helper to open once this process exits
/// (not iTimer itself, which would open on the real data).
/// Window events only, so it also runs in background mode.
static func exerciseUpdate() async -> Bool {
let updater = Updater.shared
guard updater.feedOverridden else {
note("ITIMER_UPDATE_FEED is not set")
return false
}
// The app's defaults are the user's; put the check time back after.
let defaults = UserDefaults.standard
let savedChecked = defaults.object(forKey: Preferences.updateLastChecked)
defer { defaults.set(savedChecked, forKey: Preferences.updateLastChecked) }

func present(_ identifier: String) -> Bool { find(identifier: identifier, depth: 40) != nil }
func press(_ identifier: String) -> Bool {
guard let element = find(identifier: identifier, depth: 40) else {
note("missing \(identifier)")
return false
}
return AXUIElementPerformAction(element, kAXPressAction as CFString) == .success
}

let settings = NSWindow(contentRect: NSRect(x: 120, y: 80, width: 460, height: 760), styleMask: [.titled], backing: .buffered, defer: false)
settings.title = "iTimer 软件更新自检"
settings.isReleasedWhenClosed = false
settings.appearance = NSAppearance(named: .aqua)
settings.contentView = NSHostingView(rootView: SettingsView(store: .shared))
await activateUnlessBackground()
bringForward(settings)
defer { settings.orderOut(nil) }
try? await Task.sleep(for: .milliseconds(600))

guard press("update-check"),
await wait(for: 10, label: "check", until: { updater.offer != nil || updater.outcome != nil }),
let offer = updater.offer else {
note("check found no update: \(String(describing: updater.outcome)) current=\(updater.currentVersion)")
return false
}
try? await Task.sleep(for: .milliseconds(300))
guard present("update-offer"), present("update-notes"), present("update-install") else {
note("设置 does not show the offer, its notes and the install button")
return false
}
snapshot(settings, to: "/tmp/itimer-update-settings.png")
settings.appearance = NSAppearance(named: .darkAqua)
try? await Task.sleep(for: .milliseconds(150))
snapshot(settings, to: "/tmp/itimer-update-settings-dark.png")
settings.appearance = NSAppearance(named: .aqua)
note("check offered \(offer.version) (\(offer.installer.name)), notes for \(offer.notes.map(\.version.description))")

let panel = NSWindow(contentRect: NSRect(x: 600, y: 80, width: 380, height: 640), styleMask: [.titled], backing: .buffered, defer: false)
panel.title = "iTimer 面板更新自检"
panel.isReleasedWhenClosed = false
panel.appearance = NSAppearance(named: .aqua)
panel.contentView = NSHostingView(rootView: MenuBarView(store: .shared).background(.regularMaterial))
bringForward(panel)
try? await Task.sleep(for: .milliseconds(600))
guard present("update-badge") else {
panel.orderOut(nil)
note("the panel footer does not point at the update")
return false
}
snapshot(panel, to: "/tmp/itimer-update-panel.png")
panel.orderOut(nil)
note("panel footer shows the new version")

// Swap the bundle but stay running; the relaunch is checked below.
updater.finishInstall = { _ in }
guard press("update-install"),
await wait(for: 60, label: "install", until: { updater.outcome != nil && !updater.isBusy }) else {
return false
}
guard updater.outcome == .installed(offer.version) else {
note("install ended with \(String(describing: updater.outcome))")
return false
}
try? await Task.sleep(for: .milliseconds(300))
snapshot(settings, to: "/tmp/itimer-update-installed.png")
let info = NSDictionary(contentsOf: Bundle.main.bundleURL.appendingPathComponent("Contents/Info.plist"))
let installed = info?["CFBundleShortVersionString"] as? String
guard installed == offer.version.description else {
note("bundle on disk is \(installed ?? "unreadable"), expected \(offer.version)")
return false
}
note("downloaded, checked and swapped \(Bundle.main.bundleURL.path) to \(installed ?? "")")

if let probe = ProcessInfo.processInfo.environment["ITIMER_UPDATE_RELAUNCH_PROBE"] {
do {
try Updater.spawnRelaunch(of: URL(fileURLWithPath: probe))
} catch {
note("relaunch helper did not start: \(error)")
return false
}
note("relaunch helper waits to open \(probe)")
}
return true
}
}

// MARK: - Side drawer

extension SelfTest {
Expand Down
4 changes: 4 additions & 0 deletions Sources/ITimer/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ enum Preferences {
static let brainSplitNudge = "itimer.nudge.brainSplit"
static let longRunNudge = "itimer.nudge.longRun"
static let workflowNudge = "itimer.nudge.workflow"
static let autoUpdateCheck = "itimer.update.auto"
static let updateLastChecked = "itimer.update.lastChecked"

static func enabled(_ key: String) -> Bool {
UserDefaults.standard.object(forKey: key) as? Bool ?? true
Expand Down Expand Up @@ -76,6 +78,8 @@ struct SettingsView: View {
.buttonStyle(PillButtonStyle(tint: .accentColor))
}
}

UpdateSection(updater: .shared)
}
.formStyle(.grouped)
.frame(width: 460)
Expand Down
Loading
Loading