parseThemeDeepLink function
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. A name query parameter becomes
SharePayload.name (trimmed to ThemeIntent.maxNameWords words).
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];
}
if (code == null) return null;
final payload = decodeShareCode(code);
if (payload == null) return null;
final name = ThemeIntent(name: uri.queryParameters['name']).name;
return name == null ? payload : payload.withName(name);
}