mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-23 22:34:53 +00:00
fix(mobile-voice): restore camera and discovery in dev builds
This commit is contained in:
@@ -2735,14 +2735,14 @@ export default function DictationScreen() {
|
||||
scanLockRef.current = false
|
||||
const current =
|
||||
camera ??
|
||||
(await import("expo-camera")
|
||||
.catch(() => null)
|
||||
.then((mod) => {
|
||||
if (!mod) return null
|
||||
|
||||
(() => {
|
||||
try {
|
||||
// Expo dev builds were failing to resolve this native module through async import().
|
||||
const mod = require("expo-camera") as typeof import("expo-camera") & {
|
||||
Camera?: { requestCameraPermissionsAsync?: unknown }
|
||||
}
|
||||
const direct = (mod as { requestCameraPermissionsAsync?: unknown }).requestCameraPermissionsAsync
|
||||
const fromCamera = (mod as { Camera?: { requestCameraPermissionsAsync?: unknown } }).Camera
|
||||
?.requestCameraPermissionsAsync
|
||||
const fromCamera = mod.Camera?.requestCameraPermissionsAsync
|
||||
let requestCameraPermissionsAsync: (() => Promise<{ granted: boolean }>) | null = null
|
||||
if (typeof direct === "function") {
|
||||
requestCameraPermissionsAsync = direct as () => Promise<{ granted: boolean }>
|
||||
@@ -2750,7 +2750,7 @@ export default function DictationScreen() {
|
||||
requestCameraPermissionsAsync = fromCamera as () => Promise<{ granted: boolean }>
|
||||
}
|
||||
|
||||
if (!requestCameraPermissionsAsync) {
|
||||
if (!mod.CameraView || !requestCameraPermissionsAsync) {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -2760,7 +2760,10 @@ export default function DictationScreen() {
|
||||
}
|
||||
setCamera(next)
|
||||
return next
|
||||
}))
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
})()
|
||||
if (!current) {
|
||||
Alert.alert("Scanner unavailable", "This build does not include camera support. Reinstall the latest dev build.")
|
||||
return
|
||||
|
||||
@@ -214,41 +214,38 @@ export function useMdnsDiscovery(input: UseMdnsDiscoveryInput) {
|
||||
|
||||
startScanRef.current = startScan
|
||||
|
||||
void import("react-native-zeroconf")
|
||||
.then((module) => {
|
||||
if (!active) return
|
||||
|
||||
const mod = module as ZeroconfModule
|
||||
const Zeroconf = mod.default
|
||||
if (typeof Zeroconf !== "function") {
|
||||
setDiscoveryAvailable(false)
|
||||
setDiscoveryStatus("error")
|
||||
setDiscoveryError("mDNS module unavailable")
|
||||
return
|
||||
}
|
||||
|
||||
zeroconf = new Zeroconf()
|
||||
androidImplType = Platform.OS === "android" ? (mod.ImplType?.DNSSD ?? "DNSSD") : undefined
|
||||
setDiscoveryAvailable(true)
|
||||
|
||||
zeroconf.on("resolved", rebuildServices)
|
||||
zeroconf.on("remove", rebuildServices)
|
||||
zeroconf.on("update", rebuildServices)
|
||||
zeroconf.on("error", (error) => {
|
||||
if (!active) return
|
||||
setDiscoveryStatus("error")
|
||||
setDiscoveryError(toErrorMessage(error))
|
||||
})
|
||||
|
||||
startScan()
|
||||
})
|
||||
.catch((error) => {
|
||||
if (!active) return
|
||||
try {
|
||||
// Expo dev builds were failing to resolve this native module through async import().
|
||||
const mod = require("react-native-zeroconf") as ZeroconfModule
|
||||
const Zeroconf = mod.default
|
||||
if (typeof Zeroconf !== "function") {
|
||||
setDiscoveryAvailable(false)
|
||||
setDiscoveryStatus("error")
|
||||
setDiscoveryError("mDNS module unavailable")
|
||||
return
|
||||
}
|
||||
|
||||
zeroconf = new Zeroconf()
|
||||
androidImplType = Platform.OS === "android" ? (mod.ImplType?.DNSSD ?? "DNSSD") : undefined
|
||||
setDiscoveryAvailable(true)
|
||||
|
||||
zeroconf.on("resolved", rebuildServices)
|
||||
zeroconf.on("remove", rebuildServices)
|
||||
zeroconf.on("update", rebuildServices)
|
||||
zeroconf.on("error", (error) => {
|
||||
if (!active) return
|
||||
setDiscoveryStatus("error")
|
||||
setDiscoveryError(toErrorMessage(error))
|
||||
})
|
||||
|
||||
startScan()
|
||||
} catch (error) {
|
||||
if (!active) return
|
||||
setDiscoveryAvailable(false)
|
||||
setDiscoveryStatus("error")
|
||||
setDiscoveryError(toErrorMessage(error))
|
||||
}
|
||||
|
||||
return () => {
|
||||
active = false
|
||||
startScanRef.current = null
|
||||
|
||||
Reference in New Issue
Block a user