findAvailableIDE method

Future<DetectedIDEInfo?> findAvailableIDE({
  1. Duration timeout = const Duration(seconds: 30),
  2. Duration pollInterval = const Duration(seconds: 1),
})

Finds an available IDE with polling.

Implementation

Future<DetectedIDEInfo?> findAvailableIDE({
  Duration timeout = const Duration(seconds: 30),
  Duration pollInterval = const Duration(seconds: 1),
}) async {
  _currentSearchAbort?.complete();
  final abort = Completer<void>();
  _currentSearchAbort = abort;

  await cleanupStaleIdeLockfiles();
  final stopwatch = Stopwatch()..start();

  while (stopwatch.elapsed < timeout && !abort.isCompleted) {
    final ides = await detectIDEs();
    if (abort.isCompleted) return null;
    if (ides.length == 1) return ides.first;
    await Future.delayed(pollInterval);
  }
  return null;
}