1 package host.exp.exponent 2 3 import expo.modules.manifests.core.Manifest 4 import expo.modules.updates.db.entity.UpdateEntity 5 import expo.modules.updates.selectionpolicy.LauncherSelectionPolicy 6 import expo.modules.updates.selectionpolicy.SelectionPolicies 7 import org.json.JSONObject 8 9 /** 10 * LauncherSelectionPolicy similar to LauncherSelectionPolicyFilterAware but specifically for 11 * Expo Go which uses a Expo-Go-specific field to determine compatibility. 12 */ 13 class ExpoGoLauncherSelectionPolicyFilterAware(private val sdkVersions: List<String>) : 14 LauncherSelectionPolicy { selectUpdateToLaunchnull15 override fun selectUpdateToLaunch( 16 updates: List<UpdateEntity>, 17 filters: JSONObject? 18 ): UpdateEntity? { 19 var updateToLaunch: UpdateEntity? = null 20 for (update in updates) { 21 val manifest = Manifest.fromManifestJson(update.manifest) 22 if (!sdkVersions.contains(manifest.getExpoGoSDKVersion()) || !SelectionPolicies.matchesFilters( 23 update, 24 filters 25 ) 26 ) { 27 continue 28 } 29 if (updateToLaunch == null || updateToLaunch.commitTime.before(update.commitTime)) { 30 updateToLaunch = update 31 } 32 } 33 return updateToLaunch 34 } 35 } 36