🕵️ SicherheitslückenWhat continuous operational resilience looks like under DORA(09.09.2026 um 17:53 Uhr)
🔧 AI Nachrichten OpenAI seeks tougher AI rules. CIOs may feel the ripple effects(10.09.2026 um 12:11 Uhr)
🔧 AI Nachrichten Mistral valued at €21bn after €3bn Series D funding round(08.09.2026 um 10:19 Uhr)
🪟 Windows TippsWindows XP's Cursor Indicator Is Getting a Windows 11 Refresh(25.08.2026 um 13:00 Uhr)
🕵️ SicherheitslückenWhat continuous operational resilience looks like under DORA(09.09.2026 um 17:53 Uhr)
🔧 AI Nachrichten OpenAI seeks tougher AI rules. CIOs may feel the ripple effects(10.09.2026 um 12:11 Uhr)
🔧 AI Nachrichten Mistral valued at €21bn after €3bn Series D funding round(08.09.2026 um 10:19 Uhr)
🪟 Windows TippsWindows XP's Cursor Indicator Is Getting a Windows 11 Refresh(25.08.2026 um 13:00 Uhr)

🔧 Programmierung 🕛 vor 2 Monaten 3 Min Lesezeit
0

USB Hotplug Detection in Rust on macOS — Reacting to Device Connect/Disconnect

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

All tests run on an 8-year-old MacBook Air. All results from shipping 7 Mac apps as a solo developer. No sponsored opinion.



HiyokoAutoSync and HiyokoMTP both react instantly when an Android device is connected. No polling. No "refresh" button. Just plug in and it works. Here's how USB hotplug detection works in Rust on macOS.









The approach: nusb hotplug API



nusb provides a hotplug watch API that wraps macOS's IOKit USB notifications:




CODE
use nusb::hotplug::{HotplugEvent, HotplugWatch};

fn watch_usb_devices(app_handle: AppHandle) {
std::thread::spawn(move || {
let watch = nusb::watch_devices().expect("Failed to start USB watch");

for event in watch {
match event {
HotplugEvent::Connected(device_info) => {
if is_android_device(&device_info) {
app_handle.emit("device-connected", DeviceInfo {
name: device_info.product_string().unwrap_or_default(),
vendor_id: device_info.vendor_id(),
product_id: device_info.product_id(),
}).ok();
}
}
HotplugEvent::Disconnected(device_info) => {
if is_android_device(&device_info) {
app_handle.emit("device-disconnected", ()).ok();
}
}
}
}
});
}






The watch runs in a dedicated thread — it's a blocking iterator. Emit Tauri events to notify the frontend.









Identifying Android devices



Android devices have well-known vendor IDs. A non-exhaustive list:




CODE
const ANDROID_VENDOR_IDS: &[u16] = &[
0x18D1, // Google
0x04E8, // Samsung
0x22D9, // OPPO/OnePlus
0x2717, // Xiaomi
0x12D1, // Huawei
0x0BB4, // HTC
0x1004, // LG
0x0FCE, // Sony
];

fn is_android_device(info: &nusb::DeviceInfo) -> bool {
ANDROID_VENDOR_IDS.contains(&info.vendor_id())
}






This catches most Android devices. ADB provides a more reliable check, but vendor ID filtering is fast and works before ADB connects.









ADB confirmation



After detecting a USB device with a known Android vendor ID, confirm with ADB:




CODE
async fn confirm_adb_device() -> bool {
let output = Command::new("adb")
.args(["devices", "-l"])
.output()
.await;

match output {
Ok(out) => {
let stdout = String::from_utf8_lossy(&out.stdout);
stdout.lines()
.skip(1) // skip "List of devices attached"
.any(|line| line.contains("device"))
}
Err(_) => false,
}
}






Vendor ID for fast detection, ADB for confirmation. Two-step keeps the UX instant while ensuring accuracy.









The frontend experience



The user plugs in their Android device. Within 1-2 seconds:




  1. USB hotplug fires

  2. ADB confirms the device

  3. Frontend receives device-connected event

  4. UI updates to show the device and enable sync



No button. No refresh. It just works.






TL;DR: Use nusb::watch_devices() in a dedicated thread to get IOKit USB hotplug events on macOS. Filter by vendor ID for instant detection, then confirm with adb devices for accuracy. Emit Tauri events to the frontend — plug in and it works within 1-2 seconds, no refresh button needed.






If this was useful, a ❤️ helps more than you'd think — thanks!



Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Sam Altman calls GPT-6 Astra rollout ‘messy’ as enterprise users wait for access
1 Quelle
Swiss government explores replacing Microsoft 365 with open-source software
1 Quelle
What continuous operational resilience looks like under DORA
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten USB Hotplug Detection in Rust on macOS — Reacting to Device Connect/Disconnect

Thematisch verwandte Begriffe: Hotplug, Detection, Rust, macOS · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...