schedulePeriodicPruning function
Re-runs pruneOldSelections every interval for as long as the
returned Timer is alive.
The bridge is meant to be left running for an entire dev session
(the README says so explicitly), but pruning only ran once, at startup —
so .ref/ grew without bound for as long as the process stayed up, only
getting cleaned out on the next restart. A long session tapping
through a real app accumulates a .json+.png pair per tap; this
closes that gap by pruning on a timer instead of only once. Interval is
deliberately coarse: this is disk housekeeping racing nothing, not a
latency-sensitive path.
Implementation
Timer schedulePeriodicPruning(
Directory refDir, {
Duration interval = const Duration(minutes: 10),
Duration maxAge = const Duration(hours: 1),
}) {
return Timer.periodic(interval, (_) => pruneOldSelections(refDir, maxAge: maxAge));
}