handleDeepLinkUri function

Future<int> handleDeepLinkUri(
  1. String uri
)

Handle an incoming deep link URI. Called from the CLI entry point when --handle-uri is passed.

Implementation

Future<int> handleDeepLinkUri(String uri) async {
  _logDebug('Handling deep link URI: $uri');

  DeepLinkAction action;
  try {
    action = parseDeepLink(uri);
  } catch (e) {
    stderr.writeln('Deep link error: $e');
    return 1;
  }

  _logDebug('Parsed deep link action: $action');

  // Resolve working directory
  final cwd = action.cwd ?? _homeDir();

  // Read FETCH_HEAD age for repo links
  DateTime? lastFetch;
  if (action.repo != null) {
    lastFetch = await readLastFetchTime(cwd);
  }

  final launched = await launchInTerminal(
    Platform.resolvedExecutable,
    DeepLinkAction(query: action.query, cwd: cwd, repo: action.repo),
  );

  if (!launched) {
    stderr.writeln(
      'Failed to open a terminal. Make sure a supported terminal emulator is installed.',
    );
    return 1;
  }

  return 0;
}