Skip to content

Send files directly between devices over the internet - no cloud storage, no size limits.

Share connection codes and import QR from image (#27)

Denis Lupookov3cf264c59020
diff --git a/apps/desktop/src/renderer/pages/ReceivePage/ReceiveJoinView.tsx b/apps/desktop/src/renderer/pages/ReceivePage/ReceiveJoinView.tsx
index 85c70b2..d733644 100644
--- a/apps/desktop/src/renderer/pages/ReceivePage/ReceiveJoinView.tsx
+++ b/apps/desktop/src/renderer/pages/ReceivePage/ReceiveJoinView.tsx
@@ -48,9 +48,11 @@ export function ReceiveJoinView() {
<QrCodeIcon size={18} />
</span>
<span className='min-w-0 flex-1'>
- <span className='block text-[13.5px] font-semibold text-text-primary'>Scan QR code</span>
+ <span className='block text-[13.5px] font-semibold text-text-primary'>
+ Scan or import QR
+ </span>
<span className='block text-[12px] leading-snug text-text-muted'>
- Use the webcam to read the sender’s QR
+ Use the webcam, or import a saved QR image
</span>
</span>
<span className='shrink-0 text-text-muted transition-transform group-hover:translate-x-0.5'>
diff --git a/apps/desktop/src/renderer/pages/ReceivePage/WebcamScanView.tsx b/apps/desktop/src/renderer/pages/ReceivePage/WebcamScanView.tsx
index 6bd1bda..9c780ab 100644
--- a/apps/desktop/src/renderer/pages/ReceivePage/WebcamScanView.tsx
+++ b/apps/desktop/src/renderer/pages/ReceivePage/WebcamScanView.tsx
@@ -21,6 +21,7 @@ const CAMERA_ERROR_STATES: Record<string, ScanState> = {
export function WebcamScanView({ onCancel }: WebcamScanViewProps) {
const videoRef = useRef<HTMLVideoElement>(null)
const scannerRef = useRef<QrScanner | null>(null)
+ const fileInputRef = useRef<HTMLInputElement>(null)
const handledRef = useRef(false)
const [state, setState] = useState<ScanState>('starting')
const [cameras, setCameras] = useState<QrScanner.Camera[]>([])
@@ -129,6 +130,43 @@ export function WebcamScanView({ onCancel }: WebcamScanViewProps) {
}
}
+ const importImage = async (file: File) => {
+ if (handledRef.current) return
+ setErrorMessage(null)
+
+ let data: string
+ try {
+ const result = await QrScanner.scanImage(file, { returnDetailedScanResult: true })
+ data = result.data
+ } catch {
+ setErrorMessage('No QR code found in that image.')
+ return
+ }
+
+ const joinCode = extractJoinCode(data)
+ if (!joinCode) {
+ setErrorMessage('That image isn’t an AlterSend connection code.')
+ return
+ }
+
+ if (handledRef.current) return
+ handledRef.current = true
+
+ const blockedStates: ScanState[] = ['denied', 'no-camera', 'failed']
+ const resumeState: ScanState = blockedStates.includes(state) ? state : 'scanning'
+ void scannerRef.current?.stop()
+ setState('connecting')
+
+ try {
+ await joinSession(joinCode)
+ } catch (error) {
+ handledRef.current = false
+ setErrorMessage(error instanceof Error ? error.message : 'Could not join the session.')
+ setState(resumeState)
+ if (resumeState === 'scanning') void scannerRef.current?.start()
+ }
+ }
+
const blockedMessages: Partial<Record<ScanState, { title: string; hint: string }>> = {
denied: {
title: 'Camera access blocked',
@@ -147,14 +185,28 @@ export function WebcamScanView({ onCancel }: WebcamScanViewProps) {
return (
<div className='flex h-full w-full min-w-0 flex-col overflow-y-auto pr-1'>
+ <input
+ ref={fileInputRef}
+ accept='image/*'
+ className='hidden'
+ onChange={(e) => {
+ const file = e.currentTarget.files?.[0]
+ e.currentTarget.value = ''
+ if (file) void importImage(file)
+ }}
+ type='file'
+ />
{blocked ? (
<div className='mx-auto w-full max-w-[400px] rounded-[16px] border border-border-primary bg-background-subtle p-5'>
<span className='block text-[15px] font-semibold text-text-primary'>{blocked.title}</span>
<p className='m-0 mt-1.5 text-[13px] leading-relaxed text-text-muted'>{blocked.hint}</p>
- <div className='mt-4 flex items-center gap-2.5'>
+ <div className='mt-4 flex flex-wrap items-center gap-2.5'>
<Button onClick={retry} size='sm' variant='primary'>
Try again
</Button>
+ <Button onClick={() => fileInputRef.current?.click()} size='sm' variant='secondary'>
+ Import image
+ </Button>
<Button onClick={onCancel} size='sm' variant='secondary'>
Paste code instead
</Button>
@@ -198,7 +250,8 @@ export function WebcamScanView({ onCancel }: WebcamScanViewProps) {
<div className='flex min-w-0 flex-1 flex-col gap-4'>
<p className='m-0 text-[13px] leading-relaxed text-text-muted'>
- Point the sender’s QR code at the webcam — AlterSend connects automatically.
+ Center the sender’s QR in the frame, or import a saved image. AlterSend connects
+ automatically.
</p>
{errorMessage ? (
@@ -217,7 +270,10 @@ export function WebcamScanView({ onCancel }: WebcamScanViewProps) {
</div>
) : null}
- <div className='flex'>
+ <div className='flex flex-wrap gap-2.5'>
+ <Button onClick={() => fileInputRef.current?.click()} size='sm' variant='secondary'>
+ Import image
+ </Button>
<Button onClick={onCancel} size='sm' variant='secondary'>
Paste code instead
</Button>
diff --git a/apps/mobile/app/(tabs)/receive/index.tsx b/apps/mobile/app/(tabs)/receive/index.tsx
index 01e7375..f934706 100644
--- a/apps/mobile/app/(tabs)/receive/index.tsx
+++ b/apps/mobile/app/(tabs)/receive/index.tsx
@@ -95,7 +95,7 @@ export default function ReceiveScreen() {
const title = step === 'join' ? 'Receive' : copy.title
const description =
step === 'join'
- ? "Scan a sender's QR or paste their 64-character code to start streaming."
+ ? "Scan or import a sender's QR, or paste their 64-character code to start streaming."
: copy.description
const footer =
diff --git a/apps/mobile/app/receive/scan.tsx b/apps/mobile/app/receive/scan.tsx
index 084ab9c..78c9a7b 100644
--- a/apps/mobile/app/receive/scan.tsx
+++ b/apps/mobile/app/receive/scan.tsx
@@ -1,8 +1,14 @@
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { ActivityIndicator, Linking, Pressable, StyleSheet, Text, View } from 'react-native'
-import { CameraView, useCameraPermissions, type BarcodeScanningResult } from 'expo-camera'
+import {
+ CameraView,
+ scanFromURLAsync,
+ useCameraPermissions,
+ type BarcodeScanningResult
+} from 'expo-camera'
+import * as ImagePicker from 'expo-image-picker'
import { Button, useTheme, withAlpha } from '@altersend/components'
-import { ArrowLeftIcon, QrCodeIcon } from '@altersend/components/icons'
+import { ArrowLeftIcon, ImageIcon, QrCodeIcon } from '@altersend/components/icons'
import { useNavigation, useRouter } from 'expo-router'
import { extractJoinCode, useTransferStore } from '@altersend/domain'
import { joinSession } from '@altersend/domain'
@@ -65,9 +71,9 @@ export default function ReceiveScanScreen() {
const canAskAgain = permission?.canAskAgain ?? true
const canScan = cameraGranted && !isResolving && role === null
- const handleBarcodeScanned = useCallback(
- async ({ data }: BarcodeScanningResult) => {
- if (!canScan || scanLockRef.current) {
+ const resolveCode = useCallback(
+ async (data: string, invalidHint: string) => {
+ if (scanLockRef.current || role !== null) {
return
}
@@ -79,7 +85,7 @@ export default function ReceiveScanScreen() {
invalidScanAtRef.current = now
toast.show({
title: 'Unsupported QR code',
- hint: 'Scan an AlterSend connection code.',
+ hint: invalidHint,
durationMs: 2500
})
}
@@ -97,14 +103,51 @@ export default function ReceiveScanScreen() {
setIsResolving(false)
toast.show({
title: 'Couldn’t join session',
- hint: 'Try scanning again or paste the code manually.',
+ hint: 'Try again or paste the code manually.',
durationMs: 3500
})
}
},
- [canScan, goBack, toast]
+ [goBack, role, toast]
)
+ const handleBarcodeScanned = useCallback(
+ ({ data }: BarcodeScanningResult) => {
+ if (!canScan) return
+ void resolveCode(data, 'Scan an AlterSend connection code.')
+ },
+ [canScan, resolveCode]
+ )
+
+ const importFromImage = useCallback(async () => {
+ if (scanLockRef.current || role !== null) {
+ return
+ }
+
+ const result = await ImagePicker.launchImageLibraryAsync({
+ mediaTypes: 'images',
+ quality: 1
+ })
+ const asset = result.canceled ? null : result.assets[0]
+ if (!asset) return
+
+ try {
+ const [scan] = await scanFromURLAsync(asset.uri, ['qr'])
+ if (!scan) {
+ toast.show({
+ title: 'No QR code found',
+ hint: 'Pick an image that shows an AlterSend QR code.',
+ durationMs: 2500
+ })
+ return
+ }
+ await resolveCode(scan.data, 'That image isn’t an AlterSend connection code.')
+ } catch (error) {
+ console.warn('ReceiveScanScreen: importFromImage failed', error)
+ toast.show({ title: 'Couldn’t read that image', durationMs: 2500 })
+ }
+ }, [resolveCode, role, toast])
+
const permissionCopy = useMemo(() => {
if (!permission) {
return {
@@ -121,9 +164,9 @@ export default function ReceiveScanScreen() {
}
return {
- title: 'Scan QR code',
+ title: 'Scan or import QR',
description:
- 'Center the sender’s QR code inside the frame. AlterSend will connect automatically.'
+ 'Center the sender’s QR in the frame, or import a saved image. AlterSend connects automatically.'
}
}, [cameraGranted, permission])
@@ -159,7 +202,7 @@ export default function ReceiveScanScreen() {
Enable camera access
</Text>
<Text style={[styles.noticeText, { color: theme.colors.colorTextSecondary }]}>
- You only need this to scan the sender’s QR code. You can still go back and paste the
+ The camera is only needed to scan a QR. You can also import a saved image or paste the
code manually.
</Text>
<Button
@@ -170,6 +213,15 @@ export default function ReceiveScanScreen() {
>
{permissionButtonLabel}
</Button>
+ <Button
+ icon={<ImageIcon size={18} />}
+ onClick={() => void importFromImage()}
+ size='lg'
+ variant='secondary'
+ width='full'
+ >
+ Import from image
+ </Button>
<Button onClick={goBack} size='lg' variant='secondary' width='full'>
Use pasted code instead
</Button>
@@ -280,13 +332,24 @@ export default function ReceiveScanScreen() {
</View>
) : null}
</View>
+
+ <Button
+ disabled={!canScan}
+ icon={<ImageIcon size={18} />}
+ onClick={() => void importFromImage()}
+ size='lg'
+ variant='secondary'
+ width='full'
+ >
+ Import from image
+ </Button>
</View>
)}
</Layout>
)
}
-const FRAME_SIZE = 220
+const FRAME_SIZE = 280
const CORNER_SIZE = 28
const CORNER_STROKE = 4
diff --git a/apps/mobile/src/transfer/receive/views/ReceiveJoinView.tsx b/apps/mobile/src/transfer/receive/views/ReceiveJoinView.tsx
index f49498a..834f860 100644
--- a/apps/mobile/src/transfer/receive/views/ReceiveJoinView.tsx
+++ b/apps/mobile/src/transfer/receive/views/ReceiveJoinView.tsx
@@ -49,10 +49,10 @@ export function ReceiveJoinView({
</View>
<View style={styles.qrText}>
<Text style={[styles.qrTitle, { color: theme.colors.colorTextPrimary }]}>
- Scan QR code
+ Scan or import QR
</Text>
<Text style={[styles.qrSubtitle, { color: theme.colors.colorTextSecondary }]}>
- Use camera to read sender&apos;s QR
+ Use the camera, or import a saved image
</Text>
</View>
<ChevronRightIcon size={18} color={theme.colors.colorTextMuted} />
diff --git a/apps/mobile/src/transfer/send/views/ShareView.tsx b/apps/mobile/src/transfer/send/views/ShareView.tsx
index 368d5be..ad56717 100644
--- a/apps/mobile/src/transfer/send/views/ShareView.tsx
+++ b/apps/mobile/src/transfer/send/views/ShareView.tsx
@@ -1,7 +1,8 @@
import { useEffect, useMemo, useState } from 'react'
-import { ScrollView, StyleSheet, Text, View } from 'react-native'
+import { ScrollView, Share, StyleSheet, Text, View } from 'react-native'
import * as Clipboard from 'expo-clipboard'
import {
+ buildInviteText,
formatFileSize,
getPeerListEntries,
senderKeepOpenHint,
@@ -39,6 +40,7 @@ export function ShareView() {
await Clipboard.setStringAsync(topic)
setIsKeyCopied(true)
toast.show({ title: 'Copied to clipboard' })
+ await Share.share({ message: buildInviteText(topic) })
} catch (error) {
console.error(error)
}
diff --git a/packages/domain/src/receive/joinCode.ts b/packages/domain/src/receive/joinCode.ts
index 4c0d865..a86fae8 100644
--- a/packages/domain/src/receive/joinCode.ts
+++ b/packages/domain/src/receive/joinCode.ts
@@ -6,6 +6,10 @@ export function buildJoinUrl(topic: string): string {
return `${JOIN_URL_SCHEME}://join/${topic}`
}
+export function buildInviteText(topic: string): string {
+ return `Join my file transfer on AlterSend:\n${buildJoinUrl(topic)}`
+}
+
export function isValidJoinCode(value: string): boolean {
return JOIN_CODE_PATTERN.test(value.trim())
}
diff --git a/skills-lock.json b/skills-lock.json
deleted file mode 100644
index 1d6b935..0000000
--- a/skills-lock.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "version": 1,
- "skills": {
- "app-store-screenshots": {
- "source": "ParthJadhav/app-store-screenshots",
- "sourceType": "github",
- "skillPath": "skills/app-store-screenshots/SKILL.md",
- "computedHash": "5a339bcfe7be93fdb687e0a33946065c5af0c985da04b9887d1dd0811197f6dd"
- }
- }
-}