Skip to content

feat: windows添加任务完成或者需要确认右下角弹窗提醒#1635

Open
funnytime75 wants to merge 11 commits intofarion1231:mainfrom
funnytime75:feat/claude-background-notifications
Open

feat: windows添加任务完成或者需要确认右下角弹窗提醒#1635
funnytime75 wants to merge 11 commits intofarion1231:mainfrom
funnytime75:feat/claude-background-notifications

Conversation

@funnytime75
Copy link
Copy Markdown
Contributor

背景

当前在使用 Claude Code 时,如果终端窗口处于后台,用户很容易错过以下关键状态:

  • Claude 需要人工确认
  • Claude 当前轮已经结束,等待用户返回终端查看结果

这类状态本身不是错误,但会明显影响后台执行时的可感知性与交互效率。

本次提交为 CC Switch 增加了一套 最小可用 的 Claude 后台通知能力:

  • 通过 Claude Code hooks 触发事件
  • 由 CC Switch 在本地接收事件
  • 在 Windows 平台使用系统 Toast 进行提醒

本次实现内容

  1. 新增 Claude 后台通知设置

在设置页新增了 Claude 后台通知相关配置项:

  • Claude 后台通知
  • 需要确认时提醒
  • 当前轮结束时提醒

并补充了以下交互约束:

  • 仅在 Windows 平台展示该功能设置
  • 仅在总开关开启时展示两个子开关及集成状态区
  • 非 Windows 平台仅显示说明文案,不展示交互项

  1. 新增本地通知接收与 Toast 展示能力

在 Tauri 侧新增 Claude 通知服务模块,负责:

  • 在本地监听 Claude hooks 上报的事件
  • 解析通知事件类型
  • 去重并按优先级处理重复/相邻事件
  • 在 Windows 平台调用系统通知能力展示 Toast

当前覆盖的事件包括:

  • permission_prompt
  • idle_prompt
  • stop

其中:

  • permission_prompt 对应“需要确认时提醒”
  • idle_prompt 和 stop 共同归入“当前轮结束时提醒”

  1. 新增 hooks 管理能力

本次实现支持由 CC Switch 直接管理用户级 Claude hooks:

  • 可应用 hooks 到 ~/.claude/settings.json
  • 可移除本功能写入的 hooks
  • 不覆盖用户已有的非托管 hooks
  • hook 脚本由 CC Switch 写入到本地配置目录并统一维护

这样可以避免要求用户手动编写复杂的 PowerShell 命令,同时尽量减少对项目仓库本身的侵入。


  1. 新增设置持久化与运行时同步

为通知功能新增了对应设置字段与默认值,并在设置保存后对运行态进行同步:

  • 总开关关闭时不再展示通知细项
  • 总开关开启时自动恢复原有细粒度偏好
  • 状态接口、前端类型与实际 UI 消费字段已做收敛,避免保留未使用接口或多余返回字段

  1. 补充用户文档与多语言文案

已补充:

  • 中文 / 英文 / 日文设置文案
  • 用户手册中关于 Claude 后台通知的说明

包括:

  • 功能用途
  • 一期支持的提醒范围
  • hooks 的写入位置
  • 本地监听端口变化后需要重新应用 hooks 的说明

设计取舍

为什么一期只支持 Windows

本次功能的一期范围仅覆盖 Windows,原因不是架构上排斥其他平台,而是当前仅具备 Windows
设备,无法对 Linux 和 Apple 平台进行实际验证。

为了避免提交“理论可用但未经验证”的跨平台实现,本次将范围收敛为:

  • 先交付已验证的平台
  • 后续在具备对应设备与测试条件后,再扩展其他平台支持

测试与验证

本次已完成的验证包括:

静态检查

  • pnpm typecheck
  • cargo check --manifest-path src-tauri/Cargo.toml

手动验证

  • 本地通知服务可正常接收事件并显示 Windows Toast
  • Claude 后台通知设置项可正常显示与保存
  • Windows / 非 Windows 的设置显示逻辑符合预期
  • hooks 应用与移除流程可用
  • 总开关与两个子开关的展示关系符合预期
  • win10及win11经过人工测试都已可用

影响范围

本次提交主要涉及以下部分:

  • 设置页 UI
  • 前端通知 API 封装
  • Tauri 命令与本地通知服务
  • 应用设置持久化
  • 用户文档与多语言文案

本次 PR 已尽量控制提交范围,未包含与 Claude 后台通知无关的格式化噪音或过程文档。


备注

当前实现目标是 最小可用、可验证、可合并。
后续如需继续完善,比较自然的方向包括:

  • 增加更多平台支持
  • 补充更细粒度的自动化测试
  • 进一步完善 hooks 状态展示与运行态可观测性

@farion1231
Copy link
Copy Markdown
Owner

@codex

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a1c126bb13

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/settings.rs
@farion1231
Copy link
Copy Markdown
Owner

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb3e5705e9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/commands/claude_notify.rs Outdated
Comment thread src-tauri/src/claude_notify/server.rs Outdated
@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@funnytime75
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0acb93d356

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/claude_notify/server.rs Outdated
Comment thread src-tauri/src/commands/settings.rs Outdated
@funnytime75
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 57d03e6692

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/commands/settings.rs
Comment thread src-tauri/src/commands/claude_notify.rs Outdated
@funnytime75
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a8f86e69bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/commands/claude_notify.rs
Comment thread src-tauri/src/commands/settings.rs Outdated
@funnytime75
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 44da65db3f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/commands/claude_notify.rs Outdated
Comment thread src/components/settings/ClaudeBackgroundNotificationSettings.tsx
@funnytime75
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9f2f5218fb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/commands/claude_notify.rs Outdated
Comment thread src-tauri/src/claude_notify/server.rs Outdated
@funnytime75
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f8473fad8f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/claude_notify/server.rs Outdated
@funnytime75
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1364480bc2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/claude_notify/dedupe.rs Outdated
@funnytime75
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Owner

@farion1231 farion1231 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢你的贡献。请请查看一下是否有以下问题:

P1 PR 当前会让测试目标编不过。AppState 新增了 claude_notify_service 字段,但测试 fixture 还在用旧结构体字面量初始化,见 store.rs (line 7)、support.rs (line 63)、support.rs (line 71)、deeplink_import.rs (line 22)、deeplink_import.rs (line 62)。我在 PR head 上跑 cargo test --manifest-path src-tauri/Cargo.toml claude_notify,直接报 E0063 missing field claude_notify_service in initializer of AppState。

P2 后端错误消息是中文硬编码,最终会直接透传到前端,英文/日文环境下会看到中文报错。见 server.rs (line 135)、server.rs (line 152)、server.rs (line 166)、commands/claude_notify.rs (line 391)。

P2 save_settings 的回滚逻辑会吞掉原始错误。如果运行时同步失败后回滚也失败,用户只能看到回滚失败,拿不到真正的根因。见 settings.rs (line 33)。

P3 Windows-only 边界还没完全收紧。通知插件、命令注册、ClaudeNotifyService 初始化、.ps1 hooks 生成逻辑目前都是全平台可编译/可调用,只是“自动启动”在 Windows 下才加了 cfg。见 Cargo.toml (line 38)、lib.rs (line 233)、lib.rs (line 890)、lib.rs (line 695)。
P3 apply_claude_notify_hook_config 的 _port 参数是死参数,前端传了但后端完全忽略,接口语义有误导性。见 commands/claude_notify.rs (line 376)。

@funnytime75
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@funnytime75
Copy link
Copy Markdown
Contributor Author

这轮主要是对当前已实现的 Claude 后台通知能力做补充收口,重点修了 5 个问题:

  1. 收敛通知链路中的硬编码中文错误
    - 将会直接透传前端的几处中文错误改为 AppError::localized(...)
    - 避免英文/日文环境直接看到纯中文后端报错
  2. 修复 save_settings 回滚吞错
    - 运行时同步失败后,如果回滚也失败,现会同时保留原始同步错误和回滚错误
    - 不再只剩“回滚失败”而丢失真正根因
  3. 继续收紧 Windows-only 边界
    - tauri-plugin-notification 改为 Windows 条件依赖
    - 通知插件注册改为仅 Windows 编译
    - 非 Windows 提供 ClaudeNotifyService / Claude notify commands 的 stub 实现
    - 使 .ps1、powershell.exe、真实 hooks 写入与监听逻辑不再进入非 Windows 编译路径
  4. 清理 apply_claude_notify_hook_config 的误导性死参数
    - 前端不再传 port
    - 后端由运行时状态自行决定实际端口
    - 使接口语义与真实行为一致
  5. 修复测试夹具中的旧 AppState 初始化
    - 测试改为统一使用 AppState::new(...)
    - 不再因为新增 claude_notify_service 字段而触发旧字面量初始化错误

已补充验证:

  • cargo check --manifest-path src-tauri/Cargo.toml
  • cargo test --manifest-path src-tauri/Cargo.toml --test deeplink_import
  • cargo test --manifest-path src-tauri/Cargo.toml --test support

补充说明:

  • 当前环境仅安装了 Windows target,因此本轮没有执行非 Windows target 的 cargo check --target ...
  • 但已静态确认 notification plugin、真实 service / command、.ps1 / powershell.exe 逻辑都已从非 Windows 编译路径中隔离出去

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants