Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungAutomating Bug Reports with Tally and Make(22.09.2026 um 22:44 Uhr)
Sichere ProgrammierungHTB - Forest(22.09.2026 um 22:49 Uhr)
Sichere ProgrammierungYour Ports Are Lying About Your Business(22.09.2026 um 22:52 Uhr)
Sichere ProgrammierungOLTP vs. OLAP: Understanding the Foundation of Modern Data Systems(22.09.2026 um 22:54 Uhr)
Sichere ProgrammierungYour AI Meeting Assistant Is Taking Notes. Who Is Doing the Work?(22.09.2026 um 22:57 Uhr)
Sichere ProgrammierungDebuggear se va a acabar(22.09.2026 um 23:03 Uhr)
Sichere ProgrammierungAutomating Bug Reports with Tally and Make(22.09.2026 um 22:44 Uhr)
Sichere ProgrammierungHTB - Forest(22.09.2026 um 22:49 Uhr)
Sichere ProgrammierungYour Ports Are Lying About Your Business(22.09.2026 um 22:52 Uhr)
Sichere ProgrammierungOLTP vs. OLAP: Understanding the Foundation of Modern Data Systems(22.09.2026 um 22:54 Uhr)
Sichere ProgrammierungYour AI Meeting Assistant Is Taking Notes. Who Is Doing the Work?(22.09.2026 um 22:57 Uhr)
Sichere ProgrammierungDebuggear se va a acabar(22.09.2026 um 23:03 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

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

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"…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

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:




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:




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:




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!



HiyokoAutoSync | X → @hiyoyok

Ä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 ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-82000 | Adobe Experience Manager Forms JEE is affected by a Server-Side Request …
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick