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
Add sharing option in the native lib (#4)
Denis Lupookov86f43e89cabe
diff --git a/apps/mobile/app.json b/apps/mobile/app.jsonindex e6a883c..1c50755 100644--- a/apps/mobile/app.json+++ b/apps/mobile/app.json@@ -107,6 +107,18 @@"savePhotosPermission": "AlterSend saves received images and videos to your photo library.","isAccessMediaLocationEnabled": false}+ ],+ [+ "expo-share-intent",+ {+ "iosAppGroupIdentifier": "group.com.altersend.mobile",+ "iosActivationRules": {+ "NSExtensionActivationSupportsImageWithMaxCount": 100,+ "NSExtensionActivationSupportsMovieWithMaxCount": 100,+ "NSExtensionActivationSupportsFileWithMaxCount": 100+ },+ "androidIntentFilters": ["*/*"]+ }]],"extra": {diff --git a/apps/mobile/app/+native-intent.ts b/apps/mobile/app/+native-intent.tsnew file mode 100644index 0000000..cccd8fd--- /dev/null+++ b/apps/mobile/app/+native-intent.ts@@ -0,0 +1,12 @@+import { getShareExtensionKey } from 'expo-share-intent'++export function redirectSystemPath({ path }: { path: string; initial: boolean }) {+ try {+ if (path.includes(`dataUrl=${getShareExtensionKey()}`)) {+ return '/'+ }+ return path+ } catch {+ return '/'+ }+}diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsxindex f6d6d87..48b5728 100644--- a/apps/mobile/app/_layout.tsx+++ b/apps/mobile/app/_layout.tsx@@ -20,6 +20,7 @@ import { mobileApi } from '../src/api/mobileApi'import { ToastProvider } from '../src/components/Toast'import { startAppStateBridge } from '../src/lifecycle/appStateBridge'import { startDeepLinkHandler } from '../src/lifecycle/deepLinkHandler'+import { ShareIntentHandler } from '../src/lifecycle/ShareIntentHandler'import { startPhotosCopyEffect } from '../src/transfer/receive'import { initSentry, captureException } from '../src/sentry'@@ -99,6 +100,7 @@ export default function RootLayout() {}}><ToastProvider>+ <ShareIntentHandler /><ThemedStack /></ToastProvider></ErrorBoundary>diff --git a/apps/mobile/package.json b/apps/mobile/package.jsonindex e9d6232..f7c868e 100644--- a/apps/mobile/package.json+++ b/apps/mobile/package.json@@ -53,6 +53,7 @@"expo-linking": "~55.0.13","expo-media-library": "~55.0.15","expo-router": "~55.0.5",+ "expo-share-intent": "^6.1.0","expo-sharing": "~55.0.18","expo-system-ui": "~55.0.9","lucide-react-native": "^1.8.0",diff --git a/apps/mobile/src/lifecycle/ShareIntentHandler.tsx b/apps/mobile/src/lifecycle/ShareIntentHandler.tsxnew file mode 100644index 0000000..7adbf7b--- /dev/null+++ b/apps/mobile/src/lifecycle/ShareIntentHandler.tsx@@ -0,0 +1,29 @@+import { useEffect } from 'react'+import { router } from 'expo-router'+import { useShareIntent } from 'expo-share-intent'+import { replaceSelectedFiles, continueShare, type SelectedFile } from '@altersend/domain'++function toFilePath(path: string): string {+ return path.startsWith('file://') ? path.slice('file://'.length) : path+}++export function ShareIntentHandler() {+ const { hasShareIntent, shareIntent, resetShareIntent } = useShareIntent()++ useEffect(() => {+ if (!hasShareIntent || !shareIntent.files?.length) return++ const files: SelectedFile[] = shareIntent.files.map((f) => ({+ name: f.fileName ?? f.path.split('/').pop() ?? 'file',+ path: toFilePath(f.path),+ size: f.size ?? undefined+ }))++ replaceSelectedFiles(files)+ router.navigate('/send')+ void continueShare(files)+ resetShareIntent()+ }, [hasShareIntent, shareIntent, resetShareIntent])++ return null+}diff --git a/package-lock.json b/package-lock.jsonindex 57110ae..ef44b45 100644--- a/package-lock.json+++ b/package-lock.json@@ -126,6 +126,7 @@"expo-linking": "~55.0.13","expo-media-library": "~55.0.15","expo-router": "~55.0.5",+ "expo-share-intent": "^6.1.0","expo-sharing": "~55.0.18","expo-system-ui": "~55.0.9","lucide-react-native": "^1.8.0",@@ -15417,6 +15418,31 @@"node": ">=20.16.0"}},+ "node_modules/expo-share-intent": {+ "version": "6.1.0",+ "resolved": "https://registry.npmjs.org/expo-share-intent/-/expo-share-intent-6.1.0.tgz",+ "integrity": "sha512-cyGJjpA6ImNR641hj3J1Li/+jcD1ByPvLjgA93s8/ajkAAq42DMZvLi5RzmsWEhX0lBedva+fEhLNGCo+LpWMw==",+ "funding": [+ {+ "type": "github",+ "url": "https://github.com/sponsors/achorein"+ },+ "https://www.buymeacoffee.com/achorein"+ ],+ "license": "MIT",+ "dependencies": {+ "@expo/config-plugins": "~55.0.6",+ "expo-constants": "~55.0.7",+ "expo-linking": "~55.0.7"+ },+ "peerDependencies": {+ "expo": "^55",+ "expo-constants": ">=55.0.7",+ "expo-linking": ">=55.0.7",+ "react": "*",+ "react-native": "*"+ }+ },"node_modules/expo-sharing": {"version": "55.0.19","resolved": "https://registry.npmjs.org/expo-sharing/-/expo-sharing-55.0.19.tgz",diff --git a/packages/domain/src/transfer/commands.ts b/packages/domain/src/transfer/commands.tsindex e46aab8..20b900e 100644--- a/packages/domain/src/transfer/commands.ts+++ b/packages/domain/src/transfer/commands.ts@@ -74,6 +74,11 @@ export const addSelectedFiles = (files: SelectedFile[]): void => {dispatchToTransferStore({ type: 'add_selected_files', files })}+export const replaceSelectedFiles = (files: SelectedFile[]): void => {+ dispatchToTransferStore({ type: 'clear_send_draft' })+ if (files.length > 0) dispatchToTransferStore({ type: 'add_selected_files', files })+}+export const removeSelectedFile = (path: string): void => {dispatchToTransferStore({ type: 'remove_selected_file', path })}