Recognise wrong QR code type in every scanner

When a scanner is shown a QR code of a different kind than it expects, it
now tells the user what they actually scanned and where to use it, instead
of a generic "invalid" message.

Link recognition is done in the core: a new chat_check_link export
classifies a scanned string using the same decoders the views use to
process the links (connection link, server address, migration file link,
desktop address, security code), returning a typed result. Each scanner
calls checkLink first; the expected type proceeds to that scanner's normal
success path, a recognised-but-wrong type shows a shared wrong-type alert
saying what it is and where to use it, and an unrecognised string falls
back to that scanner's own contextual error. Mirrored on Android, desktop
and iOS.

Note: the iOS Swift was written without an Xcode toolchain and is not yet
compiled — needs a Mac/CI build to verify.
This commit is contained in:
Narasimha-sc
2026-07-21 12:33:37 +00:00
parent 2ea5940e81
commit fd34525aa3
31 changed files with 1261 additions and 142 deletions
+32
View File
@@ -187,6 +187,38 @@ struct ParsedServerAddress: Decodable {
var parseError: String
}
// The kind of SimpleX QR code / link a scanned string turned out to be, as
// determined by the core (chat_check_link). Public: it crosses the
// SimpleXChat -> app module boundary. Case names and the connection payload
// label must match the Haskell ScannedLinkType wire tags.
public enum ScannedLinkType: Decodable {
case connection(linkType: SimplexLinkType)
case server
case fileDescription
case desktopCtrl
case verificationCode
}
// Wrapper stays internal it never leaves the framework. A missing linkType
// key (the "not a SimpleX code" case) decodes to nil.
struct CheckedLink: Decodable {
var linkType: ScannedLinkType?
}
public func checkLink(_ s: String) -> ScannedLinkType? {
var c = s.cString(using: .utf8)!
if let cjson = chat_check_link(&c) {
if let d = dataFromCString(cjson) {
do {
return try jsonDecoder.decode(CheckedLink.self, from: d).linkType
} catch {
logger.error("checkLink jsonDecoder.decode error: \(error.localizedDescription)")
}
}
}
return nil
}
public func parseSanitizeUri(_ s: String, safe: Bool) -> ParsedUri? {
var c = s.cString(using: .utf8)!
if let cjson = chat_parse_uri(&c, safe ? 1 : 0) {