Skip to content

Commit

Permalink
Merge branch 'dev' into fix-camera-on-calls
Browse files Browse the repository at this point in the history
  • Loading branch information
stavares843 authored Dec 18, 2024
2 parents e7b6327 + 0a92384 commit 8ae506b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ios/App/App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<true/>
<key>UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>UISupportsDocumentBrowser</key>
<true/>
<key>NSMicrophoneUsageDescription</key>
Expand Down
18 changes: 18 additions & 0 deletions ios/App/PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<!-- Add this dict entry to the array if the PrivacyInfo file already exists -->
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>C617.1</string>
</array>
</dict>
</array>
</dict>
</plist>
1 change: 1 addition & 0 deletions src/lib/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions src/lib/wasm/ConstellationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class ConstellationStore {
return regex.test(path)
}

async downloadFile(fileName: string): Promise<Result<WarpError, Blob>> {
async downloadFile(fileName: string): Promise<Result<WarpError, Buffer>> {
const constellation = get(this.constellationWritable)
if (constellation) {
try {
Expand All @@ -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))
Expand Down
37 changes: 36 additions & 1 deletion src/routes/files/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 8ae506b

Please sign in to comment.