2 Commits
Author SHA1 Message Date
molluskandClaude Opus 4.7 f926dbea4e feat(gui): desktop notification when a viewer joins or leaves
The host screen pops a desktop notification on each viewer join/leave,
so you know someone connected while the window is in the background.

Fired on a detached thread (the D-Bus call never touches the egui
frame) and gated on the same viewer-list transitions, so stopping the
host — which drops the child and stops pumping events — doesn't spray a
notification per remaining viewer.

notify-rust's default features give the pure-Rust zbus backend, so this
adds no system libdbus dependency and no GTK event loop (gui feature
only; the headless build is untouched).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 15:31:48 -04:00
molluskandClaude Opus 4.7 24e0d0e799 feat(gui): list connected viewers and let the host kick them
Track viewers by endpoint id instead of a bare count. The JSON event
stream gains viewer_joined / viewer_left (each carrying the id),
replacing viewer_count; active/max still ride along so the count
display is unchanged.

The host screen now renders one row per connected viewer with a Kick
button. Clicking it sends `kick <id>` to the headless child over a new
stdin command channel, which the host turns into a per-viewer
CancellationToken cancel; the existing teardown path then emits the
leave, so a kick and a self-disconnect look identical downstream.

The stdin channel only runs under --output json (the GUI shell-out) and
on a detached OS thread, so a read parked on stdin can't hold up the
host's Ctrl+C shutdown.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 15:27:49 -04:00
6 changed files with 513 additions and 75 deletions
Generated
+305 -43
View File
@@ -242,7 +242,7 @@ dependencies = [
"serde_repr", "serde_repr",
"tokio", "tokio",
"url", "url",
"zbus", "zbus 4.4.0",
] ]
[[package]] [[package]]
@@ -269,6 +269,20 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
] ]
[[package]]
name = "async-executor"
version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c96bf972d85afc50bf5ab8fe2d54d1586b4e0b46c97c50a0c9e71e2f7bcd812a"
dependencies = [
"async-task",
"concurrent-queue",
"fastrand",
"futures-lite",
"pin-project-lite",
"slab",
]
[[package]] [[package]]
name = "async-io" name = "async-io"
version = "2.6.0" version = "2.6.0"
@@ -711,7 +725,7 @@ dependencies = [
"iana-time-zone", "iana-time-zone",
"num-traits", "num-traits",
"serde", "serde",
"windows-link", "windows-link 0.2.1",
] ]
[[package]] [[package]]
@@ -1893,8 +1907,8 @@ dependencies = [
"libc", "libc",
"log", "log",
"rustversion", "rustversion",
"windows-link", "windows-link 0.2.1",
"windows-result", "windows-result 0.4.1",
] ]
[[package]] [[package]]
@@ -1914,7 +1928,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8" checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8"
dependencies = [ dependencies = [
"rustix 1.1.4", "rustix 1.1.4",
"windows-link", "windows-link 0.2.1",
] ]
[[package]] [[package]]
@@ -2385,7 +2399,7 @@ dependencies = [
"js-sys", "js-sys",
"log", "log",
"wasm-bindgen", "wasm-bindgen",
"windows-core", "windows-core 0.62.2",
] ]
[[package]] [[package]]
@@ -2582,7 +2596,7 @@ dependencies = [
"socket2", "socket2",
"widestring", "widestring",
"windows-registry", "windows-registry",
"windows-result", "windows-result 0.4.1",
"windows-sys 0.61.2", "windows-sys 0.61.2",
] ]
@@ -2816,7 +2830,7 @@ dependencies = [
"simd_cesu8", "simd_cesu8",
"thiserror 2.0.18", "thiserror 2.0.18",
"walkdir", "walkdir",
"windows-link", "windows-link 0.2.1",
] ]
[[package]] [[package]]
@@ -2925,7 +2939,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"windows-link", "windows-link 0.2.1",
] ]
[[package]] [[package]]
@@ -3053,6 +3067,18 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3d25b0e0b648a86960ac23b7ad4abb9717601dec6f66c165f5b037f3f03065f" checksum = "d3d25b0e0b648a86960ac23b7ad4abb9717601dec6f66c165f5b037f3f03065f"
[[package]]
name = "mac-notification-sys"
version = "0.6.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29a16783dd1a47849b8c8133c9cd3eb2112cfbc6901670af3dba47c8bbfb07d3"
dependencies = [
"cc",
"objc2 0.6.4",
"objc2-foundation 0.3.2",
"time",
]
[[package]] [[package]]
name = "matchers" name = "matchers"
version = "0.2.0" version = "0.2.0"
@@ -3363,8 +3389,8 @@ dependencies = [
"tokio-util", "tokio-util",
"tracing", "tracing",
"web-sys", "web-sys",
"windows", "windows 0.62.2",
"windows-result", "windows-result 0.4.1",
"wmi", "wmi",
] ]
@@ -3480,6 +3506,20 @@ dependencies = [
"windows-sys 0.61.2", "windows-sys 0.61.2",
] ]
[[package]]
name = "notify-rust"
version = "4.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50ff2e74231b72c832d82982193b417f230945be6bdb5575b251d941d31adb00"
dependencies = [
"futures-lite",
"log",
"mac-notification-sys",
"serde",
"tauri-winrt-notification",
"zbus 5.15.0",
]
[[package]] [[package]]
name = "nu-ansi-term" name = "nu-ansi-term"
version = "0.50.3" version = "0.50.3"
@@ -3972,7 +4012,7 @@ dependencies = [
"libc", "libc",
"redox_syscall 0.5.18", "redox_syscall 0.5.18",
"smallvec", "smallvec",
"windows-link", "windows-link 0.2.1",
] ]
[[package]] [[package]]
@@ -4110,6 +4150,7 @@ dependencies = [
"iroh", "iroh",
"iroh-tickets", "iroh-tickets",
"nix 0.30.1", "nix 0.30.1",
"notify-rust",
"pipewire", "pipewire",
"serde", "serde",
"serde_json", "serde_json",
@@ -4154,7 +4195,7 @@ checksum = "092791278e026273c1b65bbdcfbba3a300f2994c896bd01ab01da613c29c46f1"
dependencies = [ dependencies = [
"base64", "base64",
"indexmap", "indexmap",
"quick-xml", "quick-xml 0.39.4",
"serde", "serde",
"time", "time",
] ]
@@ -4360,6 +4401,15 @@ version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
[[package]]
name = "quick-xml"
version = "0.37.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "quick-xml" name = "quick-xml"
version = "0.39.4" version = "0.39.4"
@@ -5263,6 +5313,18 @@ version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df7f62577c25e07834649fc3b39fafdc597c0a3527dc1c60129201ccfcbaa50c" checksum = "df7f62577c25e07834649fc3b39fafdc597c0a3527dc1c60129201ccfcbaa50c"
[[package]]
name = "tauri-winrt-notification"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b1e66e07de489fe43a46678dd0b8df65e0c973909df1b60ba33874e297ba9b9"
dependencies = [
"quick-xml 0.37.5",
"thiserror 2.0.18",
"windows 0.61.3",
"windows-version",
]
[[package]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.27.0" version = "3.27.0"
@@ -5793,6 +5855,7 @@ checksum = "ddd74a9687298c6858e9b88ec8935ec45d22e8fd5e6394fa1bd4e99a87789c76"
dependencies = [ dependencies = [
"getrandom 0.4.2", "getrandom 0.4.2",
"js-sys", "js-sys",
"serde_core",
"wasm-bindgen", "wasm-bindgen",
] ]
@@ -6141,7 +6204,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c324a910fd86ebdc364a3e61ec1f11737d3b1d6c273c0239ee8ff4bc0d24b4a" checksum = "9c324a910fd86ebdc364a3e61ec1f11737d3b1d6c273c0239ee8ff4bc0d24b4a"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quick-xml", "quick-xml 0.39.4",
"quote", "quote",
] ]
@@ -6367,16 +6430,38 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.61.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893"
dependencies = [
"windows-collections 0.2.0",
"windows-core 0.61.2",
"windows-future 0.2.1",
"windows-link 0.1.3",
"windows-numerics 0.2.0",
]
[[package]] [[package]]
name = "windows" name = "windows"
version = "0.62.2" version = "0.62.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580" checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580"
dependencies = [ dependencies = [
"windows-collections", "windows-collections 0.3.2",
"windows-core", "windows-core 0.62.2",
"windows-future", "windows-future 0.3.2",
"windows-numerics", "windows-numerics 0.3.1",
]
[[package]]
name = "windows-collections"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8"
dependencies = [
"windows-core 0.61.2",
] ]
[[package]] [[package]]
@@ -6385,7 +6470,20 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610" checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610"
dependencies = [ dependencies = [
"windows-core", "windows-core 0.62.2",
]
[[package]]
name = "windows-core"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
dependencies = [
"windows-implement",
"windows-interface",
"windows-link 0.1.3",
"windows-result 0.3.4",
"windows-strings 0.4.2",
] ]
[[package]] [[package]]
@@ -6396,9 +6494,20 @@ checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
dependencies = [ dependencies = [
"windows-implement", "windows-implement",
"windows-interface", "windows-interface",
"windows-link", "windows-link 0.2.1",
"windows-result", "windows-result 0.4.1",
"windows-strings", "windows-strings 0.5.1",
]
[[package]]
name = "windows-future"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e"
dependencies = [
"windows-core 0.61.2",
"windows-link 0.1.3",
"windows-threading 0.1.0",
] ]
[[package]] [[package]]
@@ -6407,9 +6516,9 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb" checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb"
dependencies = [ dependencies = [
"windows-core", "windows-core 0.62.2",
"windows-link", "windows-link 0.2.1",
"windows-threading", "windows-threading 0.2.1",
] ]
[[package]] [[package]]
@@ -6434,20 +6543,36 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "windows-link"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
[[package]] [[package]]
name = "windows-link" name = "windows-link"
version = "0.2.1" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-numerics"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1"
dependencies = [
"windows-core 0.61.2",
"windows-link 0.1.3",
]
[[package]] [[package]]
name = "windows-numerics" name = "windows-numerics"
version = "0.3.1" version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26" checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26"
dependencies = [ dependencies = [
"windows-core", "windows-core 0.62.2",
"windows-link", "windows-link 0.2.1",
] ]
[[package]] [[package]]
@@ -6456,9 +6581,18 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720"
dependencies = [ dependencies = [
"windows-link", "windows-link 0.2.1",
"windows-result", "windows-result 0.4.1",
"windows-strings", "windows-strings 0.5.1",
]
[[package]]
name = "windows-result"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
dependencies = [
"windows-link 0.1.3",
] ]
[[package]] [[package]]
@@ -6467,7 +6601,16 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
dependencies = [ dependencies = [
"windows-link", "windows-link 0.2.1",
]
[[package]]
name = "windows-strings"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
dependencies = [
"windows-link 0.1.3",
] ]
[[package]] [[package]]
@@ -6476,7 +6619,7 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
dependencies = [ dependencies = [
"windows-link", "windows-link 0.2.1",
] ]
[[package]] [[package]]
@@ -6512,7 +6655,7 @@ version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [ dependencies = [
"windows-link", "windows-link 0.2.1",
] ]
[[package]] [[package]]
@@ -6546,13 +6689,31 @@ dependencies = [
"windows_x86_64_msvc 0.52.6", "windows_x86_64_msvc 0.52.6",
] ]
[[package]]
name = "windows-threading"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6"
dependencies = [
"windows-link 0.1.3",
]
[[package]] [[package]]
name = "windows-threading" name = "windows-threading"
version = "0.2.1" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37" checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37"
dependencies = [ dependencies = [
"windows-link", "windows-link 0.2.1",
]
[[package]]
name = "windows-version"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4060a1da109b9d0326b7262c8e12c84df67cc0dbc9e33cf49e01ccc2eb63631"
dependencies = [
"windows-link 0.2.1",
] ]
[[package]] [[package]]
@@ -6828,8 +6989,8 @@ dependencies = [
"log", "log",
"serde", "serde",
"thiserror 2.0.18", "thiserror 2.0.18",
"windows", "windows 0.62.2",
"windows-core", "windows-core 0.62.2",
] ]
[[package]] [[package]]
@@ -6990,9 +7151,44 @@ dependencies = [
"uds_windows", "uds_windows",
"windows-sys 0.52.0", "windows-sys 0.52.0",
"xdg-home", "xdg-home",
"zbus_macros", "zbus_macros 4.4.0",
"zbus_names", "zbus_names 3.0.0",
"zvariant", "zvariant 4.2.0",
]
[[package]]
name = "zbus"
version = "5.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3bcbf15c8708d7fc1be0c993622e0a5cbd5e8b52bfa40afa4c3e0cd8d724ac1"
dependencies = [
"async-broadcast",
"async-executor",
"async-io",
"async-lock",
"async-process",
"async-recursion",
"async-task",
"async-trait",
"blocking",
"enumflags2",
"event-listener",
"futures-core",
"futures-lite",
"hex",
"libc",
"ordered-stream",
"rustix 1.1.4",
"serde",
"serde_repr",
"tracing",
"uds_windows",
"uuid",
"windows-sys 0.61.2",
"winnow",
"zbus_macros 5.15.0",
"zbus_names 4.3.2",
"zvariant 5.11.0",
] ]
[[package]] [[package]]
@@ -7005,7 +7201,22 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
"zvariant_utils", "zvariant_utils 2.1.0",
]
[[package]]
name = "zbus_macros"
version = "5.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51fa5406ad9175a8c825a931f8cf347116b531b3634fcb0b627c290f1f2516ff"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn",
"zbus_names 4.3.2",
"zvariant 5.11.0",
"zvariant_utils 3.3.1",
] ]
[[package]] [[package]]
@@ -7016,7 +7227,18 @@ checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c"
dependencies = [ dependencies = [
"serde", "serde",
"static_assertions", "static_assertions",
"zvariant", "zvariant 4.2.0",
]
[[package]]
name = "zbus_names"
version = "4.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7074f3e50b894eac91750142016d30d0a89be8e67dbfd9704fb875825760e52d"
dependencies = [
"serde",
"winnow",
"zvariant 5.11.0",
] ]
[[package]] [[package]]
@@ -7145,7 +7367,21 @@ dependencies = [
"serde", "serde",
"static_assertions", "static_assertions",
"url", "url",
"zvariant_derive", "zvariant_derive 4.2.0",
]
[[package]]
name = "zvariant"
version = "5.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c1567a6ec68df868cbbfde844cfc6d81649fe5109a62b116b19fabd53e618ee"
dependencies = [
"endi",
"enumflags2",
"serde",
"winnow",
"zvariant_derive 5.11.0",
"zvariant_utils 3.3.1",
] ]
[[package]] [[package]]
@@ -7158,7 +7394,20 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
"zvariant_utils", "zvariant_utils 2.1.0",
]
[[package]]
name = "zvariant_derive"
version = "5.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7d5b780599bbde114e39d9a0799577fad1ced5105d38515745f7b3099d8ceda"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn",
"zvariant_utils 3.3.1",
] ]
[[package]] [[package]]
@@ -7171,3 +7420,16 @@ dependencies = [
"quote", "quote",
"syn", "syn",
] ]
[[package]]
name = "zvariant_utils"
version = "3.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d464f5733ffa07a3164d656f18533caace9d0638596721355d73256a410d691"
dependencies = [
"proc-macro2",
"quote",
"serde",
"syn",
"winnow",
]
+4 -1
View File
@@ -34,6 +34,9 @@ ureq = { version = "3", default-features = false, features = ["rustls"] }
toml = "1" toml = "1"
chrono = { version = "0.4", default-features = false, features = ["clock", "serde"] } chrono = { version = "0.4", default-features = false, features = ["clock", "serde"] }
eframe = { version = "0.34.2", default-features = false, features = ["glow", "default_fonts", "wayland", "x11"], optional = true } eframe = { version = "0.34.2", default-features = false, features = ["glow", "default_fonts", "wayland", "x11"], optional = true }
# Desktop notifications on viewer join/leave. Default features give the
# pure-Rust zbus backend (no system libdbus, no image crate).
notify-rust = { version = "4", optional = true }
[profile.release] [profile.release]
lto = "thin" lto = "thin"
@@ -43,4 +46,4 @@ strip = "symbols"
[features] [features]
# Opt-in graphical front-end (pixelpass --gui). Default-off so the headless # Opt-in graphical front-end (pixelpass --gui). Default-off so the headless
# build never pulls the GUI toolkit tree. # build never pulls the GUI toolkit tree.
gui = ["dep:eframe"] gui = ["dep:eframe", "dep:notify-rust"]
+11 -3
View File
@@ -22,7 +22,11 @@ pub fn set_json(enabled: bool) {
JSON_ENABLED.store(enabled, Ordering::Relaxed); JSON_ENABLED.store(enabled, Ordering::Relaxed);
} }
fn json_enabled() -> bool { /// Whether the JSON event stream is on — i.e. we're being driven by a
/// machine front-end (the `--gui` shell-out) rather than a human terminal.
/// Gates features that only make sense under that front-end, like the
/// stdin command channel the host reads `kick` requests from.
pub fn json_enabled() -> bool {
JSON_ENABLED.load(Ordering::Relaxed) JSON_ENABLED.load(Ordering::Relaxed)
} }
@@ -42,8 +46,12 @@ pub enum Event<'a> {
max_viewers: u32, max_viewers: u32,
max_viewers_source: &'a str, max_viewers_source: &'a str,
}, },
/// Active viewer count changed. /// A viewer joined. `id` is the viewer's endpoint id; `active` is the new
ViewerCount { active: u32, max: u32 }, /// total after the join.
ViewerJoined { id: &'a str, active: u32, max: u32 },
/// A viewer left — disconnected on their own or kicked by the host. `id`
/// is the viewer's endpoint id; `active` is the new total after.
ViewerLeft { id: &'a str, active: u32, max: u32 },
/// Capture pipeline lifecycle (spawned on first viewer, torn down on last). /// Capture pipeline lifecycle (spawned on first viewer, torn down on last).
Capture { state: CaptureState }, Capture { state: CaptureState },
/// A viewer was turned away (host full, or capture spawn failed). /// A viewer was turned away (host full, or capture spawn failed).
+37 -7
View File
@@ -6,8 +6,8 @@
//! egui app drains each frame. stderr is captured into a small ring so a //! egui app drains each frame. stderr is captured into a small ring so a
//! failed launch (e.g. a missing gst plugin) can be surfaced in the window. //! failed launch (e.g. a missing gst plugin) can be surfaced in the window.
use std::io::{BufRead, BufReader}; use std::io::{BufRead, BufReader, Write};
use std::process::{Child, Command, Stdio}; use std::process::{Child, ChildStdin, Command, Stdio};
use std::sync::mpsc::Receiver; use std::sync::mpsc::Receiver;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::time::Duration; use std::time::Duration;
@@ -35,7 +35,13 @@ pub enum ChildEvent {
max_viewers: u32, max_viewers: u32,
max_viewers_source: String, max_viewers_source: String,
}, },
ViewerCount { ViewerJoined {
id: String,
active: u32,
max: u32,
},
ViewerLeft {
id: String,
active: u32, active: u32,
max: u32, max: u32,
}, },
@@ -63,6 +69,9 @@ pub struct ChildProc {
child: Child, child: Child,
pub rx: Receiver<ChildEvent>, pub rx: Receiver<ChildEvent>,
stderr_tail: Arc<Mutex<Vec<String>>>, stderr_tail: Arc<Mutex<Vec<String>>>,
/// Write end of the child's stdin, for the line-based command channel
/// (see [`ChildProc::send_command`]). `None` once it's been closed.
stdin: Option<ChildStdin>,
} }
impl ChildProc { impl ChildProc {
@@ -72,11 +81,14 @@ impl ChildProc {
let exe = std::env::current_exe()?; let exe = std::env::current_exe()?;
let mut child = Command::new(exe) let mut child = Command::new(exe)
.args(args) .args(args)
.stdin(Stdio::null()) // Piped so we can send line commands (e.g. `kick <id>`); the host
// only reads it when driven this way (`--output json`).
.stdin(Stdio::piped())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.stderr(Stdio::piped()) .stderr(Stdio::piped())
.spawn()?; .spawn()?;
let stdin = child.stdin.take();
let (tx, rx) = std::sync::mpsc::channel(); let (tx, rx) = std::sync::mpsc::channel();
let stdout = child.stdout.take().expect("stdout piped"); let stdout = child.stdout.take().expect("stdout piped");
std::thread::spawn(move || { std::thread::spawn(move || {
@@ -114,9 +126,23 @@ impl ChildProc {
child, child,
rx, rx,
stderr_tail, stderr_tail,
stdin,
}) })
} }
/// Send one newline-terminated command to the child over its stdin (the
/// host parses these as `kick <endpoint-id>`). Best-effort: a closed pipe
/// (child already gone) just drops the command.
pub fn send_command(&mut self, cmd: &str) {
let Some(stdin) = self.stdin.as_mut() else {
return;
};
if let Err(e) = writeln!(stdin, "{cmd}") {
tracing::warn!("failed to send command to host child: {e}");
self.stdin = None; // pipe is dead; stop trying
}
}
/// Whether the child is still running. /// Whether the child is still running.
pub fn is_alive(&mut self) -> bool { pub fn is_alive(&mut self) -> bool {
matches!(self.child.try_wait(), Ok(None)) matches!(self.child.try_wait(), Ok(None))
@@ -205,10 +231,14 @@ mod tests {
} }
#[test] #[test]
fn viewer_count_round_trips() { fn viewer_join_leave_round_trip() {
assert!(matches!( assert!(matches!(
parse(Event::ViewerCount { active: 2, max: 4 }), parse(Event::ViewerJoined { id: "nodeXYZ", active: 2, max: 4 }),
ChildEvent::ViewerCount { active: 2, max: 4 } ChildEvent::ViewerJoined { id, active: 2, max: 4 } if id == "nodeXYZ"
));
assert!(matches!(
parse(Event::ViewerLeft { id: "nodeXYZ", active: 1, max: 4 }),
ChildEvent::ViewerLeft { id, active: 1, max: 4 } if id == "nodeXYZ"
)); ));
} }
+59 -1
View File
@@ -78,6 +78,23 @@ fn short_id(id: &str) -> String {
} }
} }
/// Fire a desktop notification, on a detached thread so the D-Bus round-trip
/// can't stall the egui frame. Best-effort: with no notification daemon it
/// just does nothing. (notify-rust talks D-Bus via pure-Rust zbus, so this
/// needs no system libdbus and no GTK event loop.)
fn notify(summary: &'static str, body: String) {
std::thread::spawn(move || {
if let Err(e) = notify_rust::Notification::new()
.appname("PixelPass")
.summary(summary)
.body(&body)
.show()
{
tracing::warn!("desktop notification failed: {e}");
}
});
}
/// Which screen the single window is currently showing. /// Which screen the single window is currently showing.
#[derive(Default, PartialEq)] #[derive(Default, PartialEq)]
enum Screen { enum Screen {
@@ -168,6 +185,9 @@ struct HostState {
copied: bool, copied: bool,
last_refusal: Option<String>, last_refusal: Option<String>,
error: Option<String>, error: Option<String>,
/// Endpoint ids of the currently-connected viewers, in arrival order.
/// Drives the per-viewer list and its Kick buttons.
viewers: Vec<String>,
} }
impl Default for HostState { impl Default for HostState {
@@ -186,6 +206,7 @@ impl Default for HostState {
copied: false, copied: false,
last_refusal: None, last_refusal: None,
error: None, error: None,
viewers: Vec::new(),
} }
} }
} }
@@ -362,6 +383,23 @@ impl PixelPassApp {
ui.add_space(6.0); ui.add_space(6.0);
ui.label(format!("Viewers: {} / {}", self.host.active, self.host.max)); ui.label(format!("Viewers: {} / {}", self.host.active, self.host.max));
// Per-viewer list with a Kick button each. Collect the click first so
// we're not borrowing self.host.viewers while we reach for the child.
let mut kick: Option<String> = None;
for id in &self.host.viewers {
ui.horizontal(|ui| {
ui.label(format!("• endpoint {}", short_id(id)));
if ui.small_button("Kick").clicked() {
kick = Some(id.clone());
}
});
}
if let Some(id) = kick
&& let Some(p) = &mut self.host.proc
{
p.send_command(&format!("kick {id}"));
}
if let Some(info) = &self.host.info { if let Some(info) = &self.host.info {
ui.label( ui.label(
egui::RichText::new(format!("{} · {}", info.display, info.capture)) egui::RichText::new(format!("{} · {}", info.display, info.capture))
@@ -452,6 +490,7 @@ impl PixelPassApp {
self.host.max = 0; self.host.max = 0;
self.host.capturing = false; self.host.capturing = false;
self.host.copied = false; self.host.copied = false;
self.host.viewers.clear();
let mut args = vec![ let mut args = vec![
"--host".to_string(), "--host".to_string(),
@@ -483,6 +522,7 @@ impl PixelPassApp {
self.host.capturing = false; self.host.capturing = false;
self.host.ticket = None; self.host.ticket = None;
self.host.copied = false; self.host.copied = false;
self.host.viewers.clear();
} }
/// Drain the host child's event channel into state, and detect an /// Drain the host child's event channel into state, and detect an
@@ -543,9 +583,27 @@ impl PixelPassApp {
cap_source: max_viewers_source, cap_source: max_viewers_source,
}); });
} }
ChildEvent::ViewerCount { active, max } => { ChildEvent::ViewerJoined { id, active, max } => {
self.host.active = active; self.host.active = active;
self.host.max = max; self.host.max = max;
if !self.host.viewers.contains(&id) {
notify(
"PixelPass — viewer connected",
format!("endpoint {} is now watching ({active}/{max})", short_id(&id)),
);
self.host.viewers.push(id);
}
}
ChildEvent::ViewerLeft { id, active, max } => {
self.host.active = active;
self.host.max = max;
if self.host.viewers.iter().any(|v| v == &id) {
notify(
"PixelPass — viewer disconnected",
format!("endpoint {} left ({active}/{max})", short_id(&id)),
);
self.host.viewers.retain(|v| v != &id);
}
} }
ChildEvent::Capture { state } => { ChildEvent::Capture { state } => {
self.host.capturing = matches!(state, child::CaptureState::Started); self.host.capturing = matches!(state, child::CaptureState::Started);
+97 -20
View File
@@ -10,6 +10,7 @@ use anyhow::{Result, bail};
use iroh::endpoint::{Connection, presets}; use iroh::endpoint::{Connection, presets};
use iroh::{Endpoint, EndpointAddr}; use iroh::{Endpoint, EndpointAddr};
use iroh_tickets::endpoint::EndpointTicket; use iroh_tickets::endpoint::EndpointTicket;
use std::collections::HashMap;
use std::time::Duration; use std::time::Duration;
use tokio::sync::{mpsc, oneshot}; use tokio::sync::{mpsc, oneshot};
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
@@ -23,15 +24,28 @@ use crate::common::{
use self::pipeline::CaptureHandle; use self::pipeline::CaptureHandle;
use self::quality::EffectiveQuality; use self::quality::EffectiveQuality;
/// Messages from per-viewer tasks to the capture supervisor. /// Messages from per-viewer tasks (and the GUI command channel) to the
/// capture supervisor.
// The shared `Viewer` suffix is the point — these are all viewer lifecycle
// messages — so keep the descriptive names.
#[allow(clippy::enum_variant_names)]
enum SupervisorMsg { enum SupervisorMsg {
/// A new viewer wants in. Supervisor replies with the local capture /// A new viewer wants in. Supervisor replies with the local capture HTTP
/// HTTP port to connect to, or an error string if the host is full or /// port to connect to, or an error string if the host is full or capture
/// capture spawn failed. /// spawn failed. `cancel` is the viewer's own token — the supervisor keeps
AddViewer(oneshot::Sender<Result<u16, String>>), /// it so a later `KickViewer` can tear this viewer's stream down.
AddViewer {
id: String,
cancel: CancellationToken,
reply: oneshot::Sender<Result<u16, String>>,
},
/// A viewer's session ended. Supervisor decrements the count and tears /// A viewer's session ended. Supervisor decrements the count and tears
/// down capture if it just hit zero. /// down capture if it just hit zero.
RemoveViewer, RemoveViewer { id: String },
/// Host asked (via the GUI command channel) to disconnect a viewer by
/// endpoint id. Cancels that viewer's token; the normal teardown path then
/// emits the `ViewerLeft`.
KickViewer { id: String },
} }
pub async fn run(opts: HostOpts) -> Result<()> { pub async fn run(opts: HostOpts) -> Result<()> {
@@ -113,6 +127,15 @@ pub async fn run(opts: HostOpts) -> Result<()> {
sup_rx, sup_rx,
)); ));
// Command channel for the GUI front-end: read `kick <endpoint-id>` lines
// off stdin. Only when machine-driven (`--output json`) — a human host has
// nothing to type here, and we don't want to swallow terminal input. Runs
// on a plain OS thread (not a tokio task) so a read parked on stdin can't
// hold up runtime shutdown on Ctrl+C; the thread dies with the process.
if output::json_enabled() {
spawn_kick_listener(sup_tx.clone());
}
accept_loop(&endpoint, sup_tx.clone(), cancel.clone()).await; accept_loop(&endpoint, sup_tx.clone(), cancel.clone()).await;
drop(sup_tx); drop(sup_tx);
@@ -159,9 +182,18 @@ async fn handle_peer(
cancel: CancellationToken, cancel: CancellationToken,
) { ) {
let remote = conn.remote_id(); let remote = conn.remote_id();
let id = remote.to_string();
// This viewer's own kill switch: the supervisor holds a clone so a `kick`
// can cancel it, and the stream select! below watches it.
let peer_cancel = CancellationToken::new();
let (reply_tx, reply_rx) = oneshot::channel(); let (reply_tx, reply_rx) = oneshot::channel();
if sup_tx.send(SupervisorMsg::AddViewer(reply_tx)).await.is_err() { let add = SupervisorMsg::AddViewer {
id: id.clone(),
cancel: peer_cancel.clone(),
reply: reply_tx,
};
if sup_tx.send(add).await.is_err() {
tracing::warn!(%remote, "supervisor channel closed; dropping peer"); tracing::warn!(%remote, "supervisor channel closed; dropping peer");
return; return;
} }
@@ -182,7 +214,7 @@ async fn handle_peer(
Ok(s) => s, Ok(s) => s,
Err(e) => { Err(e) => {
tracing::warn!(%remote, "accept_bi failed: {e:#}"); tracing::warn!(%remote, "accept_bi failed: {e:#}");
let _ = sup_tx.send(SupervisorMsg::RemoveViewer).await; let _ = sup_tx.send(SupervisorMsg::RemoveViewer { id }).await;
return; return;
} }
}; };
@@ -193,7 +225,7 @@ async fn handle_peer(
Ok(t) => t, Ok(t) => t,
Err(e) => { Err(e) => {
tracing::warn!(%remote, "connect_to_capture failed: {e:#}"); tracing::warn!(%remote, "connect_to_capture failed: {e:#}");
let _ = sup_tx.send(SupervisorMsg::RemoveViewer).await; let _ = sup_tx.send(SupervisorMsg::RemoveViewer { id }).await;
return; return;
} }
}; };
@@ -207,10 +239,34 @@ async fn handle_peer(
_ = cancel.cancelled() => { _ = cancel.cancelled() => {
tracing::info!(%remote, "cancellation during stream"); tracing::info!(%remote, "cancellation during stream");
} }
_ = peer_cancel.cancelled() => {
tracing::info!(%remote, "kicked by host");
}
} }
eprintln!("[pixelpass] viewer disconnected: {remote}"); eprintln!("[pixelpass] viewer disconnected: {remote}");
let _ = sup_tx.send(SupervisorMsg::RemoveViewer).await; let _ = sup_tx.send(SupervisorMsg::RemoveViewer { id }).await;
}
/// Read `kick <endpoint-id>` lines off stdin and forward them to the
/// supervisor. Runs on a detached OS thread (see the call site for why). Ends
/// when stdin hits EOF (the GUI closed the pipe) or the supervisor is gone.
fn spawn_kick_listener(sup_tx: mpsc::Sender<SupervisorMsg>) {
use std::io::BufRead;
std::thread::spawn(move || {
let stdin = std::io::stdin();
for line in stdin.lock().lines().map_while(Result::ok) {
let Some(id) = line.trim().strip_prefix("kick ") else {
continue;
};
let msg = SupervisorMsg::KickViewer { id: id.trim().to_string() };
// blocking_send is valid here: this is a plain thread, not inside
// the tokio runtime. An Err means the supervisor closed — stop.
if sup_tx.blocking_send(msg).is_err() {
break;
}
}
});
} }
/// Owns the single shared CaptureHandle and the active viewer count. Spawns /// Owns the single shared CaptureHandle and the active viewer count. Spawns
@@ -225,11 +281,15 @@ async fn supervise(
mut rx: mpsc::Receiver<SupervisorMsg>, mut rx: mpsc::Receiver<SupervisorMsg>,
) { ) {
let mut handle: Option<CaptureHandle> = None; let mut handle: Option<CaptureHandle> = None;
let mut count: u32 = 0; // Active viewers, keyed by endpoint id, holding each one's kill switch.
// The count is just `viewers.len()`. (A given endpoint connecting twice is
// a non-case here: each viewer process uses a fresh ephemeral identity.)
let mut viewers: HashMap<String, CancellationToken> = HashMap::new();
while let Some(msg) = rx.recv().await { while let Some(msg) = rx.recv().await {
match msg { match msg {
SupervisorMsg::AddViewer(reply) => { SupervisorMsg::AddViewer { id, cancel, reply } => {
let count = viewers.len() as u32;
if count >= max_viewers { if count >= max_viewers {
let reason = let reason =
format!("host is full ({count} of {max_viewers} viewers connected)"); format!("host is full ({count} of {max_viewers} viewers connected)");
@@ -255,16 +315,22 @@ async fn supervise(
} }
let port = handle.as_ref().expect("handle was just set").local_port(); let port = handle.as_ref().expect("handle was just set").local_port();
count += 1; viewers.insert(id.clone(), cancel);
let active = viewers.len() as u32;
let _ = reply.send(Ok(port)); let _ = reply.send(Ok(port));
output::emit(output::Event::ViewerCount { active: count, max: max_viewers }); output::emit(output::Event::ViewerJoined { id: &id, active, max: max_viewers });
tracing::info!(active = count, cap = max_viewers, "viewer joined"); tracing::info!(active, cap = max_viewers, "viewer joined");
} }
SupervisorMsg::RemoveViewer => { SupervisorMsg::RemoveViewer { id } => {
count = count.saturating_sub(1); // A given viewer task only ever sends RemoveViewer once, but the
output::emit(output::Event::ViewerCount { active: count, max: max_viewers }); // map remove is the source of truth either way.
tracing::info!(active = count, cap = max_viewers, "viewer left"); if viewers.remove(&id).is_none() {
if count == 0 continue;
}
let active = viewers.len() as u32;
output::emit(output::Event::ViewerLeft { id: &id, active, max: max_viewers });
tracing::info!(active, cap = max_viewers, "viewer left");
if active == 0
&& let Some(h) = handle.take() && let Some(h) = handle.take()
{ {
tracing::info!("last viewer left — tearing down capture"); tracing::info!("last viewer left — tearing down capture");
@@ -274,6 +340,17 @@ async fn supervise(
}); });
} }
} }
SupervisorMsg::KickViewer { id } => {
match viewers.get(&id) {
// Cancel the viewer's token; its handle_peer select! wakes,
// sends RemoveViewer, and the leave is emitted there.
Some(cancel) => {
tracing::info!(%id, "kicking viewer");
cancel.cancel();
}
None => tracing::debug!(%id, "kick for unknown/already-gone viewer"),
}
}
} }
} }