From 0a92384346ecace4892a7361bc2247e7588fcf7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Gon=C3=A7alves=20Marchi?= Date: Wed, 18 Dec 2024 15:01:43 -0300 Subject: [PATCH 1/2] fix(Mobile): Fix download files from storage (#944) --- ios/App/App/Info.plist | 2 ++ ios/App/PrivacyInfo.xcprivacy | 18 +++++++++++++++ src/lib/lang/en.json | 1 + src/lib/wasm/ConstellationStore.ts | 5 ++-- src/routes/files/+page.svelte | 37 +++++++++++++++++++++++++++++- 5 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 ios/App/PrivacyInfo.xcprivacy diff --git a/ios/App/App/Info.plist b/ios/App/App/Info.plist index f71c543b3..1d468b3cb 100644 --- a/ios/App/App/Info.plist +++ b/ios/App/App/Info.plist @@ -24,6 +24,8 @@ UIFileSharingEnabled + LSSupportsOpeningDocumentsInPlace + UISupportsDocumentBrowser NSMicrophoneUsageDescription diff --git a/ios/App/PrivacyInfo.xcprivacy b/ios/App/PrivacyInfo.xcprivacy new file mode 100644 index 000000000..c8f5d51fa --- /dev/null +++ b/ios/App/PrivacyInfo.xcprivacy @@ -0,0 +1,18 @@ + + + + + NSPrivacyAccessedAPITypes + + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategoryFileTimestamp + NSPrivacyAccessedAPITypeReasons + + C617.1 + + + + + \ No newline at end of file diff --git a/src/lib/lang/en.json b/src/lib/lang/en.json index 923d5e7c8..b88559fb7 100644 --- a/src/lib/lang/en.json +++ b/src/lib/lang/en.json @@ -189,6 +189,7 @@ "dragging_files": "Dragging {count} files for upload", "unknown": "UNKNOWN", "download": "Download", + "shareFileCanceled": "File sharing canceled", "rename": "Rename", "share": "Share", "share.selectChats": "Select Chats", diff --git a/src/lib/wasm/ConstellationStore.ts b/src/lib/wasm/ConstellationStore.ts index d3bbd3516..205d9fb2a 100644 --- a/src/lib/wasm/ConstellationStore.ts +++ b/src/lib/wasm/ConstellationStore.ts @@ -288,7 +288,7 @@ class ConstellationStore { return regex.test(path) } - async downloadFile(fileName: string): Promise> { + async downloadFile(fileName: string): Promise> { const constellation = get(this.constellationWritable) if (constellation) { try { @@ -308,8 +308,7 @@ class ConstellationStore { } } finally { const combinedArray = Buffer.concat(chunks) - const blob = new Blob([new Uint8Array(combinedArray)], { type: "application/octet-stream" }) - return success(blob) + return success(combinedArray) } } catch (error) { return failure(handleErrors(error)) diff --git a/src/routes/files/+page.svelte b/src/routes/files/+page.svelte index 3c47caa10..ecfac7813 100644 --- a/src/routes/files/+page.svelte +++ b/src/routes/files/+page.svelte @@ -25,6 +25,10 @@ import { Store } from "$lib/state/Store" import path from "path" import { MultipassStoreInstance } from "$lib/wasm/MultipassStore" + import { Share } from "@capacitor/share" + import { isAndroidOriOS } from "$lib/utils/Mobile" + import { Filesystem, Directory, Encoding } from "@capacitor/filesystem" + import { log } from "$lib/utils/Logger" export let browseFilesForChatMode: boolean = false @@ -456,7 +460,12 @@ err => { Store.addToastNotification(new ToastMessage("", err, 2)) }, - blob => { + async combinedArray => { + if (isAndroidOriOS()) { + await shareFile(fileName, combinedArray) + return + } + const blob = new Blob([new Uint8Array(combinedArray)], { type: "application/octet-stream" }) const url = URL.createObjectURL(blob) const a = document.createElement("a") a.href = url @@ -469,6 +478,32 @@ ) } + async function shareFile(fileName: string, combinedArray: Buffer) { + try { + const base64Data = combinedArray.toString("base64") + + const filePath = await Filesystem.writeFile({ + path: fileName, + data: base64Data!, + directory: Directory.Cache, + }) + + await Share.share({ + text: fileName, + url: filePath.uri, + }) + + log.info(`File shared: ${fileName} successfully`) + } catch (error) { + let errorMessage = `${error}` + log.error("Error when to share file:", fileName, "Error:", errorMessage) + if (errorMessage.includes("Share canceled")) { + Store.addToastNotification(new ToastMessage("", $_("files.shareFileCanceled"), 2)) + return + } + } + } + $: chats = UIStore.state.chats $: activeChat = Store.state.activeChat From 4347185dd8ff960be582912d9139e4cfffd084fc Mon Sep 17 00:00:00 2001 From: Luis E <35935591+luisecm@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:23:13 -0600 Subject: [PATCH 2/2] update(friends): make add friend input visible on mobile (#956) --- src/lib/lang/en.json | 4 +++- src/routes/friends/+page.svelte | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/lang/en.json b/src/lib/lang/en.json index b88559fb7..65acbd084 100644 --- a/src/lib/lang/en.json +++ b/src/lib/lang/en.json @@ -162,6 +162,7 @@ "request_sent": "You sent a request for {amount}" }, "friends": { + "copy": "Copy", "copy_did": "Copy ID", "block": "Block", "blocked": "Blocked", @@ -170,9 +171,10 @@ "all": "All", "active": "Active", "add": "Add", + "add_friend": "Add Friend", "add_someone": "Add Someone", "search_friends_placeholder": "Search friends", - "find_placeholder": "Enter Friend ID", + "find_placeholder": "Enter Friend DID", "incoming_requests": "Incoming Requests", "outgoing_requests": "Outgoing Requests", "noOutgoing": "No outbound requests.", diff --git a/src/routes/friends/+page.svelte b/src/routes/friends/+page.svelte index 4653ebc79..0dc105a7c 100644 --- a/src/routes/friends/+page.svelte +++ b/src/routes/friends/+page.svelte @@ -260,7 +260,9 @@ bind:value={requestString}> - await copy_did(false), }, ]}> -