Share file instead of download to Documents

This commit is contained in:
Tony Giorgio
2023-10-20 16:46:05 -05:00
committed by Tony Giorgio
parent a8334de655
commit f6d79f155c
5 changed files with 46 additions and 19 deletions

View File

@@ -13,6 +13,7 @@ dependencies {
implementation project(':capacitor-browser')
implementation project(':capacitor-clipboard')
implementation project(':capacitor-filesystem')
implementation project(':capacitor-share')
implementation project(':capacitor-toast')
implementation project(':mutinywallet-barcode-scanner')

View File

@@ -12,7 +12,10 @@ include ':capacitor-clipboard'
project(':capacitor-clipboard').projectDir = new File('../node_modules/.pnpm/@capacitor+clipboard@5.0.6_@capacitor+core@5.2.2/node_modules/@capacitor/clipboard/android')
include ':capacitor-filesystem'
project(':capacitor-filesystem').projectDir = new File('../node_modules/.pnpm/@capacitor+filesystem@5.1.1_@capacitor+core@5.2.2/node_modules/@capacitor/filesystem/android')
project(':capacitor-filesystem').projectDir = new File('../node_modules/.pnpm/@capacitor+filesystem@5.1.4_@capacitor+core@5.2.2/node_modules/@capacitor/filesystem/android')
include ':capacitor-share'
project(':capacitor-share').projectDir = new File('../node_modules/.pnpm/@capacitor+share@5.0.6_@capacitor+core@5.2.2/node_modules/@capacitor/share/android')
include ':capacitor-toast'
project(':capacitor-toast').projectDir = new File('../node_modules/.pnpm/@capacitor+toast@5.0.6_@capacitor+core@5.2.2/node_modules/@capacitor/toast/android')

View File

@@ -47,7 +47,8 @@
"@capacitor/browser": "^5.0.6",
"@capacitor/clipboard": "^5.0.6",
"@capacitor/core": "^5.2.2",
"@capacitor/filesystem": "^5.1.1",
"@capacitor/filesystem": "^5.1.4",
"@capacitor/share": "^5.0.6",
"@capacitor/toast": "^5.0.6",
"@kobalte/core": "^0.9.8",
"@kobalte/tailwindcss": "^0.5.0",

27
pnpm-lock.yaml generated
View File

@@ -1,5 +1,9 @@
lockfileVersion: '6.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
importers:
.:
@@ -20,8 +24,11 @@ importers:
specifier: ^5.2.2
version: 5.2.2
'@capacitor/filesystem':
specifier: ^5.1.1
version: 5.1.1(@capacitor/core@5.2.2)
specifier: ^5.1.4
version: 5.1.4(@capacitor/core@5.2.2)
'@capacitor/share':
specifier: ^5.0.6
version: 5.0.6(@capacitor/core@5.2.2)
'@capacitor/toast':
specifier: ^5.0.6
version: 5.0.6(@capacitor/core@5.2.2)
@@ -1588,14 +1595,22 @@ packages:
tslib: 2.6.1
dev: false
/@capacitor/filesystem@5.1.1(@capacitor/core@5.2.2):
resolution: {integrity: sha512-wq55joyYocsYI0f0UNoDE9TPxI0n4fx+PmejGR5JOYFzrnU8DqcSJ9EREAYAkkoOrmQHrB1vuN9F79XC0PuADw==}
/@capacitor/filesystem@5.1.4(@capacitor/core@5.2.2):
resolution: {integrity: sha512-10EM1KvFMs+pTzxkcflspzxBWcX9sOnS9nTP5Afjr5hn4OxLrwTFySw2Z12Uv6jdN4OnhY3jXtDKXPljXvXILg==}
peerDependencies:
'@capacitor/core': ^5.1.1
dependencies:
'@capacitor/core': 5.2.2
dev: false
/@capacitor/share@5.0.6(@capacitor/core@5.2.2):
resolution: {integrity: sha512-/dVOW7kcuuD7hWB9Z1drArIpEk+5JCoMnMrAs2c7CLp3q5PeaXNJjTkGr6RJ1OtMhsHyXc6DAFwQ4frFkmZsgw==}
peerDependencies:
'@capacitor/core': ^5.0.0
dependencies:
'@capacitor/core': 5.2.2
dev: false
/@capacitor/toast@5.0.6(@capacitor/core@5.2.2):
resolution: {integrity: sha512-djkRHVT8YtLJC1vvOnDU3EfAHfQYqAD7LYEXmSmhYuTnXRIggX93m/NkazwLnnpr95kDbs2VVPM/J6dqqYuJng==}
peerDependencies:
@@ -14062,7 +14077,3 @@ packages:
/yocto-queue@0.1.0:
resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
engines: {node: '>=10'}
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false

View File

@@ -1,5 +1,6 @@
import { Capacitor } from "@capacitor/core";
import { Directory, Encoding, Filesystem } from "@capacitor/filesystem";
import { Share } from "@capacitor/share";
import { Toast } from "@capacitor/toast";
export async function downloadTextFile(
@@ -11,21 +12,31 @@ export async function downloadTextFile(
if (Capacitor.isNativePlatform()) {
try {
const writeFileResult = await Filesystem.writeFile({
path: `${fileName}`,
const fileConfig = {
path: `Exports/${fileName}`,
data: content,
directory: Directory.Documents,
encoding: Encoding.UTF8
});
directory: Directory.Cache,
encoding: Encoding.UTF8,
recursive: true
};
const writeFileResult = await Filesystem.writeFile(fileConfig);
// Share the file
// This is because we save to the cache to get around reinstall issues
// with file storage permissions.
await Share.share({ url: writeFileResult.uri });
await Toast.show({
text: `Saved to ${writeFileResult.uri}`,
text: `File shared successfully`,
duration: "long"
});
} catch (err) {
console.error("Error writing the file:", err);
} catch (error) {
console.error(
"Error creating or sharing the file: ",
JSON.stringify(error)
);
await Toast.show({
text: `Error while saving file`,
text: `Error while saving or sharing file`,
duration: "long"
});
}