Send files directly between devices over the internet - no cloud storage, no size limits.
TypeScript cross-platformdata-transferdecentralizedfile-sharingfile-transferhole-punchingopen-sourcep2ppeer-to-peerprivacyprivacy-tools
feature: add link and text sharing support (fixes #32) (#36)
Kiran Tej T R0d66dc88ff35
diff --git a/apps/desktop/src/renderer/pages/ReceivePage/ReceiveCompleteView.tsx b/apps/desktop/src/renderer/pages/ReceivePage/ReceiveCompleteView.tsxindex 28c595c..d4051e6 100644--- a/apps/desktop/src/renderer/pages/ReceivePage/ReceiveCompleteView.tsx+++ b/apps/desktop/src/renderer/pages/ReceivePage/ReceiveCompleteView.tsx@@ -29,7 +29,10 @@ export function ReceiveCompleteView() {})}, [])- const totalBytes = incomingFileOffers.reduce((sum, f) => sum + f.size, 0)+ const totalBytes = incomingFileOffers.reduce(+ (sum, f) => sum + (f.kind === 'file' ? f.size : 0),+ 0+ )const fileCount = incomingFileOffers.lengthconst firstSavedTo = Object.values(downloadStates).find((s) => s.savedTo)?.savedTo@@ -84,6 +87,7 @@ export function ReceiveCompleteView() {<div className='min-h-0 flex-1 overflow-y-auto'>{incomingFileOffers.map((file) => {+ if (file.kind !== 'file') return nullconst state = downloadStates[getOfferKey(file)]const savedTo = state?.savedToconst shortPath = savedTo ? shortenHomePath(getParentDir(savedTo)) : nulldiff --git a/apps/desktop/src/renderer/pages/ReceivePage/ReceiveConnectedView.tsx b/apps/desktop/src/renderer/pages/ReceivePage/ReceiveConnectedView.tsxindex c9f3d35..3ae90c6 100644--- a/apps/desktop/src/renderer/pages/ReceivePage/ReceiveConnectedView.tsx+++ b/apps/desktop/src/renderer/pages/ReceivePage/ReceiveConnectedView.tsx@@ -44,15 +44,29 @@ export function ReceiveConnectedView() {const isDownloading = totals.activeCount > 0const allCompleted = hasIncomingFiles && totals.completedCount === incomingFileOffers.length+ const textOffer = incomingFileOffers.find((f) => f.kind === 'text')+ const isTextTransfer = textOffer !== undefined++ const isUrl = useMemo(() => {+ if (textOffer?.kind !== 'text') return false+ try {+ const url = new URL(textOffer.content)+ return url.protocol === 'https:' || url.protocol === 'http:'+ } catch {+ return false+ }+ }, [textOffer])+const downloadAll = async () => {- if (incomingFileOffers.length === 0 || isDownloading) return+ const fileOffers = incomingFileOffers.filter((f) => f.kind === 'file')+ if (fileOffers.length === 0 || isDownloading) return- if (incomingFileOffers.length === 1) {- const selected = await bridgeApi.pickSaveFile(incomingFileOffers[0].name)+ if (fileOffers.length === 1) {+ const selected = await bridgeApi.pickSaveFile(fileOffers[0].name)if (!selected?.path) returntry {- await downloadFiles([createSingleDownloadRequest(incomingFileOffers[0], selected.path)])+ await downloadFiles([createSingleDownloadRequest(fileOffers[0], selected.path)])} catch (error) {console.error('ReceiveConnectedView: single-file download failed', error)}@@ -73,33 +87,60 @@ export function ReceiveConnectedView() {return (<div className='flex h-full min-h-0 w-full flex-1 flex-col'>- <div className='min-h-0 flex-1 overflow-y-auto pr-1'>- <div className='overflow-hidden rounded-[10px] border border-border-primary bg-background-subtle'>- {incomingFileOffers.map((file) => {- const row = getDownloadRowDisplay(file, downloadStates[getOfferKey(file)])- return (- <LinkRow- key={getOfferKey(file)}- file- bare- compact- label={file.name}- size={file.size}- description={row.description}- status={{ label: getDownloadStatusLabel(t, row), tone: row.status.tone }}- progressPercent={row.progressPercent}- />- )- })}+ {isTextTransfer ? (+ <div className='flex-1 flex flex-col justify-center items-center'>+ <div className='p-4 bg-background-subtle rounded-lg border border-border-primary w-full break-words'>+ <p className='text-text-primary text-center select-text'>{textOffer.content}</p>+ </div></div>- </div>+ ) : (+ <div className='min-h-0 flex-1 overflow-y-auto pr-1'>+ <div className='overflow-hidden rounded-[10px] border border-border-primary bg-background-subtle'>+ {incomingFileOffers.map((file) => {+ if (file.kind !== 'file') return null+ const row = getDownloadRowDisplay(file, downloadStates[getOfferKey(file)])+ return (+ <LinkRow+ key={getOfferKey(file)}+ file+ bare+ compact+ label={file.name}+ size={file.size}+ description={row.description}+ status={{ label: getDownloadStatusLabel(t, row), tone: row.status.tone }}+ progressPercent={row.progressPercent}+ />+ )+ })}+ </div>+ </div>+ )}<div className='mt-4 flex shrink-0 items-center justify-end gap-4'><div className='flex shrink-0 items-center gap-2'><Button onClick={clearSession} size='sm' variant='secondary'>{t('common:actions.endSession')}</Button>- {peerCount > 0 && hasIncomingFiles && !allCompleted ? (+ {isTextTransfer ? (+ isUrl ? (+ <Button+ onClick={() => void bridgeApi.openExternalUrl(textOffer.content!)}+ size='sm'+ variant='primary'+ >+ Open Link+ </Button>+ ) : (+ <Button+ onClick={() => void navigator.clipboard.writeText(textOffer.content!)}+ size='sm'+ variant='primary'+ >+ Copy Text+ </Button>+ )+ ) : peerCount > 0 && hasIncomingFiles && !allCompleted ? (<Buttondisabled={isDownloading}icon={<DownloadIcon size={14} />}diff --git a/apps/desktop/src/renderer/pages/ReceivePage/ReceiveDisconnectedView.tsx b/apps/desktop/src/renderer/pages/ReceivePage/ReceiveDisconnectedView.tsxindex e283869..d317499 100644--- a/apps/desktop/src/renderer/pages/ReceivePage/ReceiveDisconnectedView.tsx+++ b/apps/desktop/src/renderer/pages/ReceivePage/ReceiveDisconnectedView.tsx@@ -46,6 +46,7 @@ export function ReceiveDisconnectedView() {{incomingFileOffers.map((file) => {const state = downloadStates[getOfferKey(file)]const isComplete = state?.status === 'completed'+ if (file.kind !== 'file') return nullreturn (<LinkRowkey={getOfferKey(file)}diff --git a/apps/desktop/src/renderer/pages/ReceivePage/index.tsx b/apps/desktop/src/renderer/pages/ReceivePage/index.tsxindex a3a38e6..f3224b6 100644--- a/apps/desktop/src/renderer/pages/ReceivePage/index.tsx+++ b/apps/desktop/src/renderer/pages/ReceivePage/index.tsx@@ -38,7 +38,10 @@ export default function ReceivePage() {peerCount})- const totalBytes = incomingFileOffers.reduce((sum, f) => sum + f.size, 0)+ const totalBytes = incomingFileOffers.reduce(+ (sum, f) => sum + (f.kind === 'file' ? f.size : 0),+ 0+ )const { title, description } = getReceivePageCopy(t, step, incomingFileOffers.length, totalBytes)const connectedBadge =diff --git a/apps/desktop/src/renderer/pages/SendPage/SelectFilesView.tsx b/apps/desktop/src/renderer/pages/SendPage/SelectFilesView.tsxindex 5135378..e5aaa7a 100644--- a/apps/desktop/src/renderer/pages/SendPage/SelectFilesView.tsx+++ b/apps/desktop/src/renderer/pages/SendPage/SelectFilesView.tsx@@ -5,9 +5,11 @@ import {addSelectedFiles,normalizeSelectedFiles,removeSelectedFile,- useTransferStore+ useTransferStore,+ ENABLE_TEXT_SHARING} from '@altersend/domain'import { bridgeApi } from '../../api/bridgeApi'+import { Input, Button } from '@altersend/components'interface DataTransferEntryLike {isDirectory: boolean@@ -28,6 +30,7 @@ export function SelectFilesView() {const selectedFiles = useTransferStore((s) => s.selectedFiles)const [isDropZoneDragging, setIsDropZoneDragging] = useState(false)const [selectionError, setSelectionError] = useState<string | null>(null)+ const [textInput, setTextInput] = useState('')const hasSelectedFiles = selectedFiles.length > 0@@ -70,6 +73,23 @@ export function SelectFilesView() {}}+ const addTextItem = () => {+ const text = textInput.trim()+ if (!text) return+ const name = text.length > 20 ? text.substring(0, 20) + '...' : text+ addSelectedFiles([+ {+ name,+ path: `text-${Date.now()}`,+ kind: 'text',+ content: text,+ isTemporary: true,+ size: text.length+ }+ ])+ setTextInput('')+ }+return (<div className='flex flex-col gap-4'><div>@@ -120,6 +140,31 @@ export function SelectFilesView() {</div>) : null}+ {ENABLE_TEXT_SHARING && (+ <div className='flex flex-row gap-2 mt-2 items-center'>+ <div className='flex-1'>+ <Input+ placeholder='Type a message or paste a link...'+ value={textInput}+ onChange={(e: React.ChangeEvent<HTMLInputElement>) => setTextInput(e.target.value)}+ onKeyDown={(e) => {+ if (e.key === 'Enter' && textInput.trim().length > 0) {+ addTextItem()+ }+ }}+ />+ </div>+ <Button+ disabled={textInput.trim().length === 0}+ onClick={addTextItem}+ size='sm'+ variant='secondary'+ >+ Add+ </Button>+ </div>+ )}+<ErrorBanner message={selectionError} /></div>)diff --git a/apps/mobile/app/(tabs)/receive/index.tsx b/apps/mobile/app/(tabs)/receive/index.tsxindex 5af1f8d..89d08a5 100644--- a/apps/mobile/app/(tabs)/receive/index.tsx+++ b/apps/mobile/app/(tabs)/receive/index.tsx@@ -94,7 +94,10 @@ export default function ReceiveScreen() {}}, [step])- const totalBytes = incomingFileOffers.reduce((sum, file) => sum + file.size, 0)+ const totalBytes = incomingFileOffers.reduce(+ (sum, file) => sum + (file.kind === 'file' ? file.size : 0),+ 0+ )const copy = getReceivePageCopy(t, step, incomingFileOffers.length, totalBytes)const title = step === 'join' ? t('receive:page.tabTitle') : copy.titleconst description = step === 'join' ? t('receive:page.join.mobileDescription') : copy.descriptiondiff --git a/apps/mobile/app/receive/incoming.tsx b/apps/mobile/app/receive/incoming.tsxindex d8a895f..b7d6f8f 100644--- a/apps/mobile/app/receive/incoming.tsx+++ b/apps/mobile/app/receive/incoming.tsx@@ -83,7 +83,10 @@ export default function ReceiveIncomingScreen() {})}, [navigation, handleEndSession, t, theme.colors.colorTextPrimary])- const totalBytes = incomingFileOffers.reduce((sum, f) => sum + f.size, 0)+ const totalBytes = incomingFileOffers.reduce(+ (sum, f) => sum + (f.kind === 'file' ? f.size : 0),+ 0+ )const { title, description } = getReceivePageCopy(t, step, incomingFileOffers.length, totalBytes)const handleDownloadAll = async () => {diff --git a/apps/mobile/src/transfer/receive/utils/openCompletedFile.ts b/apps/mobile/src/transfer/receive/utils/openCompletedFile.tsindex ed1cf3c..416252b 100644--- a/apps/mobile/src/transfer/receive/utils/openCompletedFile.ts+++ b/apps/mobile/src/transfer/receive/utils/openCompletedFile.ts@@ -21,7 +21,8 @@ export function openCompletedFile(offerKey: string): void {if (item.destination === 'downloads') {const offer = state.incomingFileOffers.find((f) => f.id === offerKey)- void openDownload(item.savedTo, guessMimeType(offer?.name ?? '')).catch((err) =>+ const name = offer?.kind === 'file' ? offer.name : ''+ void openDownload(item.savedTo, guessMimeType(name)).catch((err) =>console.error('openCompletedFile: openDownload failed', err))returndiff --git a/apps/mobile/src/transfer/receive/utils/photosCopyEffect.ts b/apps/mobile/src/transfer/receive/utils/photosCopyEffect.tsindex e9fa5d6..88e5bf4 100644--- a/apps/mobile/src/transfer/receive/utils/photosCopyEffect.ts+++ b/apps/mobile/src/transfer/receive/utils/photosCopyEffect.ts@@ -77,7 +77,7 @@ export function startPhotosCopyEffect(): () => void {if (!item.savedTo) continueconst offer = incomingFileOffers.find((f) => f.id === offerKey)- if (!offer) continue+ if (offer?.kind !== 'file') continueprocessed.add(offerKey)void routeOne(offerKey, item.savedTo, offer.name)diff --git a/apps/mobile/src/transfer/receive/views/ReceiveCompleteView.tsx b/apps/mobile/src/transfer/receive/views/ReceiveCompleteView.tsxindex 9a80c28..5fb126e 100644--- a/apps/mobile/src/transfer/receive/views/ReceiveCompleteView.tsx+++ b/apps/mobile/src/transfer/receive/views/ReceiveCompleteView.tsx@@ -15,7 +15,10 @@ export function ReceiveCompleteView() {const onOpenFile = openCompletedFileconst { theme } = useTheme()- const totalBytes = incomingFileOffers.reduce((sum, f) => sum + f.size, 0)+ const totalBytes = incomingFileOffers.reduce(+ (sum, f) => sum + (f.kind === 'file' ? f.size : 0),+ 0+ )const fileCount = incomingFileOffers.lengthreturn (@@ -57,6 +60,7 @@ export function ReceiveCompleteView() {]}>{incomingFileOffers.map((file, index) => {+ if (file.kind !== 'file') return nullconst offerKey = getOfferKey(file)const state = downloadStates[offerKey]const isComplete = state?.status === 'completed'diff --git a/apps/mobile/src/transfer/receive/views/ReceiveIncomingView.tsx b/apps/mobile/src/transfer/receive/views/ReceiveIncomingView.tsxindex f1e3315..438f6dd 100644--- a/apps/mobile/src/transfer/receive/views/ReceiveIncomingView.tsx+++ b/apps/mobile/src/transfer/receive/views/ReceiveIncomingView.tsx@@ -1,6 +1,7 @@import React from 'react'-import { View, StyleSheet } from 'react-native'-import { LinkRow, useTheme } from '@altersend/components'+import { View, StyleSheet, Linking } from 'react-native'+import * as Clipboard from 'expo-clipboard'+import { LinkRow, Button, useTheme } from '@altersend/components'import { getDownloadRowDisplay, getOfferKey, useTransferStore } from '@altersend/domain'import { useTranslation } from '@altersend/locales'import { Text } from '@/src/components/ThemedText'@@ -11,9 +12,47 @@ export function ReceiveIncomingView() {const downloadStates = useTransferStore((s) => s.receiveDownloadStates)const { theme } = useTheme()+ const textOffer = incomingFileOffers.find((f) => f.kind === 'text')+ const isTextTransfer = textOffer !== undefined++ const isUrl = React.useMemo(() => {+ if (textOffer?.kind !== 'text') return false+ try {+ const url = new URL(textOffer.content)+ return url.protocol === 'https:' || url.protocol === 'http:'+ } catch {+ return false+ }+ }, [textOffer])+return (<View style={styles.container}>- {incomingFileOffers.length > 0 ? (+ {isTextTransfer ? (+ <View style={styles.textContainer}>+ <Text style={[styles.textContent, { color: theme.colors.colorTextPrimary }]}>+ {textOffer.content}+ </Text>+ <View style={styles.textActions}>+ {isUrl ? (+ <Button+ onClick={() => void Linking.openURL(textOffer.content!)}+ size='sm'+ variant='primary'+ >+ {t('common:actions.openLink', { defaultValue: 'Open Link' })}+ </Button>+ ) : (+ <Button+ onClick={() => void Clipboard.setStringAsync(textOffer.content!)}+ size='sm'+ variant='primary'+ >+ {t('common:actions.copyText', { defaultValue: 'Copy Text' })}+ </Button>+ )}+ </View>+ </View>+ ) : incomingFileOffers.length > 0 ? (<Viewstyle={[styles.card,@@ -24,6 +63,7 @@ export function ReceiveIncomingView() {]}>{incomingFileOffers.map((file, index) => {+ if (file.kind !== 'file') return nullconst row = getDownloadRowDisplay(file, downloadStates[getOfferKey(file)])return (<LinkRow@@ -60,5 +100,19 @@ const styles = StyleSheet.create({},waitingText: {fontSize: 13+ },+ textContainer: {+ flex: 1,+ justifyContent: 'center',+ alignItems: 'center',+ gap: 16+ },+ textContent: {+ fontSize: 16,+ textAlign: 'center'+ },+ textActions: {+ flexDirection: 'row',+ gap: 8}})diff --git a/apps/mobile/src/transfer/receive/views/ReceiveInterruptedView.tsx b/apps/mobile/src/transfer/receive/views/ReceiveInterruptedView.tsxindex 31d2c5f..7786bbf 100644--- a/apps/mobile/src/transfer/receive/views/ReceiveInterruptedView.tsx+++ b/apps/mobile/src/transfer/receive/views/ReceiveInterruptedView.tsx@@ -86,6 +86,7 @@ export function ReceiveInterruptedView({]}>{incomingFileOffers.map((file, index) => {+ if (file.kind !== 'file') return nullconst offerKey = getOfferKey(file)const state = downloadStates[offerKey]const isComplete = state?.status === 'completed'diff --git a/apps/mobile/src/transfer/send/views/SelectFilesView.tsx b/apps/mobile/src/transfer/send/views/SelectFilesView.tsxindex 6c67f61..a011e50 100644--- a/apps/mobile/src/transfer/send/views/SelectFilesView.tsx+++ b/apps/mobile/src/transfer/send/views/SelectFilesView.tsx@@ -6,9 +6,17 @@ import {addSelectedFiles,removeSelectedFile,useTransferStore,+ ENABLE_TEXT_SHARING,type SelectedFile} from '@altersend/domain'-import { DropZoneLink, ErrorBanner, FileDropZone, LinkRow } from '@altersend/components'+import {+ DropZoneLink,+ ErrorBanner,+ FileDropZone,+ LinkRow,+ Input,+ Button+} from '@altersend/components'import { useTranslation } from '@altersend/locales'function uriToFilePath(uri: string): string {@@ -25,6 +33,7 @@ export function SelectFilesView() {const { t } = useTranslation(['send', 'common'])const selectedFiles = useTransferStore((s) => s.selectedFiles)const [selectionError, setSelectionError] = useState<string | null>(null)+ const [textInput, setTextInput] = useState('')const hasSelectedFiles = selectedFiles.length > 0@@ -105,6 +114,23 @@ export function SelectFilesView() {])}+ const addTextItem = () => {+ const text = textInput.trim()+ if (!text) return+ const name = text.length > 20 ? text.substring(0, 20) + '...' : text+ addSelectedFiles([+ {+ name,+ path: `text-${Date.now()}`,+ kind: 'text',+ content: text,+ isTemporary: true,+ size: text.length+ }+ ])+ setTextInput('')+ }+return (<View style={styles.container}><View style={styles.dropZoneContainer}>@@ -144,6 +170,28 @@ export function SelectFilesView() {</View>)}+ {ENABLE_TEXT_SHARING && (+ <View style={styles.textInputRow}>+ <View style={styles.textInputWrapper}>+ <Input+ placeholder={t('send:actions.typeMessageOrLink', {+ defaultValue: 'Type a message or link...'+ })}+ value={textInput}+ onChange={(e: React.ChangeEvent<HTMLInputElement>) => setTextInput(e.target.value)}+ />+ </View>+ <Button+ disabled={textInput.trim().length === 0}+ onClick={addTextItem}+ size='sm'+ variant='secondary'+ >+ {t('common:actions.add', { defaultValue: 'Add' })}+ </Button>+ </View>+ )}+<ErrorBanner message={selectionError} /></View>)@@ -158,5 +206,14 @@ const styles = StyleSheet.create({},fileList: {gap: 8+ },+ textInputRow: {+ flexDirection: 'row',+ alignItems: 'center',+ gap: 8,+ marginTop: 8+ },+ textInputWrapper: {+ flex: 1}})diff --git a/packages/core/src/worklet/rpc/protocol.ts b/packages/core/src/worklet/rpc/protocol.tsindex e7a17b4..ff06fee 100644--- a/packages/core/src/worklet/rpc/protocol.ts+++ b/packages/core/src/worklet/rpc/protocol.ts@@ -1,5 +1,5 @@import b4a from 'b4a'-import type { FileOffer, PeerControlMessage } from '../transfer/control-channel'+import type { TransferOffer, PeerControlMessage } from '../transfer/control-channel'import type { RememberedPeer } from '../peers/remembered-peer'import type { DeviceSecretInit } from '../identity/device-identity-store'import type {@@ -45,6 +45,8 @@ export interface JoinReply {export interface ShareFileRequest {path: stringisTemporary?: boolean+ kind?: 'file' | 'text'+ content?: string}export interface ShareFilesReply {@@ -134,12 +136,13 @@ export type RendererTransferEvent =| PairingPeerConnectedEvent| PeerControlMessageexport type WorkerTransferEvent = WorkerReadyEvent | RendererTransferEvent-export type IncomingFileOffer = FileOffer+export type IncomingFileOffer = TransferOfferexport interface TransferRPC {host(): Promise<HostReply>join(topic: string): Promise<JoinReply>shareFiles(files: ShareFileRequest[]): Promise<ShareFilesReply>+downloadFiles(files: DownloadFileRequest[]): Promise<DownloadFilesReply>disconnect(): Promise<DisconnectReply>closePeers(): Promise<void>diff --git a/packages/core/src/worklet/transfer/control-channel.ts b/packages/core/src/worklet/transfer/control-channel.tsindex ed8b423..25267fb 100644--- a/packages/core/src/worklet/transfer/control-channel.ts+++ b/packages/core/src/worklet/transfer/control-channel.ts@@ -13,13 +13,22 @@ export interface FileOffer {path: stringsize: numberdriveKey: string- content?: string+ kind: 'file'}+export interface TextOffer {+ id: string+ transferId: string+ kind: 'text'+ content: string+}++export type TransferOffer = FileOffer | TextOffer+export interface TransferReady {type: 'transfer-ready'transferId: string- files: FileOffer[]+ files: TransferOffer[]}export interface TransferStart {diff --git a/packages/core/src/worklet/transfer/control-validation.test.ts b/packages/core/src/worklet/transfer/control-validation.test.tsindex 32c9ffc..a12100b 100644--- a/packages/core/src/worklet/transfer/control-validation.test.ts+++ b/packages/core/src/worklet/transfer/control-validation.test.ts@@ -10,7 +10,8 @@ const validFileOffer = {name: 'photo.jpg',path: '/photo.jpg',size: 1024,- driveKey: 'abc123'+ driveKey: 'abc123',+ kind: 'file'}describe('isValidControlMessage', () => {diff --git a/packages/core/src/worklet/transfer/control-validation.ts b/packages/core/src/worklet/transfer/control-validation.tsindex 41ed4f4..5f7c78e 100644--- a/packages/core/src/worklet/transfer/control-validation.ts+++ b/packages/core/src/worklet/transfer/control-validation.ts@@ -9,6 +9,7 @@ import {type DeviceInvite,type DeviceInviteResponse,type FileOffer,+ type TextOffer,type PairingInfo,type RememberVote,type Recognition,@@ -19,6 +20,7 @@ import {const MAX_ID_LEN = 128const MAX_PATH_LEN = 4096+const MAX_CONTENT_LEN = 65_536const MAX_MESSAGE_LEN = 1024const MAX_FILES_PER_TRANSFER = 10_000const MAX_DISPLAY_NAME_LEN = 256@@ -33,7 +35,7 @@ function isValidSignatureHex(x: unknown): x is string {return typeof x === 'string' && SIGNATURE_HEX_RE.test(x)}-function isOptionalBoundedString(x: unknown, maxLen: number): boolean {+function _isOptionalBoundedString(x: unknown, maxLen: number): boolean {return x === undefined || (typeof x === 'string' && x.length <= maxLen)}@@ -51,10 +53,29 @@ function isValidFileOffer(x: unknown): x is FileOffer {isBoundedString(o.path, MAX_PATH_LEN) &&isNonNegativeInteger(o.size) &&isBoundedString(o.driveKey, MAX_ID_LEN) &&- isOptionalBoundedString(o.content, MAX_PATH_LEN)+ o.kind === 'file')}+function isValidTextOffer(x: unknown): x is TextOffer {+ if (!x || typeof x !== 'object') return false+ const o = x as Partial<TextOffer>+ return (+ isBoundedString(o.id, MAX_ID_LEN) &&+ isBoundedString(o.transferId, MAX_ID_LEN) &&+ o.kind === 'text' &&+ isBoundedString(o.content, MAX_CONTENT_LEN)+ )+}++function isValidTransferOffer(x: unknown): boolean {+ if (!x || typeof x !== 'object') return false+ const kind = (x as { kind?: unknown }).kind+ if (kind === 'file') return isValidFileOffer(x)+ if (kind === 'text') return isValidTextOffer(x)+ return false+}+export function isValidControlMessage(x: unknown): x is PeerControlMessage {if (!x || typeof x !== 'object') return falseconst m = x as { type?: unknown; protocolVersion?: unknown }@@ -76,7 +97,7 @@ export function isValidControlMessage(x: unknown): x is PeerControlMessage {isBoundedString(v.transferId, MAX_ID_LEN) &&Array.isArray(v.files) &&v.files.length <= MAX_FILES_PER_TRANSFER &&- v.files.every(isValidFileOffer)+ v.files.every(isValidTransferOffer))}case 'download-request': {diff --git a/packages/core/src/worklet/transfer/orchestrator.ts b/packages/core/src/worklet/transfer/orchestrator.tsindex a2c9b4a..b3ea955 100644--- a/packages/core/src/worklet/transfer/orchestrator.ts+++ b/packages/core/src/worklet/transfer/orchestrator.ts@@ -34,6 +34,8 @@ import {type DownloadProgress,type DownloadRequest,type PeerControlMessage,+ type TextOffer,+ type TransferOffer,type TransferReady,type TransferStart} from './control-channel'@@ -383,10 +385,10 @@ export class TransferOrchestrator implements TransferRPC {async shareFiles(requests: ShareFileRequest[]): Promise<ShareFilesReply> {if (!Array.isArray(requests) || requests.length === 0) {- throw new BadRequestError('Missing files to share')+ throw new BadRequestError('Missing items to share')}if (this.suspended) {- throw new BadRequestError('Cannot share files while suspended')+ throw new BadRequestError('Cannot share items while suspended')}if (this.role === 'receiver') {@@ -396,11 +398,14 @@ export class TransferOrchestrator implements TransferRPC {await this.storage.ready()try {- const { files, totalBytes, errors } = await this.storage.sender.scanFiles(requests)+ const fileRequests = requests.filter((r) => r.kind !== 'text')+ const textRequests = requests.filter((r) => r.kind === 'text')++ const { files, totalBytes, errors } = await this.storage.sender.scanFiles(fileRequests)for (const error of errors) this.sendError(error)- if (files.length === 0) {- this.sendError('No valid files were selected to share. Folders are not supported yet.')+ if (files.length === 0 && textRequests.length === 0) {+ this.sendError('No valid items were selected to share. Folders are not supported yet.')return { acceptedFiles: 0 }}@@ -410,7 +415,7 @@ export class TransferOrchestrator implements TransferRPC {this.activeTransfer = {type: 'transfer-start',transferId,- totalFiles: files.length,+ totalFiles: files.length + textRequests.length,totalBytes}this.activeTransferReady = null@@ -420,7 +425,7 @@ export class TransferOrchestrator implements TransferRPC {this.inflightAbort = controllertry {- const offers = await this.storage.sender.stageFiles(+ const offers: TransferOffer[] = await this.storage.sender.stageFiles(files,transferId,(file) => {@@ -429,6 +434,17 @@ export class TransferOrchestrator implements TransferRPC {controller.signal)+ for (const req of textRequests) {+ if (!req.content || req.content.trim() === '') continue+ const textOffer: TextOffer = {+ id: createTransferId(),+ transferId,+ kind: 'text',+ content: req.content+ }+ offers.push(textOffer)+ }+this.activeTransferReady = { type: 'transfer-ready', transferId, files: offers }this.swarm.broadcast(this.activeTransferReady)diff --git a/packages/core/src/worklet/transfer/sender.ts b/packages/core/src/worklet/transfer/sender.tsindex 9247e65..7a629c4 100644--- a/packages/core/src/worklet/transfer/sender.ts+++ b/packages/core/src/worklet/transfer/sender.ts@@ -141,7 +141,8 @@ export class TransferSender {name: file.fileName,path: file.sourcePath,size: file.size,- driveKey: this.driveKey+ driveKey: this.driveKey,+ kind: 'file'})}diff --git a/packages/domain/src/flags.ts b/packages/domain/src/flags.tsnew file mode 100644index 0000000..db70f11--- /dev/null+++ b/packages/domain/src/flags.ts@@ -0,0 +1 @@+export const ENABLE_TEXT_SHARING = falsediff --git a/packages/domain/src/index.ts b/packages/domain/src/index.tsindex 9087375..8f8ea65 100644--- a/packages/domain/src/index.ts+++ b/packages/domain/src/index.ts@@ -21,6 +21,7 @@ export * from './receive/pageUi'export * from './receive/joinCode'export * from './receive/downloadModel'export * from './transfer'+export * from './flags'export * from './onboarding'export * from './useSimulatedLoading'diff --git a/packages/domain/src/receive/downloadModel.ts b/packages/domain/src/receive/downloadModel.tsindex f0a62af..2b99fdd 100644--- a/packages/domain/src/receive/downloadModel.ts+++ b/packages/domain/src/receive/downloadModel.ts@@ -60,7 +60,7 @@ export function createDownloadStateMap(next[key] = current[key] ?? {status: 'idle',bytesTransferred: 0,- totalBytes: file.size+ totalBytes: file.kind === 'file' ? file.size : 0}}@@ -71,7 +71,7 @@ export function getDownloadRowDisplay(file: IncomingFileOffer,state: DownloadItemState | undefined): DownloadRowDisplay {- const totalBytes = state?.totalBytes || file.size+ const totalBytes = state?.totalBytes || (file.kind === 'file' ? file.size : 0)const percent = getProgressPercent(state?.bytesTransferred ?? 0, totalBytes)const isCompleted = state?.status === 'completed'const isActive = state?.status === 'downloading' && totalBytes > 0@@ -125,7 +125,9 @@ export function resolveOfferKey(offers: IncomingFileOffer[], message: ReceiveDowif (match) return getOfferKey(match)}- const match = offers.find((offer) => offer.name === message.file && offer.path === message.path)+ const match = offers.find(+ (offer) => offer.kind === 'file' && offer.name === message.file && offer.path === message.path+ )return match ? getOfferKey(match) : null}@@ -200,12 +202,13 @@ export function getDownloadTotals(files: IncomingFileOffer[],states: Record<string, DownloadItemState>): DownloadTotals {- const totalBytes = files.reduce((sum, file) => sum + file.size, 0)+ const fileOffers = files.filter((f) => f.kind === 'file')+ const totalBytes = fileOffers.reduce((sum, file) => sum + file.size, 0)let bytesTransferred = 0let completedCount = 0let activeCount = 0- for (const file of files) {+ for (const file of fileOffers) {const state = states[getOfferKey(file)]if (!state) continue@@ -234,6 +237,7 @@ export function createSingleDownloadRequest(file: IncomingFileOffer,targetPath: string): DownloadFileRequest {+ if (file.kind !== 'file') throw new Error('createSingleDownloadRequest: expected FileOffer')return {transferId: file.transferId,fileId: file.id,@@ -249,13 +253,15 @@ export function createDirectoryDownloadRequests(files: IncomingFileOffer[],targetDir: string): DownloadFileRequest[] {- return files.map((file) => ({- transferId: file.transferId,- fileId: file.id,- driveKey: file.driveKey,- path: file.path,- name: file.name,- size: file.size,- targetDir- }))+ return files+ .filter((f) => f.kind === 'file')+ .map((file) => ({+ transferId: file.transferId,+ fileId: file.id,+ driveKey: file.driveKey,+ path: file.path,+ name: file.name,+ size: file.size,+ targetDir+ }))}diff --git a/packages/domain/src/send/draftTypes.ts b/packages/domain/src/send/draftTypes.tsindex 363b5b4..1f0e5d5 100644--- a/packages/domain/src/send/draftTypes.ts+++ b/packages/domain/src/send/draftTypes.ts@@ -3,6 +3,8 @@ export interface SelectedFile {path: stringsize?: numberisTemporary?: boolean+ kind?: 'file' | 'text'+ content?: string}export type SenderUploadStatus = 'waiting' | 'uploading' | 'completed'diff --git a/packages/domain/src/transfer/commands.ts b/packages/domain/src/transfer/commands.tsindex 78f5d88..20d269c 100644--- a/packages/domain/src/transfer/commands.ts+++ b/packages/domain/src/transfer/commands.ts@@ -234,7 +234,9 @@ export const continueShare = async (files: SelectedFile[]): Promise<void> => {const fileRequests: ShareFileRequest[] = files.map((file) => ({path: file.path,- isTemporary: file.isTemporary+ isTemporary: file.isTemporary,+ kind: file.kind,+ content: file.content}))dispatchToTransferStore({diff --git a/packages/domain/src/transfer/reducer.test.ts b/packages/domain/src/transfer/reducer.test.tsindex 9286775..de33388 100644--- a/packages/domain/src/transfer/reducer.test.ts+++ b/packages/domain/src/transfer/reducer.test.ts@@ -18,7 +18,8 @@ const offer = (id: string, name: string): IncomingFileOffer => ({name,path: `/files/${name}`,size: 1024,- driveKey: 'drive-1'+ driveKey: 'drive-1',+ kind: 'file'})const apply = (state: TransferSessionState, action: TransferAction) =>diff --git a/packages/domain/src/transfer/reducer.ts b/packages/domain/src/transfer/reducer.tsindex 613f222..8ad968d 100644--- a/packages/domain/src/transfer/reducer.ts+++ b/packages/domain/src/transfer/reducer.ts@@ -59,10 +59,8 @@ function mergeIncomingFileOffers(current: TransferSessionState['incomingFileOffers'],nextFiles: TransferSessionState['incomingFileOffers']) {- const existingKeys = new Set(current.map((offer) => `${offer.driveKey}:${offer.path}`))- const uniqueNextFiles = nextFiles.filter(- (offer) => !existingKeys.has(`${offer.driveKey}:${offer.path}`)- )+ const existingIds = new Set(current.map((offer) => offer.id))+ const uniqueNextFiles = nextFiles.filter((offer) => !existingIds.has(offer.id))return uniqueNextFiles.length > 0 ? [...current, ...uniqueNextFiles] : current}