Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions docs/research/macos-fullscreen-status-menu-2026-11-14.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# macOS 全屏应用中菜单栏下拉菜单不可见

排查日期:2026-11-14;修复与验收:2026-11-15。

## 结论

用户确认普通桌面能打开菜单,全屏应用中只能看到菜单栏按钮高亮。2026-11-15 通过 `sw_vers` 核对,本机实际是 **macOS 27.2.1(26B131)**;上一轮将系统行为归因到 macOS 26 不准确。正在运行的安装版为 ThinkWatch Lite 2026.11.10。

证据指向 macOS 27 的原生菜单与全屏 Space、应用 activation policy 的兼容问题。Lite 主窗口打开后使用 Regular 模式;菜单可以开始跟踪,但其显示窗口未进入其他应用的全屏空间。主窗口关闭后切回 Accessory,在本机测试中能绕过问题。

## 选择与验证

| 方案 | 本机结果 |
| --- | --- |
| 修改菜单窗口及显示子窗口的空间属性 | 不稳定,未采用 |
| 在鼠标松开后,按屏幕坐标以 `inView: nil` 弹出菜单 | 用户实际点击确认仍不显示,未采用 |
| 独立 Accessory 进程持有原生菜单 | 用户确认测试探针能显示;随后确认编译后的真实 Rust 辅助进程菜单正常 |

公开的同类案例:[Codex #59930](https://github.com/openai/codex/issues/59930)、[Crossbow #346](https://github.com/Richard-Zhang1019/Crossbow/pull/346)。[macshot #511](https://github.com/sw33tLie/macshot/pull/511) 的屏幕坐标方案有其报告者的成功验证,但在本机未通过用户验收,因此没有采用。

## 已实现的修复

- `src-tauri/src/main.rs` 在初始化 Tauri、用户数据和 core 之前分流 `--menubar-helper`。
- `src-tauri/src/menubar/helper.rs` 在所有受支持的 macOS 上启动同一可执行文件的辅助模式。子进程保持 Accessory,复用现有 `macos.rs` 原生菜单实现,不启动 WebView 或 core。
- 主程序用匿名 stdin 管道传递状态快照、显示样式、语言和主题;子进程经 stdout 回传菜单开合与类型化动作。动作仍在主程序主线程上执行。
- 发送端与主队列接收端均只保留最新待处理快照,避免积压过期读数;主题只在变化时重新设置。
- 父进程退出或崩溃时,输入管道 EOF 立即结束辅助进程,即使菜单正在展开。辅助进程异常退出后,主程序等待 3 秒重新启动并重发最新快照。
- 按用户于 2026-11-15 的明确要求,移除系统版本判断及主应用中的进程内菜单分支,所有受支持的 macOS 统一走辅助进程。安装、刷新和隐藏使用同一路径。主窗口的 Dock 行为不变,不随菜单开合切换 activation policy。

`Action::Open` 的页面名使用 `Cow<'static, str>`:本地构建菜单仍可借用常量,管道解码时持有字符串,不泄漏内存。状态模型添加序列化支持,菜单渲染规则保持原样。

## 验收证据

- `cargo clippy --locked --manifest-path src-tauri/Cargo.toml --all-targets -- -D warnings`:通过。
- `cargo test --locked --manifest-path src-tauri/Cargo.toml --lib menubar::`:71 项通过,包括新增的快照等价、动作往返、消息边界、异常数据和更新合并检查。
- `cargo build --locked --manifest-path src-tauri/Cargo.toml --bin thinkwatch-lite`:通过。
- `cargo fmt --manifest-path src-tauri/Cargo.toml --all --check` 与 `git diff --check`:通过。
- 真实辅助模式进程检查:启动、EOF 退出、错误输入退出,以及语言、主题、隐藏/显示样式切换通过。
- 用户在全屏应用中实际点击真实 Rust 辅助进程的“12.3K”测试菜单,确认菜单正常并点击了“打开主界面”。测试不操作正在运行的网关。
- 保留原生回归检查 `src-tauri/examples/menubar_helper_smoke.rs`。它在真正的辅助模式进程中打开 NSMenu 并触发第一项,收到 `Open(true)`、`Open(false)`、`Action(OpenMain)`,然后验证 EOF 退出;另一个场景验证菜单跟踪期间 EOF 也能退出。两项通过。

原生回归命令:

```sh
CARGO_INCREMENTAL=0 cargo run --locked --manifest-path src-tauri/Cargo.toml --example menubar_helper_smoke
```

程序触发的点击不能替代真实全屏鼠标验收,因此两种证据分别保留。按用户要求不安排旧系统测试;外接屏及完整安装包升级尚未验收。Debug 辅助进程在测试数据持续刷新时约 82 MiB RSS,发布构建内存未测量。

统一 macOS 路径后,在当前 macOS 27.2.1 上再次通过 `cargo clippy --all-targets -- -D warnings`、格式和差异检查。没有安排旧系统测试;上面的原生交互验收针对同一辅助进程实现。

## 交付与清理

修复保留在工作区源码,尚未提交或替换 `/Applications` 中的安装版;需重新打包安装后才会影响正在使用的版本。安装版 Lite(PID 2384)和 core(PID 2411)全程保持运行。

本轮临时目录为 `/tmp/twlite-fullscreen-fix.KdFsAv`,含探针、构建缓存、二进制、测试驱动和日志,验证完成后已删除。`du` 统计清理约 4.90 GiB 临时产物;清理前后 `df` 可用空间净增约 4.45 GiB(同盘有其他活动)。保留修复源码、回归检查和本文;活动工作区不移除,因此无需制作工作区归档。

统一 macOS 路径后的验证目录 `/tmp/twlite-unified-menubar.2PWIAb` 也已清理,包含构建缓存和 Clippy 日志;清理前确认验证已结束且无辅助测试进程占用。`du` 统计删除 1,196,624 KiB(约 1.14 GiB),前后 `df` 可用空间净增 981,976 KiB(约 0.94 GiB)。源码、本文和既有活动工作区依赖继续保留。
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "thinkwatch-lite",
"private": true,
"description": "Desktop app for a local AI API gateway on macOS, Windows and Linux",
"version": "2026.11.14",
"version": "2026.11.15",
"type": "module",
"packageManager": "[email protected]",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions release-notes/2026.11.15.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Web search and page reading can now run in Core. Configure the execution mode under **Routing → Auxiliary**, choose automatic search engines or set your own preferences, and test search, page reads, and find-in-page directly from the app. Language and country/region follow the connected Core host by default, with searchable choices by name instead of code inputs.

On macOS, the menu-bar menu now runs in a dedicated accessory process, allowing it to open over other applications’ full-screen spaces while the main app keeps its normal Dock behavior. The same implementation is used on all supported macOS versions. Menu updates, actions, language, and theme stay synchronized, and the helper exits with the main app or restarts after an unexpected exit.

This release includes ThinkWatch Core 0.97.0. Recognized Claude Code standalone WebSearch requests can avoid an auxiliary model call; web tools in ordinary conversations still return results to the main model, whose normal usage remains billed. Core execution is opt-in and does not require MCP or a search API key.
6 changes: 6 additions & 0 deletions scripts/shots/mock/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ export const CORE: { [N in WebviewEndpoint]: Handler<N> } = {
ConfigRepairPlan: () => ({ base_version: configVersion(), fixes: [] }),
RepairConfig: refuse,
SaveListen: refuse,
WebTools: () => ({ config_version: configVersion(), system_locale: { language: "zh-Hans", region: "CN" }, config: {
mode: "upstream", engines: [], proxy: "system", language: "", region: "", allowed_domains: [], blocked_domains: [],
max_results: 8, read_pages: 2, max_page_chars: 12000, timeout_secs: 30, max_concurrent: 4, interval_ms: 1000, cache_secs: 600, max_tool_calls: 8, fallback_to_upstream: false,
} }),
SaveWebTools: refuse,
TestWebTool: refuse,
// 导入导出与备份:只读的列一份当前版本,写的拒绝
ConfigItems: () => overview(lastSeen()).providers.map((p) => ({ item: { kind: "provider", name: p.name }, refs: [] })),
ExportConfig: refuse,
Expand Down
29 changes: 29 additions & 0 deletions scripts/shots/scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// i18n 表里取,所以中英两种界面走的是同一段代码。
import { textOf } from "@/i18n";
import { connText } from "@/connection/connection.i18n";
import { webToolsText } from "@/routing/WebTools.i18n";
import { routingPageText } from "@/routing/RoutingPage.i18n";
import { routingText } from "@/routing/routing.i18n";
import { byText, choose, click, idle, type, waitFor } from "./drive";

Expand Down Expand Up @@ -41,6 +43,33 @@ export const SCENES: Scene[] = [
{ id: "keys", page: "keys" },
{ id: "upstreams", page: "upstreams" },
{ id: "routing", page: "routing" },
{
id: "web-tools", page: "routing",
setup: async () => {
click(await waitFor(() => byText(textOf(routingPageText).probes)));
const title = await waitFor(() => byText(textOf(webToolsText).title, "section div"));
title.scrollIntoView({ block: "center" });
},
},
{
id: "web-tools-config", page: "routing", remote: true,
setup: async () => {
click(await waitFor(() => byText(textOf(routingPageText).probes)));
click(await waitFor(() => byText(textOf(webToolsText).configure)));
await waitFor("[role=dialog]");
},
},
{
id: "web-tools-language", page: "routing", remote: true,
setup: async () => {
click(await waitFor(() => byText(textOf(routingPageText).probes)));
click(await waitFor(() => byText(textOf(webToolsText).configure)));
const input = await waitFor<HTMLInputElement>("[role=dialog] input[id$='-language']");
click(input);
type(input, textOf(webToolsText) === webToolsText.zh ? "中文" : "Chinese");
await waitFor("[role=listbox]");
},
},
{ id: "security", page: "security" },
{ id: "mcp", page: "mcp" },
{ id: "settings", page: "settings" },
Expand Down
30 changes: 15 additions & 15 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "thinkwatch-lite"
version = "2026.11.14"
version = "2026.11.15"
edition = "2024"
# **这个数决定依赖能升到哪一版。**edition 2024 的解析器只挑声明的 Rust
# 版本编得动的依赖:写 1.85 的时候,`cargo update` 一直停在旧的 time 和
Expand All @@ -26,12 +26,12 @@ license = "MIT"
# twcore 二进制必须和这里编译进去的协议镜像来自同一个 core 版本 —— 打包脚本正是
# 从 tw-api 锁到的 tag 去取二进制的(见 scripts/fetch-core.sh)。
[workspace.dependencies]
tw-api = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.96.0" }
tw-types = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.96.0" }
tw-yaml = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.96.0" }
tw-guard = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.96.0" }
tw-watch = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.96.0" }
tw-link = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.96.0" }
tw-api = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.97.0" }
tw-types = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.97.0" }
tw-yaml = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.97.0" }
tw-guard = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.97.0" }
tw-watch = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.97.0" }
tw-link = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.97.0" }

[lib]
name = "thinkwatch_lite_lib"
Expand Down
99 changes: 99 additions & 0 deletions src-tauri/examples/menubar_helper_smoke.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//! macOS 菜单辅助进程的原生往返检查,不启动 Tauri 或 core。
//!
//! `cargo run --manifest-path src-tauri/Cargo.toml --example menubar_helper_smoke`
//! 临时打开菜单、触发第一项,断言动作通过管道返回,关闭输入后子进程退出。
//! 全屏空间仍须实际鼠标点击验收,不能用这条程序触发的点击代替。

#[cfg(all(target_os = "macos", debug_assertions))]
fn main() {
use std::io::{BufRead, BufReader, Write};
use std::process::{Command, Stdio};
use std::time::Duration;

use objc2::rc::Retained;
use objc2_app_kit::{NSApplication, NSMenu, NSView};
use thinkwatch_lite_lib::menubar::{helper, macos, model};

fn containing_menu(view: &NSView) -> Option<Retained<NSMenu>> {
if let Some(item) = view.enclosingMenuItem() {
// 菜单仍由 menubar::macos 持有。
if let Some(menu) = unsafe { item.menu() } {
return Some(menu);
}
}
view.subviews().iter().find_map(|v| containing_menu(&v))
}

if std::env::args().any(|arg| arg == "--menubar-helper") {
std::thread::spawn(|| {
std::thread::sleep(Duration::from_secs(1));
macos::on_main(|mtm| macos::preview::open_menu_later(mtm, 0.1));
std::thread::sleep(Duration::from_secs(1));
macos::on_main(|mtm| {
assert!(macos::preview::is_open(), "原生菜单没有打开");
let menu = NSApplication::sharedApplication(mtm)
.windows()
.iter()
.filter_map(|window| window.contentView())
.find_map(|view| containing_menu(&view))
.expect("菜单没有挂出自定义行");
menu.cancelTrackingWithoutAnimation();
menu.performActionForItemAtIndex(0);
});
// 父端断管道应结束进程;失败时不让测试无限等待。
std::thread::sleep(Duration::from_secs(15));
std::process::exit(4);
});
assert!(helper::run_if_requested());
return;
}

for drop_while_open in [false, true] {
let mut child = Command::new(std::env::current_exe().unwrap())
.arg("--menubar-helper")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.unwrap();
let mut input = child.stdin.take().unwrap();
let frame = serde_json::json!({
"snapshot": model::Snapshot::default(),
"style": "full", "lang": "zh", "theme": null,
});
writeln!(input, "{frame}").unwrap();
input.flush().unwrap();
let mut opened = false;
let mut closed = false;
let mut action = false;
for line in BufReader::new(child.stdout.take().unwrap()).lines() {
let event: serde_json::Value = serde_json::from_str(&line.unwrap()).unwrap();
println!("{event}");
opened |= event == serde_json::json!({"Open": true});
closed |= event == serde_json::json!({"Open": false});
if drop_while_open && opened {
break;
}
if event == serde_json::json!({"Action": "OpenMain"}) {
action = true;
break;
}
}
drop(input);
assert!(
child.wait().unwrap().success(),
"辅助进程没有随管道关闭退出"
);
if drop_while_open {
assert!(opened, "菜单没有打开");
println!("PASS: EOF closes helper while its menu is tracking");
} else {
assert!(opened && closed && action, "菜单开合或动作没有完整回传");
println!("PASS: native menu action and helper EOF cleanup");
}
}
}

#[cfg(not(all(target_os = "macos", debug_assertions)))]
fn main() {
eprintln!("This check requires a macOS debug build and an active desktop session.");
}
3 changes: 3 additions & 0 deletions src-tauri/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ webview_endpoints![
ConfigRepairPlan,
RepairConfig,
SaveListen,
WebTools,
SaveWebTools,
TestWebTool,
// 记录。搜索翻的是整个库,界面自己发起、自己翻页
History,
HistorySearch,
Expand Down
5 changes: 5 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

fn main() {
// 菜单栏子进程只跑 AppKit,必须在 Tauri、数据目录和 core 初始化之前分流。
#[cfg(target_os = "macos")]
if thinkwatch_lite_lib::menubar::helper::run_if_requested() {
return;
}
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_env("TWLITE_LOG")
Expand Down
Loading
Loading