This reverts commit 55d3a42079.
This commit is contained in:
@@ -82,7 +82,6 @@ export function registerMobileHandlers(rpcServer: OrcaRuntimeRpcServer): void {
|
||||
return {
|
||||
available: true as const,
|
||||
qrDataUrl,
|
||||
pairingUrl: url,
|
||||
endpoint,
|
||||
deviceId: device.deviceId
|
||||
}
|
||||
|
||||
@@ -1172,15 +1172,11 @@ export type PreloadApi = {
|
||||
listNetworkInterfaces: () => Promise<{
|
||||
interfaces: { name: string; address: string }[]
|
||||
}>
|
||||
getPairingQR: (args?: { address?: string }) => Promise<
|
||||
getPairingQR: (args?: {
|
||||
address?: string
|
||||
}) => Promise<
|
||||
| { available: false }
|
||||
| {
|
||||
available: true
|
||||
qrDataUrl: string
|
||||
pairingUrl: string
|
||||
endpoint: string
|
||||
deviceId: string
|
||||
}
|
||||
| { available: true; qrDataUrl: string; endpoint: string; deviceId: string }
|
||||
>
|
||||
listDevices: () => Promise<{
|
||||
devices: { deviceId: string; name: string; pairedAt: number; lastSeenAt: number }[]
|
||||
|
||||
@@ -2135,13 +2135,7 @@ const api = {
|
||||
address?: string
|
||||
}): Promise<
|
||||
| { available: false }
|
||||
| {
|
||||
available: true
|
||||
qrDataUrl: string
|
||||
pairingUrl: string
|
||||
endpoint: string
|
||||
deviceId: string
|
||||
}
|
||||
| { available: true; qrDataUrl: string; endpoint: string; deviceId: string }
|
||||
> => ipcRenderer.invoke('mobile:getPairingQR', args),
|
||||
|
||||
listDevices: (): Promise<{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
import { Check, Copy, Maximize2, RefreshCw, Trash2, Wifi } from 'lucide-react'
|
||||
import { Maximize2, RefreshCw, Trash2, Wifi } from 'lucide-react'
|
||||
import { Button } from '../ui/button'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '../ui/dialog'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select'
|
||||
@@ -38,14 +38,12 @@ type NetworkInterface = {
|
||||
|
||||
export function MobilePane(): React.JSX.Element {
|
||||
const [qrDataUrl, setQrDataUrl] = useState<string | null>(null)
|
||||
const [pairingUrl, setPairingUrl] = useState<string | null>(null)
|
||||
const [endpoint, setEndpoint] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [devices, setDevices] = useState<PairedDevice[]>([])
|
||||
const [qrEnlarged, setQrEnlarged] = useState(false)
|
||||
const [networkInterfaces, setNetworkInterfaces] = useState<NetworkInterface[]>([])
|
||||
const [selectedAddress, setSelectedAddress] = useState<string | undefined>(undefined)
|
||||
const [codeCopied, setCodeCopied] = useState(false)
|
||||
|
||||
const loadDevices = useCallback(async () => {
|
||||
try {
|
||||
@@ -76,9 +74,7 @@ export function MobilePane(): React.JSX.Element {
|
||||
)
|
||||
if (result.available) {
|
||||
setQrDataUrl(result.qrDataUrl)
|
||||
setPairingUrl(result.pairingUrl)
|
||||
setEndpoint(result.endpoint)
|
||||
setCodeCopied(false)
|
||||
void loadDevices()
|
||||
} else {
|
||||
toast.error('WebSocket transport is not running')
|
||||
@@ -114,19 +110,6 @@ export function MobilePane(): React.JSX.Element {
|
||||
return () => clearInterval(interval)
|
||||
}, [deviceCountAtQr, devices.length, loadDevices])
|
||||
|
||||
async function copyPairingCode() {
|
||||
if (!pairingUrl) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await navigator.clipboard.writeText(pairingUrl)
|
||||
setCodeCopied(true)
|
||||
setTimeout(() => setCodeCopied(false), 2000)
|
||||
} catch {
|
||||
toast.error('Failed to copy pairing code')
|
||||
}
|
||||
}
|
||||
|
||||
async function revokeDevice(deviceId: string) {
|
||||
try {
|
||||
await window.api.mobile.revokeDevice({ deviceId })
|
||||
@@ -194,26 +177,6 @@ export function MobilePane(): React.JSX.Element {
|
||||
<p className="text-muted-foreground max-w-xs text-center text-xs">
|
||||
Scan this code with the Orca mobile app. Each code creates a unique device token.
|
||||
</p>
|
||||
{pairingUrl && (
|
||||
<div className="flex w-full max-w-sm flex-col gap-1.5 px-4">
|
||||
<div className="text-muted-foreground text-center text-xs">
|
||||
Or paste this code in the mobile app:
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => void copyPairingCode()}
|
||||
className="font-mono text-[10px] leading-tight whitespace-normal break-all h-auto py-2"
|
||||
>
|
||||
<span className="flex-1 text-left">{pairingUrl}</span>
|
||||
{codeCopied ? (
|
||||
<Check className="ml-2 size-3.5 shrink-0 text-emerald-500" />
|
||||
) : (
|
||||
<Copy className="ml-2 size-3.5 shrink-0" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
encodePairingOffer,
|
||||
decodePairingOffer,
|
||||
parsePairingCode,
|
||||
type PairingOffer
|
||||
} from './pairing'
|
||||
import { encodePairingOffer, decodePairingOffer, type PairingOffer } from './pairing'
|
||||
|
||||
describe('pairing offer', () => {
|
||||
const offer: PairingOffer = {
|
||||
@@ -54,43 +49,3 @@ describe('pairing offer', () => {
|
||||
expect(() => decodePairingOffer(`orca://pair#${base64}`)).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe('parsePairingCode', () => {
|
||||
const offer: PairingOffer = {
|
||||
v: 2,
|
||||
endpoint: 'ws://192.168.1.10:6768',
|
||||
deviceToken: 'token-abc',
|
||||
publicKeyB64: 'pubkey-xyz'
|
||||
}
|
||||
|
||||
it('parses a full orca://pair# URL', () => {
|
||||
const url = encodePairingOffer(offer)
|
||||
expect(parsePairingCode(url)).toEqual(offer)
|
||||
})
|
||||
|
||||
it('parses a bare base64url payload (without scheme prefix)', () => {
|
||||
const url = encodePairingOffer(offer)
|
||||
const base64url = url.split('#')[1]!
|
||||
expect(parsePairingCode(base64url)).toEqual(offer)
|
||||
})
|
||||
|
||||
it('tolerates surrounding whitespace from clipboard', () => {
|
||||
const url = encodePairingOffer(offer)
|
||||
expect(parsePairingCode(` ${url}\n`)).toEqual(offer)
|
||||
})
|
||||
|
||||
it('returns null for empty input', () => {
|
||||
expect(parsePairingCode('')).toBeNull()
|
||||
expect(parsePairingCode(' ')).toBeNull()
|
||||
})
|
||||
|
||||
it('returns null for garbage input', () => {
|
||||
expect(parsePairingCode('not a pairing code')).toBeNull()
|
||||
expect(parsePairingCode('https://example.com')).toBeNull()
|
||||
})
|
||||
|
||||
it('returns null for valid base64 of unrelated JSON', () => {
|
||||
const bogus = Buffer.from(JSON.stringify({ hello: 'world' })).toString('base64')
|
||||
expect(parsePairingCode(bogus)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
+1
-22
@@ -28,28 +28,7 @@ export function decodePairingOffer(url: string): PairingOffer {
|
||||
if (!url.startsWith('orca://pair') || hashIndex === -1) {
|
||||
throw new Error('Invalid pairing URL: must start with orca://pair#')
|
||||
}
|
||||
return decodePairingBase64(url.slice(hashIndex + 1))
|
||||
}
|
||||
|
||||
// Why: accept either an `orca://pair#<base64>` URL or the bare base64
|
||||
// string so the mobile paste-pair flow can take whichever the user
|
||||
// actually copied from desktop.
|
||||
export function parsePairingCode(input: string): PairingOffer | null {
|
||||
const trimmed = input.trim()
|
||||
if (!trimmed) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
if (trimmed.startsWith('orca://pair')) {
|
||||
return decodePairingOffer(trimmed)
|
||||
}
|
||||
return decodePairingBase64(trimmed)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function decodePairingBase64(base64url: string): PairingOffer {
|
||||
const base64url = url.slice(hashIndex + 1)
|
||||
const base64 = base64url.replace(/-/g, '+').replace(/_/g, '/')
|
||||
const json = Buffer.from(base64, 'base64').toString('utf-8')
|
||||
return PairingOfferSchema.parse(JSON.parse(json))
|
||||
|
||||
Reference in New Issue
Block a user