diff --git a/android/app/capacitor.build.gradle b/android/app/capacitor.build.gradle index fbf30d7..2b52ff7 100644 --- a/android/app/capacitor.build.gradle +++ b/android/app/capacitor.build.gradle @@ -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') diff --git a/android/capacitor.settings.gradle b/android/capacitor.settings.gradle index 88aa349..c946a17 100644 --- a/android/capacitor.settings.gradle +++ b/android/capacitor.settings.gradle @@ -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') diff --git a/package.json b/package.json index 844eedf..4cad283 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 01b73ba..ddca6a1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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 diff --git a/src/utils/download.ts b/src/utils/download.ts index 9abc35c..87e5576 100644 --- a/src/utils/download.ts +++ b/src/utils/download.ts @@ -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" }); }