Skip to content

Focus

Focus 是一款效率与番茄钟应用。Protocol Launcher 允许您生成深度链接以在 Focus 中添加和删除任务、启动计时器,以及暂停当前计时器。

使用方式

有两种使用此库的方式:

  • 按需导入(On-Demand):从子路径导入支持 tree-shaking,保持较小的打包体积。
  • 完整导入(Full Import):从根包导入更方便,但会包含所有应用模块。

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

选择安装方式

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

添加任务

On-Demand
ts
import { addTask } from 'protocol-launcher/focus'

const url = addTask({
  title: 'Read chapter 3',
})

添加带估算的任务

On-Demand
ts
import { addTask } from 'protocol-launcher/focus'

const url = addTask({
  title: 'Prepare Presentation',
  note: 'Referecene mail notes',
  sessionEstimate: 8,
  due: 'monday',
})

添加带分钟估算的任务

On-Demand
ts
import { addTask } from 'protocol-launcher/focus'

const url = addTask({
  title: 'Study documentation',
  note: 'make notes',
  minutesEstimate: 120,
  due: 'tomorrow',
})

删除任务

On-Demand
ts
import { deleteTask } from 'protocol-launcher/focus'

const url = deleteTask({
  id: 'B1127BC6-3CC3-4AC4-B561-3CD493D2EDD6',
})

Focus 也支持通过一个用 ? 分隔的 ids 字符串删除多个任务。

On-Demand
ts
import { deleteTask } from 'protocol-launcher/focus'

const url = deleteTask({
  ids: 'B1127BC6-3CC3-4AC4-B561-3CD493D2EDD6?U36SAM-3CD3-1BC4-B481-2CD590D2EDD2',
})

启动计时器

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

const url = startTimer()

启动指定时长的计时器

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

const url = startTimer({
  type: 'focus',
  duration: 40,
})

暂停计时器

On-Demand
ts
import { pauseTimer } from 'protocol-launcher/focus'

const url = pauseTimer()

x-callback-url

Focus 的每个命令都支持 x-successx-error 回调参数。添加任务成功时,Focus 会在 x-success 回调里返回新任务的 id

On-Demand
ts
import { addTask } from 'protocol-launcher/focus'

const url = addTask({
  title: 'Read chapter 3',
  xSuccess: 'shortcuts://x-callback-url/run-shortcut?name=Focus Added',
  xError: 'shortcuts://x-callback-url/run-shortcut?name=Focus Error',
})