start method

void start({
  1. required String projectPath,
})

Implementation

void start({required String projectPath}) {
  if (_watchSubscription != null) {
    _watchSubscription?.cancel();
  }

  final dir = Directory(projectPath);

  if (!dir.existsSync()) {
    throw FileSystemException('Project path does not exist', projectPath);
  }

  _watchSubscription = dir.watch(recursive: false).listen((event) {
    final fileName = _getFileName(event.path);
    final fileType = _watchedFiles[fileName];

    if (fileType != null) {
      final eventType = _mapEventType(event);

      // Debounce grouped changes (e.g. save = write+move)
      _debounceTimer?.cancel();
      _debounceTimer = Timer(debounceDuration, () {
        _controller.add(ProjectFileEvent(fileType, eventType, event.path));
      });
    }
  });
}