ReviewOS

also looking at this

craft-native/craft

fix(ios): no gated dispatcher arm can hang the page any more (58 → 0)

#120
Merged glennmichael123 wants to merge fix/ios-gated-arms-reject into main
1 file +298 -106

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

packages/ios/templates/CraftApp.swiftmodified+60-0
Changes to packages/ios/templates/CraftApp.swift
@@ -568,6 +568,8 @@ struct CraftWebView: UIViewRepresentable {
568568 if config.enableHaptics {
569569 let style = body["style"] as? String ?? "medium"
570570 triggerHaptic(style: style)
571 } else {
572 rejectCallback(callbackId, error: "Haptics is disabled", code: "CAPABILITY_DISABLED")
571573 }
572574 case "share":
573575 if config.enableShare {
@@ -585,20 +587,28 @@ struct CraftWebView: UIViewRepresentable {
585587 if config.enableCamera {
586588 pendingCallbackId = callbackId
587589 openCamera()
590 } else {
591 rejectCallback(callbackId, error: "Camera is disabled", code: "CAPABILITY_DISABLED")
588592 }
589593 case "pickImage":
590594 if config.enableCamera {
591595 pendingCallbackId = callbackId
592596 pickImage()
597 } else {
598 rejectCallback(callbackId, error: "Camera is disabled", code: "CAPABILITY_DISABLED")
593599 }
594600 case "authenticate":
595601 if config.enableBiometric {
596602 let reason = body["reason"] as? String ?? "Authenticate to continue"
597603 authenticate(reason: reason, callbackId: callbackId)
604 } else {
605 rejectCallback(callbackId, error: "Biometric authentication is disabled", code: "CAPABILITY_DISABLED")
598606 }
599607 case "registerPush":
600608 if config.enablePushNotifications {
601609 registerPushNotifications(callbackId: callbackId)
610 } else {
611 rejectCallback(callbackId, error: "Push notifications are disabled", code: "CAPABILITY_DISABLED")
602612 }
603613 case "secureSet":
604614 if config.enableSecureStorage,
@@ -688,6 +698,8 @@ struct CraftWebView: UIViewRepresentable {
688698 if config.enableClipboard {
689699 let text = UIPasteboard.general.string ?? ""
690700 resolveCallback(callbackId, result: text)
701 } else {
702 rejectCallback(callbackId, error: "Clipboard is disabled", code: "CAPABILITY_DISABLED")
691703 }
692704 // Device Info
693705 case "getDeviceInfo":
@@ -735,6 +747,8 @@ struct CraftWebView: UIViewRepresentable {
735747 case "getContacts":
736748 if config.enableContacts {
737749 getContacts(callbackId: callbackId)
750 } else {
751 rejectCallback(callbackId, error: "Contacts access is disabled", code: "CAPABILITY_DISABLED")
738752 }
739753 case "addContact":
740754 if config.enableContacts,
@@ -748,6 +762,8 @@ struct CraftWebView: UIViewRepresentable {
748762 let startDate = body["startDate"] as? Double
749763 let endDate = body["endDate"] as? Double
750764 getCalendarEvents(startDate: startDate, endDate: endDate, callbackId: callbackId)
765 } else {
766 rejectCallback(callbackId, error: "Calendar access is disabled", code: "CAPABILITY_DISABLED")
751767 }
752768 case "createCalendarEvent":
753769 if config.enableCalendar,
@@ -774,10 +790,14 @@ struct CraftWebView: UIViewRepresentable {
774790 case "cancelAllNotifications":
775791 if config.enableLocalNotifications {
776792 cancelAllLocalNotifications(callbackId: callbackId)
793 } else {
794 rejectCallback(callbackId, error: "Local notifications are disabled", code: "CAPABILITY_DISABLED")
777795 }
778796 case "getPendingNotifications":
779797 if config.enableLocalNotifications {
780798 getPendingNotifications(callbackId: callbackId)
799 } else {
800 rejectCallback(callbackId, error: "Local notifications are disabled", code: "CAPABILITY_DISABLED")
781801 }
782802
783803 // MARK: - Deep Links
@@ -785,6 +805,8 @@ struct CraftWebView: UIViewRepresentable {
785805 if config.enableDeepLinks {
786806 // Handler is registered in JS
787807 resolveCallback(callbackId, result: true)
808 } else {
809 rejectCallback(callbackId, error: "Deep links are disabled", code: "CAPABILITY_DISABLED")
788810 }
789811 case "getInitialURL":
790812 if config.enableDeepLinks {
@@ -799,6 +821,8 @@ struct CraftWebView: UIViewRepresentable {
799821 } else {
800822 resolveCallback(callbackId, result: NSNull())
801823 }
824 } else {
825 rejectCallback(callbackId, error: "Deep links are disabled", code: "CAPABILITY_DISABLED")
802826 }
803827
804828 // MARK: - In-App Purchase
@@ -815,6 +839,8 @@ struct CraftWebView: UIViewRepresentable {
815839 case "restorePurchases":
816840 if config.enableInAppPurchase {
817841 restorePurchases(callbackId: callbackId)
842 } else {
843 rejectCallback(callbackId, error: "In-app purchase is disabled", code: "CAPABILITY_DISABLED")
818844 }
819845
820846 // MARK: - Keep Awake
@@ -833,12 +859,16 @@ struct CraftWebView: UIViewRepresentable {
833859 case "unlockOrientation":
834860 if config.enableOrientationLock {
835861 unlockOrientation(callbackId: callbackId)
862 } else {
863 rejectCallback(callbackId, error: "Orientation lock is disabled", code: "CAPABILITY_DISABLED")
836864 }
837865
838866 // MARK: - QR/Barcode Scanner
839867 case "scanQRCode":
840868 if config.enableQRScanner {
841869 scanQRCode(callbackId: callbackId)
870 } else {
871 rejectCallback(callbackId, error: "QR scanning is disabled", code: "CAPABILITY_DISABLED")
842872 }
843873
844874 // MARK: - File Picker
@@ -846,6 +876,8 @@ struct CraftWebView: UIViewRepresentable {
846876 if config.enableFilePicker {
847877 let types = body["types"] as? [String]
848878 pickFile(types: types, callbackId: callbackId)
879 } else {
880 rejectCallback(callbackId, error: "File picker is disabled", code: "CAPABILITY_DISABLED")
849881 }
850882
851883 // MARK: - File Download
@@ -866,22 +898,30 @@ struct CraftWebView: UIViewRepresentable {
866898 case "signInWithApple":
867899 if config.enableSocialAuth {
868900 signInWithApple(callbackId: callbackId)
901 } else {
902 rejectCallback(callbackId, error: "Social sign-in is disabled", code: "CAPABILITY_DISABLED")
869903 }
870904
871905 // MARK: - Audio Recording
872906 case "startAudioRecording":
873907 if config.enableAudioRecording {
874908 startAudioRecording(callbackId: callbackId)
909 } else {
910 rejectCallback(callbackId, error: "Audio recording is disabled", code: "CAPABILITY_DISABLED")
875911 }
876912 case "stopAudioRecording":
877913 if config.enableAudioRecording {
878914 stopAudioRecording(callbackId: callbackId)
915 } else {
916 rejectCallback(callbackId, error: "Audio recording is disabled", code: "CAPABILITY_DISABLED")
879917 }
880918
881919 // MARK: - Video Recording
882920 case "startVideoRecording":
883921 if config.enableVideoRecording {
884922 startVideoRecording(callbackId: callbackId)
923 } else {
924 rejectCallback(callbackId, error: "Video recording is disabled", code: "CAPABILITY_DISABLED")
885925 }
886926
887927 // MARK: - Motion Sensors
@@ -889,6 +929,8 @@ struct CraftWebView: UIViewRepresentable {
889929 if config.enableMotionSensors {
890930 let interval = body["interval"] as? Double ?? 100
891931 startMotionUpdates(interval: interval, callbackId: callbackId)
932 } else {
933 rejectCallback(callbackId, error: "Motion sensors are disabled", code: "CAPABILITY_DISABLED")
892934 }
893935 case "stopMotionUpdates":
894936 stopMotionUpdates()
@@ -912,6 +954,8 @@ struct CraftWebView: UIViewRepresentable {
912954 case "startBluetoothScan":
913955 if config.enableBluetooth {
914956 startBluetoothScan(callbackId: callbackId)
957 } else {
958 rejectCallback(callbackId, error: "Bluetooth is disabled", code: "CAPABILITY_DISABLED")
915959 }
916960 case "stopBluetoothScan":
917961 stopBluetoothScan()
@@ -921,6 +965,8 @@ struct CraftWebView: UIViewRepresentable {
921965 case "scanNFC":
922966 if config.enableNFC {
923967 scanNFC(callbackId: callbackId)
968 } else {
969 rejectCallback(callbackId, error: "NFC is disabled", code: "CAPABILITY_DISABLED")
924970 }
925971
926972 // MARK: - Health
@@ -928,6 +974,8 @@ struct CraftWebView: UIViewRepresentable {
928974 if config.enableHealthKit {
929975 let types = body["types"] as? [String] ?? []
930976 requestHealthAuthorization(types: types, callbackId: callbackId)
977 } else {
978 rejectCallback(callbackId, error: "HealthKit is disabled", code: "CAPABILITY_DISABLED")
931979 }
932980 case "getHealthData":
933981 if config.enableHealthKit,
@@ -959,6 +1007,8 @@ struct CraftWebView: UIViewRepresentable {
9591007 case "takeScreenshot":
9601008 if config.enableScreenCapture {
9611009 takeScreenshot(callbackId: callbackId)
1010 } else {
1011 rejectCallback(callbackId, error: "Screen capture is disabled", code: "CAPABILITY_DISABLED")
9621012 }
9631013
9641014 // MARK: - Background Tasks
@@ -983,6 +1033,8 @@ struct CraftWebView: UIViewRepresentable {
9831033 case "cancelAllBackgroundTasks":
9841034 if config.enableBackgroundTasks {
9851035 cancelAllBackgroundTasks(callbackId: callbackId)
1036 } else {
1037 rejectCallback(callbackId, error: "Background tasks are disabled", code: "CAPABILITY_DISABLED")
9861038 }
9871039
9881040 // MARK: - PDF Viewer
@@ -1000,6 +1052,8 @@ struct CraftWebView: UIViewRepresentable {
10001052 if config.enableContacts {
10011053 let multiple = body["multiple"] as? Bool ?? false
10021054 pickContact(multiple: multiple, callbackId: callbackId)
1055 } else {
1056 rejectCallback(callbackId, error: "Contacts access is disabled", code: "CAPABILITY_DISABLED")
10031057 }
10041058
10051059 // MARK: - App Shortcuts
@@ -1044,10 +1098,14 @@ struct CraftWebView: UIViewRepresentable {
10441098 if config.enableAR {
10451099 let options = body["options"] as? [String: Any] ?? [:]
10461100 startAR(options: options, callbackId: callbackId)
1101 } else {
1102 rejectCallback(callbackId, error: "AR is disabled", code: "CAPABILITY_DISABLED")
10471103 }
10481104 case "stopAR":
10491105 if config.enableAR {
10501106 stopAR(callbackId: callbackId)
1107 } else {
1108 rejectCallback(callbackId, error: "AR is disabled", code: "CAPABILITY_DISABLED")
10511109 }
10521110 case "placeARObject":
10531111 if config.enableAR,
@@ -1063,6 +1121,8 @@ struct CraftWebView: UIViewRepresentable {
10631121 case "getARPlanes":
10641122 if config.enableAR {
10651123 getARPlanes(callbackId: callbackId)
1124 } else {
1125 rejectCallback(callbackId, error: "AR is disabled", code: "CAPABILITY_DISABLED")
10661126 }
10671127
10681128 // MARK: - ML (Core ML / Vision)