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
634 changes: 403 additions & 231 deletions src-tauri/Cargo.lock

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +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.46.0" }
tw-types = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.46.0" }
tw-yaml = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.46.0" }
tw-guard = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.46.0" }
tw-watch = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.46.0" }
tw-api = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.47.0" }
tw-types = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.47.0" }
tw-yaml = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.47.0" }
tw-guard = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.47.0" }
tw-watch = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.47.0" }
tw-link = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.47.0" }

[lib]
name = "thinkwatch_lite_lib"
Expand Down Expand Up @@ -64,9 +65,12 @@ tw-adopt = { path = "crates/tw-adopt" }
tw-scan = { path = "crates/tw-scan" }
tw-types = { workspace = true }
tw-guard = { workspace = true }
# 控制面的握手与加密(Noise NNpsk0),和 core 用的是同一份实现。握手里交换的控制面
# 版本号来自 tw-api,所以两者必须钉在同一个 tag 上(见上面 `[workspace.dependencies]`)
tw-link = { workspace = true }

anyhow = "1"
# 生成控制面的凭据(见 src/token.rs)
# 新连接的 id、诊断包的临时目录名
rand = "0.10"
libc = "0.2"
# 界面和 Rust 侧之间不经过 core 的那些类型,导出成 TypeScript(`wire.rs`)。
Expand Down
19 changes: 7 additions & 12 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,25 @@ fn main() {
tauri_build::build()
}

/// 这一版应用配的是哪一版 core:`Cargo.lock` 里 tw-api 锁到的 tag,去掉开头的 `v`。
/// 这一版应用配的是哪一版 core:`Cargo.lock` 里锁到的 tw-api 的版本号。
///
/// 连远程 core 时版本对不上,界面要说出「本应用需要 core X」。**从锁文件读,不另写
/// 一份**:打包脚本取 twcore 看的也是这一行(`scripts/fetch-core.sh`),两处说的
/// 必然是同一版。读不到(临时用 `[patch]` 指向本地 core 时就是这样)记成 `dev`
/// 一份**。读版本号而不是 tag:临时钉在某个提交上(还没发版)时没有 tag,而 core 的
/// 各个 crate 和 twcore 共用同一个版本号
fn core_tag() {
println!("cargo:rerun-if-changed=Cargo.lock");
let lock = std::fs::read_to_string("Cargo.lock").unwrap_or_default();
let mut in_api = false;
let mut tag = None;
let mut version = None;
for line in lock.lines() {
if line.starts_with("name = ") {
in_api = line == "name = \"tw-api\"";
} else if in_api
&& line.starts_with("source = ")
&& let Some(i) = line.find("tag=v")
{
let rest = &line[i + "tag=v".len()..];
let end = rest.find(['#', '&', '"']).unwrap_or(rest.len());
tag = Some(rest[..end].to_string());
} else if in_api && let Some(v) = line.strip_prefix("version = ") {
version = Some(v.trim_matches('"').to_string());
}
}
println!(
"cargo:rustc-env=TW_CORE_TAG={}",
tag.unwrap_or_else(|| "dev".into())
version.unwrap_or_else(|| "dev".into())
);
}
16 changes: 10 additions & 6 deletions src-tauri/crates/tw-scan/src/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,12 @@ mod tests {

let (_w, mut rx) = watch(std::slice::from_ref(&dir)).unwrap();
std::fs::write(dir.join("CLAUDE.md"), "# 二\n").unwrap();
// 超时和通道关了都不算:要的是真收到一个信号
assert!(
tokio::time::timeout(Duration::from_secs(5), rx.recv())
.await
.is_ok(),
matches!(
tokio::time::timeout(Duration::from_secs(5), rx.recv()).await,
Ok(Some(()))
),
"没收到信号"
);
}
Expand All @@ -244,10 +246,12 @@ mod tests {

// 而我们关心的那种照样能叫醒它
std::fs::write(dir.join("CLAUDE.md"), "# 改了\n").unwrap();
// 超时和通道关了都不算:要的是真收到一个信号
assert!(
tokio::time::timeout(Duration::from_secs(5), rx.recv())
.await
.is_ok(),
matches!(
tokio::time::timeout(Duration::from_secs(5), rx.recv()).await,
Ok(Some(()))
),
"该醒的时候没醒"
);
}
Expand Down
34 changes: 33 additions & 1 deletion src-tauri/examples/menubar_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
//! ```
//!
//! 状态:`sub`(订阅账号、有请求在跑)、`alert`(额度用完、有提醒)、`payg`(按量计费、
//! 有新版本)、`down`(网关无法启动)、`starting`。另可加 `--en`、`--icon`、`--numbers`。
//! 有新版本)、`down`(网关无法启动)、`starting`、`remote`(连着远程、断线重连中)。
//! 另可加 `--en`、`--icon`、`--numbers`,以及 `--dump`(打出原生菜单里的项就退出)。

#[cfg(target_os = "macos")]
fn main() {
Expand Down Expand Up @@ -82,6 +83,13 @@ fn main() {
);
let (bar, rows) = model::build(&snapshot(&name), style);
macos::apply(mtm, &bar, &rows);
// `--dump`:把原生菜单里实际有的项打出来就退出(看子菜单、勾选、分隔线)
if args.iter().any(|a| a == "--dump") {
for line in macos::describe_menu() {
println!("{line}");
}
return;
}
// 进行中的秒数每秒走:和应用里一样,只在后台线程里现算、投递到主线程
if name == "sub" || name == "alert" {
std::thread::spawn(move || {
Expand Down Expand Up @@ -136,8 +144,32 @@ fn snapshot(name: &str) -> thinkwatch_lite_lib::menubar::model::Snapshot {
notices_on: true,
undo_at_ms: Some(now - 40 * 60_000),
now_ms: now,
connections: vec![
Connection {
id: "local".into(),
name: "本机".into(),
current: name != "remote",
},
Connection {
id: "a1".into(),
name: "home-server".into(),
current: name == "remote",
},
Connection {
id: "b2".into(),
name: "office-nas".into(),
current: false,
},
],
..Default::default()
};
if name == "remote" {
return Snapshot {
gateway: Gateway::Unlinked,
remote: Some("home-server".into()),
..base
};
}
match name {
"sub" => Snapshot {
today: Some(Today {
Expand Down
Loading
Loading