Move SSD native detection checks to typed Kotlin

ober

eaf1e41374bf1d0dc9c52ed3f2021ea4fc62bf51

diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index 7c882ad..b6b2931 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -1187,12 +1187,21 @@
     (typed-kotlin-file "com/sfb/ssdreview/NativeDetection.kt"
       (typed-library (com sfb ssdreview)
         (export make-NativeDetection NativeDetection?
-                NativeDetection-cells NativeDetection-groups)
+                NativeDetection-cells NativeDetection-groups
+                nativeDetectionPresent nativeDetectionOrEmpty)
         (type SsdCell)
         (type SsdGroup)
         (record NativeDetection
           ((cells : (MutableList SsdCell))
-           (groups : (MutableList SsdGroup))))))
+           (groups : (MutableList SsdGroup))))
+        (def (nativeDetectionPresent (detection : (Nullable NativeDetection))) : Bool
+          (not (nullable-null? detection)))
+        (def (nativeDetectionOrEmpty (detection : (Nullable NativeDetection))) : NativeDetection
+          (if (nullable-null? detection)
+            (make-NativeDetection
+              (mutable-list-empty SsdCell)
+              (mutable-list-empty SsdGroup))
+            (nullable-get detection)))))
 
     (typed-kotlin-file "com/sfb/ssdreview/ViewportState.kt"
       (typed-library (com sfb ssdreview)
@@ -6711,8 +6720,9 @@
        "                    }"
        "                    val nativeDetection = SsdVisionBridge.detect(bitmap)"
        "                    val detectedCells: List<SsdCell>"
-       "                    if (nativeDetection != null) {"
-       "                        detectedCells = nativeDetection.cells"
+       "                    if (nativeDetectionPresent(nativeDetection)) {"
+       "                        val rustDetection = nativeDetectionOrEmpty(nativeDetection)"
+       "                        detectedCells = rustDetection.cells"
        "                        detectorNote = \", rust detector\""
        "                        detectorSource = detectorSourceWithTruth(forceDetect, existingTruthGroupCount, \"forced-rust-plus-truth\", \"rust-detector\")"
        "                    } else {"