probeHidShiftPolling function
Runs entry in a fresh isolate and waits timeout for its
completion ACK. True means the HID read COMPLETED in time — the
session is healthy enough to poll; a hang (a GUI-less session where
CoreGraphics blocks) answers false. Any message counts: the payload
value is ignored. The isolate is killed unconditionally — a wedged
probe never leaks.
Implementation
Future<bool> probeHidShiftPolling({
void Function(SendPort port)? entry,
Duration timeout = const Duration(milliseconds: 300),
}) async {
final port = ReceivePort();
final isolate = await Isolate.spawn(entry ?? _hidProbeEntry, port.sendPort);
try {
await port.first.timeout(timeout);
return true; // any message = the HID read completed in time
} on TimeoutException {
return false;
} finally {
port.close();
isolate.kill(priority: Isolate.immediate);
}
}