Skip to content

Slice 1: 睡眠定时器 MVP 核心服务 + IPC + PlayerBar 按钮 + Popover(暂停 + 预设时长) #2

Description

@Znfooe

Parent

#1 feat: 睡眠定时器 (Sleep Timer)

What to build

睡眠定时器 MVP 核心功能:用户可以从 PlayerBar 播放栏启动一个倒计时,到期后自动暂停播放。

端到端路径(全栈贯通):

  1. 主进程 — SleepTimerService:新建一个深模块类,封装定时器全部业务逻辑:

    • start(durationMinutes, action, fadeOut) — 启动倒计时
    • cancel() — 取消并清理
    • getStatus() — 返回 { isActive, remainingMs, action, fadeOutEnabled }
    • onTick / onComplete / onChange — 事件回调
    • 内部使用 setInterval(1000) 驱动倒计时,到期时调用 AudioSession.pause()
    • 并发安全:重复 start 覆盖前一个
  2. 主进程 — IPC 注册:新建 sleepTimerIpc.ts,注册 4 个通道:

    • sleepTimer:start — invoke,参数 { durationMinutes, action: 'pause', fadeOut: false }
    • sleepTimer:cancel — invoke
    • sleepTimer:getStatus — invoke,返回状态对象
    • sleepTimer:onTick — 事件通道,每秒推送剩余毫秒数
    • 在 registerIpc.ts 中注册为 'sleepTimer' 步骤
  3. Preload Bridge:在 window.echo 下新增 sleepTimer 命名空间,暴露上述 4 个方法

  4. IPC 常量:在 src/shared/constants/ipcChannels.ts 中添加 4 个通道常量

  5. 渲染进程 — SleepTimerButton:PlayerTransport 组件中新增按钮:

    • 空闲态:显示月亮图标(lucide-react 的 Moon 或 Timer)
    • 运行态:显示 MM:SS 格式剩余时间
    • 点击打开/关闭 Popover
  6. 渲染进程 — SleepTimerPopover:弹出面板包含:

    • 标题"睡眠定时器"
    • 6 个预设时长按钮:5 / 10 / 15 / 30 / 45 / 60 分钟
    • 点击任一按钮立即启动定时器
    • 运行中显示当前剩余时间 + 取消按钮
  7. i18n:zh-CN 核心翻译 key(其他语言在 Slice 6 补全)

  8. PlayerTransport 集成:在 MV 按钮右侧插入 SleepTimerButton,传入必要 props 和回调

Acceptance criteria

  • 在 PlayerBar 播放栏能看到睡眠定时器按钮(月亮图标)
  • 点击按钮弹出 Popover,显示 6 个预设时长选项
  • 选择任意预设后开始倒计时,按钮变为显示剩余时间(如 "23:45")
  • 倒计时结束后音乐自动暂停
  • 运行中再次点击可取消定时器,恢复空闲状态
  • 重启应用后定时器不保留(不持久化)
  • 窗口最小化/隐藏到托盘时定时器仍正常运行(主进程驱动)

Blocked by

None - can start immediately

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentFully specified, AFK-ready an agent can pick it up with no human context

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions