diff --git a/Cargo.lock b/Cargo.lock
index 0395239..2bcd972 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -155,6 +155,15 @@ dependencies = [
"x11rb",
]
+[[package]]
+name = "arc-swap"
+version = "1.9.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "84a22b5d51209f6de83d37a0b33d320acb8da88823e42a94c075140708f032a5"
+dependencies = [
+ "rustversion",
+]
+
[[package]]
name = "arrayref"
version = "0.3.9"
@@ -825,6 +834,15 @@ dependencies = [
"crossbeam-utils",
]
+[[package]]
+name = "crossbeam-queue"
+version = "0.3.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "03e8bd762f7479489c70ed6c768ddca99d7296857de437a68dcb2a94365b3fae"
+dependencies = [
+ "crossbeam-utils",
+]
+
[[package]]
name = "crossbeam-utils"
version = "0.8.23"
@@ -1878,6 +1896,7 @@ version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9590458a3ba4ad8e66a6b572dbe758cc5d4f84f57e682a097358e4fe0f02b006"
dependencies = [
+ "async-channel",
"bitflags 2.13.2",
"bytemuck",
"chrono",
@@ -1890,6 +1909,7 @@ dependencies = [
"icu_normalizer",
"image",
"js-sys",
+ "ksni",
"lyon_algorithms",
"lyon_extra",
"lyon_geom",
@@ -2380,6 +2400,26 @@ version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
+[[package]]
+name = "ksni"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1bcc1cb43797140f74b711f1c4a49f48a7a7429f211c5fb78264e7bcd1e99caf"
+dependencies = [
+ "arc-swap",
+ "async-executor",
+ "async-io",
+ "async-lock",
+ "crossbeam-queue",
+ "futures-channel",
+ "futures-lite",
+ "futures-util",
+ "pastey",
+ "serde",
+ "task-local",
+ "zbus",
+]
+
[[package]]
name = "kurbo"
version = "0.13.1"
@@ -3250,6 +3290,12 @@ dependencies = [
"skrifa",
]
+[[package]]
+name = "pastey"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2ee67f1008b1ba2321834326597b8e186293b049a023cdef258527550b9935b4"
+
[[package]]
name = "pem-rfc7468"
version = "0.7.0"
@@ -4631,6 +4677,15 @@ dependencies = [
"xattr",
]
+[[package]]
+name = "task-local"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2972044a9e5e448a506a7ff6f0d03b566d8ef4cd6918a58fc59835a0f8666626"
+dependencies = [
+ "pin-project-lite",
+]
+
[[package]]
name = "tempfile"
version = "3.27.0"
diff --git a/Cargo.toml b/Cargo.toml
index 315f363..19704e1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,7 +16,7 @@ serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["preserve_order"] }
sha2 = "0.10"
thiserror = "2"
-slint = { version = "1", default-features = false, features = ["std", "compat-1-18", "backend-winit", "renderer-software"] }
+slint = { version = "1", default-features = false, features = ["std", "compat-1-18", "backend-winit", "renderer-software", "system-tray"] }
[build-dependencies]
slint-build = "1"
diff --git a/README.md b/README.md
index 771a5e0..b35426f 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,6 @@ cargo run --bin punchlog-ui
cargo run --bin extract-device -- --write
```
-`punchlog-ui` 打开最近一周的列表窗口。`extract-device --write` 需要手机打开 USB 调试并具有 root,用来把当前 iCenter 的版本和设备身份写回 `.env`。
+`punchlog-ui` 打开最近一周的列表窗口。关闭窗口后程序留在托盘,右键可以选择显示、隐藏或退出。`extract-device --write` 需要手机打开 USB 调试并具有 root,用来把当前 iCenter 的版本和设备身份写回 `.env`。
账号、密码、token、项目和设备身份放在项目根目录的 `.env`,参考 `.env.example`。token 失效时会用账号密码重新登录。
diff --git a/src/bin/punchlog-ui.rs b/src/bin/punchlog-ui.rs
index 3b63566..14f48a0 100644
--- a/src/bin/punchlog-ui.rs
+++ b/src/bin/punchlog-ui.rs
@@ -1,5 +1,6 @@
+use std::cell::RefCell;
use std::process::ExitCode;
-use std::rc::Rc;
+use std::rc::{Rc, Weak};
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;
use std::time::Duration;
@@ -8,40 +9,138 @@ use chrono::{Datelike, NaiveDate};
slint::include_modules!();
+/// 窗口可以关掉并释放。托盘一直留着,直到选择退出。
+struct Session {
+ window: RefCell