示例工程 31-notifications-taskbar

31-notifications-taskbar/app/README.md

markdown · 2.1 KB

# 31-notifications-taskbar / app

通知与任务栏工作台:发送系统通知(发送前脱敏)、模拟点击回跳、
Dock 徽标 / 任务栏进度 / 请求注意,并展示平台能力矩阵与事件记录。

## 运行

```bash
pnpm --filter @tutorial/31-notifications-taskbar-app start
pnpm --filter @tutorial/31-notifications-taskbar-app smoke
pnpm --filter @tutorial/31-notifications-taskbar-app shots
```

## smoke 输出

```json
{"evt":"smoke","ok":true,"dockBadge":"3","platform":"darwin",
 "supported":true,"previewTitle":"构建完成:/Users/<user>/project/app",
 "previewBody":"请联系 <email>,令牌 sk-***,或 Bearer ***",
 "hits":["用户路径","邮箱","API Key","Bearer Token"],"showLogged":true,
 "clicked":"构建完成:/Users/<user>/project/app","badge":"3",
 "progress":0.5,"bounceLogged":true,"cleared":true,"logAfterClear":0}
```

## 结构

- `shared/redact.ts`:邮箱/路径/token/查询参数脱敏,主进程与预览共用
- `shared/ipc.ts`:通知/进度/徽标类型与入参校验
- `main/index.ts`:Notification、click/action/close/failed、Dock 徽标、任务栏进度
- `preload/index.ts`:只暴露 `get/preview/send/simulateClick/setBadge/setProgress/bounce/clear`
- `src/App.ts`:编辑器、脱敏预览、通知卡片、Dock/任务栏预览、事件记录

## testid

| testid | 用途 |
| --- | --- |
| `notify-title` / `notify-body` | 通知输入 |
| `redacted-title` / `redacted-body` / `hits` | 脱敏预览 |
| `send` / `simulate-click` / `status` | 发送与点击 |
| `notification-preview` / `toast-title` / `toast-body-text` | 通知预览 |
| `last-clicked` | 最近点击 |
| `badge-input` / `badge-apply` / `badge-clear` | 徽标 |
| `progress-range` / `progress-mode` / `progress-apply` | 进度 |
| `dock-badge` / `dock-progress` | Dock 预览 |
| `capabilities` / `log` / `event-count` | 能力与事件 |

## 已知限制

- 截图只抓页面,原生通知横幅与 Dock 不在图内;页面展示同源预览。
- 开发态未签名的 macOS 应用可能无法送达通知,`failed` 事件会记录原因。
- 任务栏进度只在 Windows/Linux 原生生效;macOS 仅展示状态。