Skip to content

Feat/chat bubble#985

Open
xuebkgithub wants to merge 46 commits into
ayangweb:masterfrom
xuebkgithub:feat/ai-chat-bubble
Open

Feat/chat bubble#985
xuebkgithub wants to merge 46 commits into
ayangweb:masterfrom
xuebkgithub:feat/ai-chat-bubble

Conversation

@xuebkgithub

Copy link
Copy Markdown

feat: 猫咪对话气泡 + HTTP 推送接口

这个 PR 做了什么

给桌宠猫加了一个会说话的气泡:可以在猫旁边弹出一句话,自动测量大小、定位、计时淡出。文字内容既能由 App 内部触发(如模型加载完成时打招呼),也能由外部程序通过本地 HTTP 接口推送(curl 一行就能让猫说话)。

主要内容

模块 说明
气泡窗口 独立 chat 窗口,跟随主窗口移动/缩放;macOS 用 NSPanel 实现不抢焦点
气泡生命周期 文字横排自动换行、按内容测量尺寸、定位、定时淡出
HTTP 接口 本地 127.0.0.1:{端口} 监听(仅本机),tiny_http 实现,可选 Token 鉴权
GET /say 推一条气泡,可带一次性样式覆盖(颜色/字号/底色/时长),不改保存的设置
GET /config 持久默认值,写入磁盘并实时同步到设置页
设置页 → Chat 标签 气泡开关、默认时长/颜色/字号/底色透明度、HTTP 开关/端口/Token、内联 API 文档、调试测试区
多语言 新增文案覆盖 5 种语言(zh-CN / zh-TW / en-US / pt-BR / vi-VN)

怎么用(一眼上手)

# 让猫说一句话
curl "http://127.0.0.1:7800/say?text=hi"

# 临时改个样式(只对这一条生效)
curl "http://127.0.0.1:7800/say?text=hi&textColor=%23ff0000&fontSize=20&duration=5"

# 改默认值(持久保存,设置页同步)
curl "http://127.0.0.1:7800/config?bgColor=%23000000&bgOpacity=80"

设置页:设置 → Chat 开启「启用 HTTP 接口」即可(改端口/Token 后需重启)。手工测试脚本见 scripts/bubble-http.sh

保库(baoku) and others added 30 commits April 29, 2026 15:14
macOS 主窗口由 NSPanel 创建,CollectionBehavior 含 .stationary(),
导致面板被钉死在创建时所在屏幕,多显示器用户无法把猫咪带到当前工作的屏幕。

- 偏好设置「通用 → 应用设置」新增「跟随当前屏幕」开关,仅 macOS 显示,
  默认关闭,行为保持现状
- Rust 端新增 set_multi_screen_follow command,使用 AtomicBool 共享开关状态,
  show/hide 路径同步读取;开启时去掉 .stationary() 让 NSPanel 可跨 Space/屏幕
- 新增 useMultiScreenFollow composable,开关启用时 800ms 轮询
  cursorPosition + monitorFromPoint,按相对偏移把窗口平移到鼠标所在显示器
  并裁剪到边界
- Windows / Linux 端提供同名 no-op,保持 generate_handler! 跨平台符号一致
- 5 个 locale (en-US / zh-CN / zh-TW / pt-BR / vi-VN) 全量补齐文案

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
大屏 → 小屏切换时跨屏跟随会被裁剪到小屏边界,回到大屏后
之前用户手动设定的位置就会丢失。

- 新增 monitorOffsets Map,按屏幕 (x,y,w,h) 作为 key
- 每次轮询同步当前屏幕的最新偏移,捕获用户屏内拖动
- 跨屏移动时优先使用目标屏幕的历史偏移,无记录再用源屏偏移
- 关闭开关时清空 Map,避免状态残留

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Implement computeBubblePosition() function that calculates the bubble's
top-left corner in physical pixels, handling edge cases: horizontal
centering with screen boundaries, vertical placement (above cat by
default, below if no room), and multi-display support with negative
coordinates and high-DPI scaling.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collects IPC listener UnlistenFn in onMounted and calls them in onUnmounted
to prevent listener leaks. Also clears pending auto-hide timer and validates
hex color input in hexToRgba before parsing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… not a WebviewWindow method)

reposition() called main.currentMonitor(), but currentMonitor is a free
function in @tauri-apps/api/window, not a method on WebviewWindow/Window —
so every reposition threw TypeError and the bubble never positioned/showed.
Find the cat's monitor by physical-bounds containment via availableMonitors()
(same pattern as useWindowState). Also make App.vue's unhandledrejection
handler log Error name/message/stack instead of JSON.stringify→'{}'.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The bubble was a flex item; width:max-content does not stop flex-shrink, so
in the narrow chat window it collapsed to min-content (one CJK char per line)
and setSize locked that in. Switch to a measured block wrapper (w-max max-w-80
p-3): a block with width:max-content is window-independent, so short text stays
on one line and long text wraps only at the 320px cap. The wrapper's padding
(measured, unlike the old margin) reserves the box-shadow space.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ffff

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…o feat/ai-chat-bubble

# Conflicts:
#	src/pages/preference/components/general/index.vue
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.

1 participant