import {App} from '@capacitor/app' import {Capacitor} from '@capacitor/core' import {githubRepo} from 'common/constants' import {HOSTING_ENV, IS_VERCEL} from 'common/hosting/constants' import {PrivateUser} from 'common/user' import {useEffect, useState} from 'react' import {Button} from 'web/components/buttons/button' import {Col} from 'web/components/layout/col' import {CustomLink} from 'web/components/links' import {WithPrivateUser} from 'web/components/user/with-user' import {api} from 'web/lib/api' import {useT} from 'web/lib/locale' export type WebBuild = { gitSha?: string gitMessage?: string deploymentId?: string environment?: string } export type LiveUpdateInfo = { bundleId?: string | null commitSha?: string commitMessage?: string commitDate?: string } export type Android = { appVersion?: string buildNumber?: string liveUpdate?: LiveUpdateInfo } export type Backend = { version?: string gitSha?: string gitMessage?: string commitDate?: string } export type Runtime = { platform: string } export type Diagnostics = { web?: WebBuild android?: Android backend?: Backend runtime: Runtime } function useDiagnostics() { const [data, setData] = useState(null) useEffect(() => { const load = async () => { const diagnostics: Diagnostics = { runtime: { platform: IS_VERCEL ? 'web' : Capacitor.isNativePlatform() ? 'android' : HOSTING_ENV, }, } if (IS_VERCEL) { diagnostics.web = { environment: process.env.NEXT_PUBLIC_VERCEL_ENV, gitSha: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA, gitMessage: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_MESSAGE, deploymentId: process.env.NEXT_PUBLIC_VERCEL_DEPLOYMENT_ID, } } if (Capacitor.isNativePlatform()) { const appInfo = await App.getInfo() // const bundle = await LiveUpdate.getCurrentBundle().catch(() => { // return {bundleId: null} // }) // const buildInfo = await getLiveUpdateInfo().catch(() => null) diagnostics.android = { appVersion: appInfo.version, buildNumber: appInfo.build, // liveUpdate: { // bundleId: bundle?.bundleId, // commitSha: buildInfo?.commitSha, // commitMessage: buildInfo?.commitMessage, // commitDate: buildInfo?.commitDate // } } } const backend = await api('health').catch(() => null) if (backend) { diagnostics.backend = { version: backend.version, gitSha: backend.git?.revision, gitMessage: backend.git?.message, commitDate: backend.git?.commitDate, } } setData(diagnostics) } load() }, []) return data } function diagnosticsToText(d: Diagnostics): string { const replacer = (key: string, value: any) => { if (value === null) return 'null' if (value === undefined) return 'undefined' return value } return JSON.stringify(d, replacer, 2) .replace(/ {2}"/g, '') .replace(/["{}[\]]/g, '') .replace(/^[ \t]*\n/gm, '') .replace(/,\n/g, '\n') .trim() } export const AboutSettings = () => ( {(user) => } ) const LoadedAboutSettings = (_props: {privateUser: PrivateUser}) => { const [copyFeedback, setCopyFeedback] = useState('') const t = useT() const diagnostics = useDiagnostics() if (!diagnostics) return null const handleCopy = async () => { if (!diagnostics) return await navigator.clipboard.writeText(diagnosticsToText(diagnostics)) setCopyFeedback(t('about.settings.copied', 'Copied!')) setTimeout(() => { setCopyFeedback('') }, 2000) } return ( ) } const WebBuildInfo = (props: {info?: WebBuild}) => { const {info} = props if (!info) return const env = info.environment const gitMessage = info.gitMessage const sha = info.gitSha const deploymentId = info.deploymentId const url = `${githubRepo}/commit/${sha}` return (

Web build (Vercel)

Commit SHA: {sha}

Commit message: {gitMessage}

Vercel deployment ID: {deploymentId}

Environment: {env}

) } const AndroidInfo = (props: {info?: Android}) => { const {info} = props if (!info) return const sha = info.liveUpdate?.commitSha const url = `${githubRepo}/commit/${sha}` return (

Android (Capacitor)

App version (Android): {info.appVersion}

Native build number (Android): {info.buildNumber}

{info.liveUpdate && ( <>

Live update build ID (Capawesome): {info.liveUpdate?.bundleId}

Live update commit SHA (Capawesome): {sha}

Live update commit message (Capawesome): {info.liveUpdate?.commitMessage}

Live update commit date (Capawesome): {info.liveUpdate?.commitDate}

)} ) } const BackendInfo = (props: {info?: Backend}) => { const {info} = props if (!info) return const sha = info.gitSha const commitDate = info.commitDate const commitMessage = info.gitMessage const url = `${githubRepo}/commit/${sha}` return (

Backend

API version: {info.version}

{sha && (

API commit SHA: {sha}

)} {commitMessage &&

API commit message: {commitMessage}

} {commitDate &&

API commit date: {commitDate}

} ) } const RuntimeInfo = (props: {info?: Runtime}) => { const {info} = props if (!info) return return (

Runtime

Platform: {info.platform}

) }