DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(native): add manual address entry to the scan page (#1163)
Zuyang Liu7180e70a7e45
diff --git a/docs/specs/native.md b/docs/specs/native.mdindex 483929f5..d28bf6ce 100644--- a/docs/specs/native.md+++ b/docs/specs/native.md@@ -95,13 +95,14 @@ src-native/## 4. 启动与连接流程 (Startup & Connection)* **首次进入**(无成功连接历史):只展示连接方式选择——「自动扫描局域网」「扫码连接」「最近连接」,**不**自动连接、**不**隐式扫描。+* **手动输入**:扫码页在相机权限已授予后提供「手动输入地址」,切换后卸载相机、只留地址输入框,「改为扫码连接」切回。输入与二维码共用 `parseQrPayload`,解析失败且不含 `://` 时补 `https://` 再解析一次(裸域名走 HTTPS,`host:port` 仍按 HTTP);解析结果直接交给 `connectAddress`,需要认证的主机在 WebView 的配对页输入桌面端显示的配对码。* **再次进入**(历史中有主机):只探测历史主机并自动连接可用项,检测期文案为「寻找可用连接」;全部不可用时停在连接方式选择,**不**退化为局域网扫描。* **主动发现**由用户操作触发:点击「自动扫描局域网」,或断开连接后紧接的那轮扫描。* 探测成功由可信 DSH 文档就绪消息确认,不以原生 `onLoad` 或 HTTP 200 判定。* 超时与预算集中在 `src-native/config/constants.ts`:默认端口 `3088` / `3080`、并发 40、单次探测 600 ms、历史探测 3 s、整体扫描预算 20 s、前台健康检查间隔 15 s。* 服务识别与健康检查只请求上游真实公开的 `/manifest.webmanifest`,严格校验 `name: 'DeepSeek Harness'` 与 `short_name: 'DSH'`;不请求不存在的认证状态端点,也不把任意 HTML 200 当作 DSH 服务。* 服务识别不代表登录成功。需要认证的主机由 WebView 完成配对,只有可信文档就绪消息才能确认连接成功;健康检查不读取或重放配对码。-* 主机前置 Cloudflare Access 时,需为 `/manifest.webmanifest` 单独建一个 Bypass 应用(该隧道路由不开 Protect with Access),否则启动自动重连与健康检查一律失败;扫码、点选历史与重新连接不经探测。+* 主机前置 Cloudflare Access 时,需为 `/manifest.webmanifest` 单独建一个 Bypass 应用(该隧道路由不开 Protect with Access),否则启动自动重连与健康检查一律失败;扫码、手动输入、点选历史与重新连接不经探测。* 探测与扫描拆成两个模块:`src-native/services/probe-bridge.ts` 的 `probeBridge(address, signal, timeoutMs?)` 探测单个地址(超时、网络错误、非 2xx、响应体不合法一律返回 `null`),`src-native/services/scan-candidates.ts` 的 `scanCandidates(candidates, { signal, concurrency, timeoutMs, budgetMs, onFound })` 以有界并发遍历候选地址并受总预算约束(参数非法直接抛 `RangeError`)。* 断开会清空当前连接并保留历史,紧接着的扫描跳过刚断开的精确 origin。@@ -132,7 +133,7 @@ src-native/## 6. 网络与安全边界 (Network & Security)* 局域网 HTTP 通过 `expo-build-properties` 的 `usesCleartextTraffic: true` 支持;HTTP 不提供传输保密性,仅用于可信局域网,公网优先 HTTPS。-* 自动发现基于当前 IPv4 推导 `/24` 网段,不保证跨网段、VPN、访客 Wi-Fi 隔离或非默认端口;此时改用桌面端 / Bridge 生成的二维码,或在 `EXTRA_SCAN_PORTS` 追加端口。+* 自动发现基于当前 IPv4 推导 `/24` 网段,不保证跨网段、VPN、访客 Wi-Fi 隔离或非默认端口;此时改用桌面端 / Bridge 生成的二维码、在扫码页手动输入地址,或在 `EXTRA_SCAN_PORTS` 追加端口。* 通知与 WebView 消息入口校验类型白名单、精确 scheme / host / port origin、原生事件 URL 与每个 WebView 的随机 nonce;外站顶层链接交由外部浏览器打开。* 唯一例外是 Cloudflare Access 登录:受信 origin 的文档请求被服务端重定向到 `https://*.cloudflareaccess.com/cdn-cgi/access/login/…` 时,登录留在 WebView 内,流程中的 https 顶层跳转(团队域、IdP)放行,回到受信 origin 即结束,期间隐藏加载遮罩并暂停 20 s 超时,结束后 Android 清空返回历史;已加载文档里点开的同类链接仍走外部浏览器。Google 作为 IdP 会拒绝嵌入式 WebView(`disallowed_useragent`),需改用 One-time PIN 等。* 配对登录与会话保留在 WebView 内由 cookie jar 管理,**不**通过 RN `fetch` 登录。远程访问不再生成、保存或接受访问密码;SSH 密码与密钥口令不受影响。diff --git a/src-native/app/scan.tsx b/src-native/app/scan.tsxindex 847e1260..731fd29e 100644--- a/src-native/app/scan.tsx+++ b/src-native/app/scan.tsx@@ -3,6 +3,7 @@ import { CameraView, useCameraPermissions } from 'expo-camera'import { router } from 'expo-router'import { Button } from 'heroui-native/button'import { useThemeColor } from 'heroui-native/hooks'+import { Input } from 'heroui-native/input'import { useEffect, useRef, useState } from 'react'import { useTranslation } from 'react-i18next'import { Else, If, Then } from 'react-if-lite'@@ -22,6 +23,9 @@ export default function ScanScreen() {const insets = useSafeAreaInsets()const [error, setError] = useState<string | null>(null)const [scanned, setScanned] = useState(false)+ const [manual, setManual] = useState(false)+ const [typedAddress, setTypedAddress] = useState('')+ const [invalidAddress, setInvalidAddress] = useState(false)const lockedRef = useRef(false)const [background, foreground] = useThemeColor(['background', 'foreground'])// keep:effect Recheck the native camera permission when returning from system settings.@@ -58,13 +62,34 @@ export default function ScanScreen() {setError(null)setScanned(false)}+ function switchMode(next: boolean) {+ retry()+ setInvalidAddress(false)+ setManual(next)+ }+ function submitAddress() {+ const text = typedAddress.trim()+ if (!text || lockedRef.current)+ return+ const address = parseQrPayload(text) ?? (text.includes('://') ? null : parseQrPayload(`https://${text}`))+ if (!address) {+ setInvalidAddress(true)+ return+ }+ lockedRef.current = true+ connectAddress(address)+ router.back()+ }let permissionLabel: string = t('scan.allowCamera')if (permission && !permission.canAskAgain)permissionLabel = t('scan.openSettings')+ let title: string = t('scan.cameraTitle')+ if (manual)+ title = t('scan.addressTitle')return (<View style={{ flex: 1, backgroundColor: background, paddingTop: insets.top, paddingBottom: insets.bottom, paddingLeft: insets.left, paddingRight: insets.right }}><View className="flex-row items-center justify-between gap-3 px-5 pb-3 pt-2">- <Text className="flex-1 text-lg font-semibold text-foreground">{t('scan.cameraTitle')}</Text>+ <Text className="flex-1 text-lg font-semibold text-foreground">{title}</Text><Button variant="ghost" isIconOnly accessibilityLabel={t('scan.closeScanner')} onPress={() => router.back()}><X size={24} color={foreground} /></Button>@@ -73,31 +98,61 @@ export default function ScanScreen() {<Then><If cond={permission?.granted}><Then>- <View className="mx-5 flex-1 overflow-hidden rounded-3xl bg-black">- <If cond={appState === 'active'}>- <Then>- <CameraView- style={{ flex: 1 }}- facing="back"- barcodeScannerSettings={{ barcodeTypes: ['qr'] }}- onBarcodeScanned={scanned ? undefined : handleBarcode}- onMountError={() => setError(t('scan.cameraError'))}+ <If cond={manual}>+ <Then>+ <View className="flex-1 gap-4 px-5 pt-2">+ <Text className="text-sm leading-6 text-muted">{t('scan.addressHint')}</Text>+ <Input+ accessibilityLabel={t('scan.address')}+ value={typedAddress}+ onChangeText={(text) => {+ setTypedAddress(text)+ setInvalidAddress(false)+ }}+ isInvalid={invalidAddress}+ autoFocus+ autoCapitalize="none"+ autoCorrect={false}+ keyboardType="url"+ returnKeyType="go"+ onSubmitEditing={submitAddress}/>- </Then>- </If>- <View pointerEvents="none" className="absolute inset-0 items-center justify-center">- <View className="h-64 w-64 rounded-3xl border-2 border-white/80" />- </View>- </View>- <View className="gap-4 px-6 py-6">- <Text className="text-center text-sm leading-6 text-muted">{t('scan.cameraHint')}</Text>- <If cond={error !== null}>- <Then>- <Text className="text-center text-sm text-danger" accessibilityLiveRegion="polite">{error}</Text>- <Button variant="outline" onPress={retry}>{t('scan.qrRetry')}</Button>- </Then>- </If>- </View>+ <If cond={invalidAddress}>+ <Then><Text className="text-sm text-danger" accessibilityLiveRegion="polite">{t('scan.invalidAddress')}</Text></Then>+ </If>+ <Button isDisabled={!typedAddress.trim()} onPress={submitAddress}>{t('scan.connect')}</Button>+ <Button variant="ghost" onPress={() => switchMode(false)}>{t('scan.scanInstead')}</Button>+ </View>+ </Then>+ <Else>+ <View className="mx-5 flex-1 overflow-hidden rounded-3xl bg-black">+ <If cond={appState === 'active'}>+ <Then>+ <CameraView+ style={{ flex: 1 }}+ facing="back"+ barcodeScannerSettings={{ barcodeTypes: ['qr'] }}+ onBarcodeScanned={scanned ? undefined : handleBarcode}+ onMountError={() => setError(t('scan.cameraError'))}+ />+ </Then>+ </If>+ <View pointerEvents="none" className="absolute inset-0 items-center justify-center">+ <View className="h-64 w-64 rounded-3xl border-2 border-white/80" />+ </View>+ </View>+ <View className="gap-4 px-6 py-6">+ <Text className="text-center text-sm leading-6 text-muted">{t('scan.cameraHint')}</Text>+ <If cond={error !== null}>+ <Then>+ <Text className="text-center text-sm text-danger" accessibilityLiveRegion="polite">{error}</Text>+ <Button variant="outline" onPress={retry}>{t('scan.qrRetry')}</Button>+ </Then>+ </If>+ <Button variant="ghost" onPress={() => switchMode(true)}>{t('scan.enterAddress')}</Button>+ </View>+ </Else>+ </If></Then><Else><View className="flex-1 items-center justify-center gap-6 px-8">diff --git a/src-native/i18n/locales/en-US.json b/src-native/i18n/locales/en-US.jsonindex f77caa5d..297953f4 100644--- a/src-native/i18n/locales/en-US.json+++ b/src-native/i18n/locales/en-US.json@@ -46,6 +46,13 @@"scan.cameraError": "Cannot open the camera. Check the camera permission and try again.","scan.invalidQr": "The QR code contains no valid HTTP/HTTPS connection address.","scan.qrRetry": "Scan again",+ "scan.enterAddress": "Enter address manually",+ "scan.addressTitle": "Connect by address",+ "scan.addressHint": "Enter the DSH host address, such as https://dsh.example.com or 192.168.1.10:3088",+ "scan.address": "Connection address",+ "scan.connect": "Connect",+ "scan.scanInstead": "Scan QR code instead",+ "scan.invalidAddress": "Enter a valid HTTP/HTTPS connection address.","notification.channel": "Connection and task notifications","notification.channelSilent": "Connection and task notifications · silent"}diff --git a/src-native/i18n/locales/zh-CN.json b/src-native/i18n/locales/zh-CN.jsonindex 047906b6..0084663c 100644--- a/src-native/i18n/locales/zh-CN.json+++ b/src-native/i18n/locales/zh-CN.json@@ -46,6 +46,13 @@"scan.cameraError": "无法打开相机,请检查相机权限后重试。","scan.invalidQr": "二维码中没有有效的 HTTP/HTTPS 连接地址。","scan.qrRetry": "重新扫码",+ "scan.enterAddress": "手动输入地址",+ "scan.addressTitle": "输入地址连接",+ "scan.addressHint": "输入 DSH 主机地址,例如 https://dsh.example.com 或 192.168.1.10:3088",+ "scan.address": "连接地址",+ "scan.connect": "连接",+ "scan.scanInstead": "改为扫码连接",+ "scan.invalidAddress": "请输入有效的 HTTP/HTTPS 连接地址。","notification.channel": "连接与任务通知","notification.channelSilent": "连接与任务通知 · 静音"}diff --git a/src-native/ui/scan.test.tsx b/src-native/ui/scan.test.tsxindex d883cf70..015aa126 100644--- a/src-native/ui/scan.test.tsx+++ b/src-native/ui/scan.test.tsx@@ -73,6 +73,7 @@ vi.mock('heroui-native/button', async () => {}return { Button: Object.assign(Button, { Label: 'Text' }) }})+vi.mock('heroui-native/input', () => ({ Input: 'Input' }))vi.mock('react-native-safe-area-context', () => ({ SafeAreaView: 'SafeAreaView', useSafeAreaInsets: () => native.insets }))vi.mock('react-native-lucide', () => ({ X: 'Icon' }))vi.mock('react-native-reanimated', async () => {@@ -144,6 +145,22 @@ async function press(label: string) {})}+function addressInput() {+ return root().find(node => String(node.type) === 'Input')+}++async function typeAddress(value: string) {+ await act(async () => {+ addressInput().props.onChangeText(value)+ })+}++async function submitFromKeyboard() {+ await act(async () => {+ addressInput().props.onSubmitEditing()+ })+}+async function mount() {await act(async () => {screen = create(createElement(ScanScreen))@@ -391,3 +408,119 @@ describe('rendered scanner QR events', () => {expect(connection.stage).toBe('connected')})})++describe('rendered scanner manual address entry', () => {+ it('replaces the camera with a focused URL field when manual entry is chosen', async () => {+ await mount()++ await press('手动输入地址')++ expect(root().findAll(node => String(node.type) === 'CameraView')).toHaveLength(0)+ expect(addressInput().props).toMatchObject({ accessibilityLabel: '连接地址', value: '', isInvalid: false, autoFocus: true, autoCapitalize: 'none', autoCorrect: false, keyboardType: 'url', returnKeyType: 'go' })+ expect(texts()).toContain('输入地址连接')+ expect(texts()).not.toContain('扫码连接 DSH Mobile')+ })++ it('returns from the address form to a camera that accepts a fresh QR result after an invalid one', async () => {+ await mount()+ await act(async () => {+ camera().props.onBarcodeScanned({ data: 'not a connection QR code' })+ })+ expect(camera().props.onBarcodeScanned).toBeUndefined()++ await press('手动输入地址')+ await press('改为扫码连接')++ expect(texts()).toContain('扫码连接 DSH Mobile')+ expect(texts()).not.toContain('二维码中没有有效的 HTTP/HTTPS 连接地址。')+ await act(async () => {+ camera().props.onBarcodeScanned({ data: 'http://bridge.local:3080/' })+ })+ expect(connection.current).toEqual({ id: 'http://bridge.local:3080', url: 'http://bridge.local:3080/', host: 'bridge.local', port: 3080 })+ expect(native.back).toHaveBeenCalledExactlyOnceWith()+ })++ it('connects a typed URL with its pairing code once before React commits and returns to Home once', async () => {+ await mount()+ await press('手动输入地址')+ await typeAddress(' http://192.168.1.10:3088/?auth=K7M2Q9XA ')++ await act(async () => {+ button('连接').props.onPress()+ button('连接').props.onPress()+ })++ expect(connection.current).toEqual({ id: 'http://192.168.1.10:3088', url: 'http://192.168.1.10:3088/', host: '192.168.1.10', port: 3088, token: 'K7M2Q9XA' })+ expect(connection.stage).toBe('connected')+ expect(native.back).toHaveBeenCalledExactlyOnceWith()+ const generation = connection.viewGeneration+ await submitFromKeyboard()+ expect(native.back).toHaveBeenCalledTimes(1)+ expect(connection.viewGeneration).toBe(generation)+ })++ it('connects a bare host name submitted from the keyboard over https', async () => {+ await mount()+ await press('手动输入地址')+ await typeAddress('dsh.example.com')++ await submitFromKeyboard()++ expect(connection.current).toEqual({ id: 'https://dsh.example.com', url: 'https://dsh.example.com/', host: 'dsh.example.com', port: 443 })+ expect(native.back).toHaveBeenCalledExactlyOnceWith()+ })++ it('keeps a typed host and port on plain http', async () => {+ await mount()+ await press('手动输入地址')+ await typeAddress('192.168.1.10:3088')++ await press('连接')++ expect(connection.current).toEqual({ id: 'http://192.168.1.10:3088', url: 'http://192.168.1.10:3088/', host: '192.168.1.10', port: 3088 })+ expect(native.back).toHaveBeenCalledExactlyOnceWith()+ })++ it.each(['ftp://files.local', 'bridge local'])('rejects the typed address %s without connecting', async (value) => {+ await mount()+ await press('手动输入地址')+ await typeAddress(value)++ await press('连接')++ expect(texts()).toContain('请输入有效的 HTTP/HTTPS 连接地址。')+ expect(addressInput().props.isInvalid).toBe(true)+ expect(connection.current).toBeNull()+ expect(native.back).not.toHaveBeenCalled()+ })++ it('clears the invalid-address error once the address is edited', async () => {+ await mount()+ await press('手动输入地址')+ await typeAddress('ftp://files.local')+ await press('连接')+ expect(texts()).toContain('请输入有效的 HTTP/HTTPS 连接地址。')++ await typeAddress('https://files.local')++ expect(texts()).not.toContain('请输入有效的 HTTP/HTTPS 连接地址。')+ expect(addressInput().props.isInvalid).toBe(false)+ expect(connection.current).toBeNull()+ })++ it('keeps Connect disabled and ignores keyboard submits while the address is blank', async () => {+ await mount()+ await press('手动输入地址')+ expect(button('连接').props.isDisabled).toBe(true)++ await typeAddress(' ')+ await submitFromKeyboard()++ expect(button('连接').props.isDisabled).toBe(true)+ expect(texts()).not.toContain('请输入有效的 HTTP/HTTPS 连接地址。')+ expect(connection.current).toBeNull()+ expect(native.back).not.toHaveBeenCalled()+ await typeAddress('dsh.example.com')+ expect(button('连接').props.isDisabled).toBe(false)+ })+})