watch method

  1. @override
Stream<TomFileChange>? watch({
  1. bool descend(
    1. String path
    )?,
})
override

Changes under root, or null when the platform refuses to watch.

descend is asked, with a folder's path relative to the root, whether changes inside it are wanted, so a folder a tree does not enter need not be watched. An implementation may watch more than it is asked to — a native recursive watch costs the same either way — but never less.

Implementation

@override
Stream<TomFileChange>? watch({bool Function(String path)? descend}) {
  if (!FileSystemEntity.isWatchSupported) return null;
  TomFileChange change(String local) =>
      TomFileChange(_relative(local), Uri.file(local));
  if (_watchEachDirectory) {
    return TomDirectoryWatches(
      rootPath,
      descend: descend ?? (_) => true,
    ).stream.map(change);
  }
  try {
    return Directory(
      rootPath,
    ).watch(recursive: true).map((event) => change(event.path));
  } on FileSystemException {
    return null;
  }
}