Skip to content

Rust reimplementation of VolumeAssistant.App for minimal memory footprint#10

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/recreate-volumeassistant-app
Draft

Rust reimplementation of VolumeAssistant.App for minimal memory footprint#10
Copilot wants to merge 5 commits intomainfrom
copilot/recreate-volumeassistant-app

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

The .NET WinForms tray app carries significant runtime overhead (~30–80 MB RAM, ~5–15 MB binary). This adds a Rust reimplementation targeting the smallest possible footprint.

New project: src/VolumeAssistant.App.Rust/

Full feature-parity Rust port compiled to x86_64-pc-windows-gnu native PE, no .NET or C++ runtime dependency.

Metric .NET Native AOT Rust
Binary size ~5–15 MB ~710 KB
Idle RAM ~30–80 MB ~2–5 MB
Runtime required None None

Key implementation choices

  • Win32 API directly via windows-sys (raw FFI, no abstraction overhead) — tray icon (Shell_NotifyIconW), main window, GDI icon rendering
  • WASAPI via manually-defined COM vtables (IMMDeviceEnumeratorIAudioEndpointVolume) — no NAudio dependency
  • Cambridge Audio WebSocket client (tungstenite, blocking I/O in a dedicated thread) with exponential-backoff reconnect
  • Matter UDP server (port 5540) + mDNS advertising (mdns-sd) — matching C# behaviour
  • Threads + Arc<Mutex<AppState>> instead of async runtime — eliminates tokio overhead
  • appsettings.json parsed with identical JSON shape to the C# app (VolumeAssistant.Matter nesting, CambridgeAudio, App sections)
  • Log ring buffer uses VecDeque for O(1) front-removal

Release profile

[profile.release]
opt-level = "z"       # optimize for size
lto = true
codegen-units = 1
panic = "abort"
strip = true

Build

rustup target add x86_64-pc-windows-gnu
cargo build --release --target x86_64-pc-windows-gnu \
  --manifest-path src/VolumeAssistant.App.Rust/Cargo.toml

Other changes

  • .gitignore — excludes src/VolumeAssistant.App.Rust/target/
  • README.md — documents Rust app, build instructions, footprint comparison table

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI and others added 4 commits March 17, 2026 22:27
Creates VolumeAssistant.App.Rust — a complete Rust project that
cross-compiles from Linux to Windows using MinGW.

Modules:
- config: JSON config deserialization via serde
- coordinator: shared AppState with Cambridge Audio status + logs
- audio: WASAPI via raw COM vtables (windows-sys 0.59 pointer handles)
- cambridge: WebSocket client (tungstenite 0.26 + handshake feature)
- matter: stub UDP server, TLV encoder, device model
- mdns: mDNS advertisement via mdns-sd 0.12
- tray: Win32 system tray using Shell_NotifyIconW
- window: main window with tab control, labels, listbox
- icon: GDI-drawn volume dial icon

Key fixes applied during compilation:
- Binary name uses VolumeAssistantApp (dots not allowed in crate names)
- tungstenite requires features=["handshake"] for connect()
- Message::text() used instead of Message::Text(s.into())
- Shell_NotifyIconW/NIM_ADD/NIM_DELETE imported from Win32::UI::Shell
- TlvElement derives PartialEq for TlvType derive to work
- windows-sys 0.59 handles are *mut c_void, not isize

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- icon.rs: use screen DC for CreateCompatibleBitmap to get color bitmap
- matter/protocol.rs: clamp TLV string/bytestring length to 255 bytes
- window/mod.rs: pre-collect all wide strings before LB_ADDSTRING calls
- mdns.rs: replace infinite sleep loop with thread::park()
- tray.rs: document intentional Arc::into_raw lifetime pattern
- Remove unused imports and suppress only non_snake_case naming warnings

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: simonjlawson <7670716+simonjlawson@users.noreply.github.com>
Copilot AI changed the title [WIP] Recreate VolumeAssistant.App with minimal memory footprint Rust reimplementation of VolumeAssistant.App for minimal memory footprint Mar 17, 2026
Copilot AI requested a review from simonjlawson March 17, 2026 22:39
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.

2 participants