Skip to content

Timing

Timing 是一款 Mac 自动时间追踪应用。Protocol Launcher 允许你生成 Timing 的官方 URL scheme 链接。

使用

有两种方式可以使用此库:

  • 按需从子路径导入,支持 Tree Shaking 并保持包体积较小。
  • 从根包完整导入更适合快速脚本或示例,但会包含全部应用模块。

生产构建建议使用按需导入;快速演示可以使用完整导入。

选择安装方式

按需加载
推荐使用。生产环境优化。
全量导入
使用便捷。适合快速脚本。

说明

Timing 官方 URL scheme 页面说明,这些 URL 至少需要 Timing Expert。页面也区分了目标应用:tracker app actions 使用 timing2helper://,主 Timing app 使用 timing2://

本模块只暴露官方记录的 URL 形式:startTimerstopTimercreateTimeEntryeditTimeEntry/<time-entry-id>selectProjects/<project-name-or-id>

URL 方法

启动计时器

生成官方记录的 URL,在 Timing tracker app 中启动一个计时器。将 startImmediately 设为 false 时,Timing 会先显示对话框。

On-Demand
ts
import { startTimer } from 'protocol-launcher/timing'

const url = startTimer({
  title: 'Some title',
  notes: 'Some\nnotes',
  project: 'Work',
  estimatedDuration: 600,
  startDate: '2022-04-01T12:00:00Z',
  startImmediately: false,
  center: true,
})

停止计时器

生成官方记录的 URL,用来停止当前正在运行的计时器(如果存在)。hideNotification 会隐藏计时器停止后的通知。

On-Demand
ts
import { stopTimer } from 'protocol-launcher/timing'

const url = stopTimer({
  hideNotification: true,
})

创建 Time Entry

生成官方记录的 URL,在 Timing tracker app 中创建新的 time entry。

On-Demand
ts
import { createTimeEntry } from 'protocol-launcher/timing'

const url = createTimeEntry({
  title: 'Some title',
  notes: 'Some\nnotes',
  project: 'Work',
  startDate: '2022-04-01T12:00:00Z',
  endDate: '2022-04-01T12:30:00Z',
  createImmediately: false,
  center: true,
})

Timing 文档说明,只有在至少提供 startDateendDate 且提供 titleproject 之一时,createImmediately 才可用。centerobtainFocus 只在 createImmediately 不为 true 时可用。

编辑 Time Entry

生成官方记录的 URL,通过 ID 打开编辑 time entry 的对话框。Timing 也记录了可以使用 latest 编辑最近的 time entry。

On-Demand
ts
import { editTimeEntry } from 'protocol-launcher/timing'

const url = editTimeEntry({
  id: 'latest',
})

选择项目

生成官方记录的 URL,在主 Timing app 侧边栏中选择项目。省略 projects 时会选择 “All Activities”。

On-Demand
ts
import { selectProjects } from 'protocol-launcher/timing'

const url = selectProjects({
  projects: ['ProjectA', 'ProjectB'],
})
On-Demand
ts
import { selectProjects } from 'protocol-launcher/timing'

const url = selectProjects()

生成的 URL

ts
startTimer({
  title: 'Some title',
  notes: 'Some\nnotes',
  project: 'Work',
  estimatedDuration: 600,
  startDate: '2022-04-01T12:00:00Z',
  startImmediately: false,
  center: true,
})
// => 'timing2helper://startTimer?title=Some%20title&notes=Some%0Anotes&project=Work&estimatedDuration=600&startDate=2022-04-01T12:00:00Z&startImmediately=false&center=true'

stopTimer({ hideNotification: true })
// => 'timing2helper://stopTimer?hideNotification=true'

createTimeEntry({
  title: 'Some title',
  notes: 'Some\nnotes',
  project: 'Work',
  startDate: '2022-04-01T12:00:00Z',
  endDate: '2022-04-01T12:30:00Z',
  createImmediately: false,
  center: true,
})
// => 'timing2helper://createTimeEntry?title=Some%20title&notes=Some%0Anotes&project=Work&startDate=2022-04-01T12:00:00Z&endDate=2022-04-01T12:30:00Z&createImmediately=false&center=true'

editTimeEntry({ id: 'latest' })
// => 'timing2helper://editTimeEntry/latest'

selectProjects({ projects: ['ProjectA', 'ProjectB'] })
// => 'timing2://selectProjects/ProjectA/ProjectB'

selectProjects()
// => 'timing2://selectProjects'

官方文档