import * as Clipboard from "expo-clipboard" import {useRef} from "react" import {Linking, TextStyle, TouchableOpacity, View} from "react-native" import Toast from "react-native-toast-message" import {Text} from "@/components/ignite" import {useAppTheme} from "@/contexts/ThemeContext" import {useAuth} from "@/contexts/AuthContext" import {useEngineSnapshot} from "@/hooks/useEngineSnapshot" import {translate} from "@/i18n" import {resolvedEndpoints} from "@/services/cloudClient" import {engine, SETTINGS, useSetting, getAppBuildInfo} from "@mentra/engine" import {ThemedStyle} from "@/theme" import showAlert from "@/utils/AlertUtils" const SUPER_MODE_PRESS_DURATION_MS = 10000 export const VersionInfo = () => { const {themed} = useAppTheme() const buildInfo = getAppBuildInfo() const {user} = useAuth() const [debugMode, setDebugMode] = useSetting(SETTINGS.debug_mode.key) const [_superMode, setSuperMode] = useSetting(SETTINGS.super_mode.key) useSetting(SETTINGS.cloud_core_url.key) const coreUrl = resolvedEndpoints().core const audioTransport = useEngineSnapshot(engine.session.status, (onChange) => engine.session.onStatus(onChange), ).audioTransport const pressCount = useRef(0) const lastPressTime = useRef(0) const pressTimeout = useRef | null>(null) const longPressTimer = useRef | null>(null) const pressSequence = useRef(0) const longPress = useRef<{id: number; startedAt: number} | null>(null) const handleQuickPress = () => { const currentTime = Date.now() const timeDiff = currentTime - lastPressTime.current const maxTimeDiff = 2000 const maxPressCount = 10 // Reset counter if too much time has passed if (timeDiff > maxTimeDiff) { pressCount.current = 1 } else { pressCount.current += 1 } lastPressTime.current = currentTime copyVersionInfo() // Clear existing timeout if (pressTimeout.current) { clearTimeout(pressTimeout.current) } // Enable debug mode once the version number has been tapped enough times. if (pressCount.current === maxPressCount) { showAlert(translate("debug:debugModeEnabled"), translate("debug:debugModeEnabled"), [ {text: translate("common:ok")}, ]) setDebugMode(true) pressCount.current = 0 } // Reset counter after 2 seconds of no activity pressTimeout.current = setTimeout(() => { pressCount.current = 0 }, maxTimeDiff) } const copyVersionInfo = async () => { const info = [ `version: ${buildInfo.appVersion}`, `branch: ${buildInfo.buildBranch}`, `time: ${buildInfo.buildTime}`, `commit: ${buildInfo.buildCommit}`, `cloud_core_url: ${resolvedEndpoints().core}`, `cloud_runtime_url: ${resolvedEndpoints().runtime}`, `audio: ${audioTransport}`, ] if (user) { info.push(`id: ${user.id}`) info.push(`email: ${user.email}`) } await Clipboard.setStringAsync(info.join("\n")) if (debugMode) { Toast.show({ type: "info", text1: translate("debug:versionInfoCopied"), position: "bottom", topOffset: 80, visibilityTime: 1000, }) } } const handlePressIn = () => { const press = {id: ++pressSequence.current, startedAt: performance.now()} longPress.current = press console.info("[SUPER_MODE_PRESS]", { phase: "press_in", pressId: press.id, atMs: Date.now(), timerPending: longPressTimer.current !== null, }) const timerRequestedAt = performance.now() longPressTimer.current = setTimeout(() => { const elapsedMs = Math.round(performance.now() - timerRequestedAt) console.info("[SUPER_MODE_PRESS]", { phase: "timer_fired", pressId: press.id, atMs: Date.now(), elapsedMs, requestedDurationMs: SUPER_MODE_PRESS_DURATION_MS, timerDelayMs: elapsedMs - SUPER_MODE_PRESS_DURATION_MS, }) setSuperMode(true) // showAlert(translate("debug:superMode"), translate("debug:superModeActivated"), [{text: translate("common:ok")}]) Toast.show({ type: "success", text1: translate("debug:superModeActivated"), position: "bottom", topOffset: 80, visibilityTime: 2000, }) longPressTimer.current = null }, SUPER_MODE_PRESS_DURATION_MS) console.info("[SUPER_MODE_PRESS]", { phase: "timer_requested", pressId: press.id, atMs: Date.now(), requestedDurationMs: SUPER_MODE_PRESS_DURATION_MS, }) } const handlePressOut = () => { const press = longPress.current const elapsedMs = press ? Math.round(performance.now() - press.startedAt) : null console.info("[SUPER_MODE_PRESS]", { phase: "press_out", pressId: press?.id ?? null, atMs: Date.now(), elapsedMs, timerPending: longPressTimer.current !== null, }) if (longPressTimer.current) { clearTimeout(longPressTimer.current) longPressTimer.current = null console.info("[SUPER_MODE_PRESS]", { phase: "timer_cancelled", pressId: press?.id ?? null, atMs: Date.now(), elapsedMs, reason: "press_out", }) copyVersionInfo() } } if (debugMode) { return ( ) } const isChina = process.env.EXPO_PUBLIC_DEPLOYMENT_REGION === "china" return ( {isChina && ( Linking.openURL("https://beian.miit.gov.cn/")}> )} ) } const $buildInfo: ThemedStyle = ({colors}) => ({ color: colors.muted_foreground, fontSize: 13, }) const $icpLink: ThemedStyle = ({colors}) => ({ color: colors.muted_foreground, fontSize: 13, textDecorationLine: "underline", })