idleMilliseconds method
The Idle duration in milliseconds.
Throws UnsupportedError when isSupported is false. Implementations
that are supported must not throw for ordinary OS failures — they report
0 (treat the user as active) so a transient failure cannot silently
end monitoring.
Implementation
@override
int idleMilliseconds() {
// Freed unconditionally: this runs on every poll for the lifetime of the
// app, so a leaked 8 bytes per call is a leak that grows all day. `calloc`
// rather than `malloc` so the tick field is zero even on the failure path,
// where it is read but ignored.
final info = calloc<_LastInputInfo>();
try {
info.ref.cbSize = sizeOf<_LastInputInfo>();
return idleFromTicks(
succeeded: _getLastInputInfo(info) != 0,
tickCount64: _getTickCount64(),
lastInputTick: info.ref.dwTime,
);
} finally {
calloc.free(info);
}
}