convertFile static method

Future<ReplayTraceConversionResult> convertFile(
  1. String tracePath, {
  2. ReplayTraceConversionOptions options = const ReplayTraceConversionOptions(),
})

Implementation

static Future<ReplayTraceConversionResult> convertFile(
  String tracePath, {
  ReplayTraceConversionOptions options = const ReplayTraceConversionOptions(),
}) async {
  final file = File(tracePath);
  if (!await file.exists()) {
    throw FileSystemException('Trace file not found', tracePath);
  }
  final lines = await file.readAsLines();
  final parsed = _parseTrace(
    lines,
    includeCustomEvents: options.includeCustomEvents,
  );
  if (!parsed.hasStructuredInput && !parsed.hasCustomEvents) {
    throw const FormatException(
      'Trace is missing structured input events. '
      'Capture a new trace with the updated TUI tracer.',
    );
  }
  final filteredEvents = parsed.events
      .where((event) {
        final from = options.fromUs;
        if (from != null && event.tsUs < from) return false;
        final to = options.toUs;
        if (to != null && event.tsUs > to) return false;
        return true;
      })
      .toList(growable: false);

  final converted = _toActions(
    filteredEvents,
    minSleepUs: math.max(0, options.minSleepUs),
    includeHoverMoves: options.includeHoverMoves,
  );
  final screenWidth = options.screenWidth > 0
      ? options.screenWidth
      : parsed.inferredScreenWidth;
  final screenHeight = options.screenHeight > 0
      ? options.screenHeight
      : parsed.inferredScreenHeight;
  final name = _resolvedScenarioName(options.name, tracePath);
  final scenario = ReplayScenario(
    name: name,
    description: options.description,
    screen: ReplayScreen(
      width: screenWidth,
      height: screenHeight,
      fixedRightWidth: math.max(0, options.fixedRightWidth),
    ),
    actions: converted.actions,
  );
  return ReplayTraceConversionResult(
    tracePath: tracePath,
    scenario: scenario,
    eventCount: filteredEvents.length,
    actionCount: converted.actions.length,
    skippedCount: converted.skippedCount,
    inferredScreenWidth: parsed.inferredScreenWidth,
    inferredScreenHeight: parsed.inferredScreenHeight,
  );
}