parseThemeDeepLink function

SharePayload? parseThemeDeepLink(
  1. String link
)

Parses a theme deep link (calsee://t/CODE, or the pre-release infinitecalc://t/CODE; scheme and host lowercase, the code may be any case) or a web link (https://calsee.tech/t/CODE). Returns null for anything else or a bad code.

Implementation

SharePayload? parseThemeDeepLink(String link) {
  final uri = Uri.tryParse(link.trim());
  if (uri == null) return null;
  String? code;
  if ((uri.scheme == deepLinkScheme || uri.scheme == legacyDeepLinkScheme) &&
      uri.host == deepLinkThemeHost) {
    final segs = uri.pathSegments.where((s) => s.isNotEmpty).toList();
    if (segs.length == 1) code = segs.single;
  } else if (uri.scheme == 'https' && deepLinkWebHosts.contains(uri.host)) {
    final segs = uri.pathSegments.where((s) => s.isNotEmpty).toList();
    if (segs.length == 2 && segs[0] == deepLinkThemeHost) code = segs[1];
  }
  return code == null ? null : decodeShareCode(code);
}