@capgo/capacitor-share-target 8.0.56 → 8.0.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Let users share text, links, images and files from other apps straight into your
|
|
|
5
5
|
<a href="https://capgo.app/?ref=plugin_share_target"><img src="https://capgo.app/readme-banner.svg?repo=Cap-go/capacitor-share-target" alt="Capgo - Instant updates for Capacitor" /></a>
|
|
6
6
|
|
|
7
7
|
<div align="center">
|
|
8
|
-
<p><b>Capgo</b>:
|
|
8
|
+
<p><b>Capgo</b>: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.</p>
|
|
9
9
|
<h2><a href="https://capgo.app/register/?ref=plugin_share_target">➡️ Get started for free</a></h2>
|
|
10
10
|
<p>14-day unlimited free trial. No credit card required</p>
|
|
11
11
|
<p><a href="https://capgo.app/consulting/?ref=plugin_share_target">Missing a feature? We'll build the plugin for you 💪</a></p>
|
|
@@ -18,7 +18,7 @@ Let users share text, links, images and files from other apps straight into your
|
|
|
18
18
|
## Key features
|
|
19
19
|
|
|
20
20
|
- **Share event**: the `shareReceived` listener delivers the title, texts and files.
|
|
21
|
-
- **Files**: each shared file comes with its URI, name and MIME type.
|
|
21
|
+
- **Files**: each shared file comes with its URI, name and MIME type. On iOS, your Share Extension must save these attachment details to the App Group.
|
|
22
22
|
- **Android**: receives content through intent filters you set for the MIME types you want.
|
|
23
23
|
- **iOS**: reads content saved by your Share Extension through an App Group set as `appGroupId`.
|
|
24
24
|
- **Platforms**: iOS and Android. iOS needs a Share Extension target. Not available on web.
|
|
@@ -277,6 +277,8 @@ Represents a file shared to the application.
|
|
|
277
277
|
|
|
278
278
|
## Example
|
|
279
279
|
|
|
280
|
+
On Android, successful copies live under the app cache directory `shared_files`. The plugin removes copies older than 24 hours and caps how many are kept. When `files[].uri` is a path under that directory, delete it after you finish processing so large shares do not fill storage. If copying fails, `files[].uri` may be the original content URI instead.
|
|
281
|
+
|
|
280
282
|
Here's a complete example of handling shared content in your app:
|
|
281
283
|
|
|
282
284
|
```typescript
|
|
@@ -23,6 +23,8 @@ public class CapacitorShareTargetPlugin extends Plugin {
|
|
|
23
23
|
|
|
24
24
|
private static final String TAG = "CapacitorShareTarget";
|
|
25
25
|
private static final String pluginVersion = "7.0.0";
|
|
26
|
+
private static final long SHARED_FILE_MAX_AGE_MS = 24L * 60 * 60 * 1000;
|
|
27
|
+
private static final int SHARED_FILE_MAX_COUNT = 50;
|
|
26
28
|
|
|
27
29
|
@Override
|
|
28
30
|
protected void handleOnNewIntent(Intent intent) {
|
|
@@ -59,6 +61,12 @@ public class CapacitorShareTargetPlugin extends Plugin {
|
|
|
59
61
|
|
|
60
62
|
// Get files
|
|
61
63
|
JSArray files = new JSArray();
|
|
64
|
+
File sharedFilesDir = new File(getContext().getCacheDir(), "shared_files");
|
|
65
|
+
if (!sharedFilesDir.exists()) {
|
|
66
|
+
sharedFilesDir.mkdirs();
|
|
67
|
+
}
|
|
68
|
+
evictStaleSharedFiles(sharedFilesDir);
|
|
69
|
+
|
|
62
70
|
if (Intent.ACTION_SEND.equals(action)) {
|
|
63
71
|
Uri fileUri;
|
|
64
72
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
@@ -92,7 +100,6 @@ public class CapacitorShareTargetPlugin extends Plugin {
|
|
|
92
100
|
|
|
93
101
|
// Notify listeners and retain until JavaScript registers to handle cold starts
|
|
94
102
|
notifyListeners("shareReceived", shareData, true);
|
|
95
|
-
Log.d(TAG, "Share received: " + shareData.toString());
|
|
96
103
|
} catch (Exception e) {
|
|
97
104
|
Log.e(TAG, "Error handling shared content", e);
|
|
98
105
|
}
|
|
@@ -178,25 +185,25 @@ public class CapacitorShareTargetPlugin extends Plugin {
|
|
|
178
185
|
cacheDir.mkdirs();
|
|
179
186
|
}
|
|
180
187
|
|
|
181
|
-
|
|
182
|
-
fileName = "shared_file_" + System.currentTimeMillis();
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
File outputFile = new File(cacheDir, fileName);
|
|
188
|
+
File outputFile = File.createTempFile("share-", ".tmp", cacheDir);
|
|
186
189
|
|
|
187
|
-
try (
|
|
188
|
-
InputStream inputStream = getActivity().getContentResolver().openInputStream(uri);
|
|
189
|
-
FileOutputStream outputStream = new FileOutputStream(outputFile)
|
|
190
|
-
) {
|
|
190
|
+
try (InputStream inputStream = getActivity().getContentResolver().openInputStream(uri)) {
|
|
191
191
|
if (inputStream == null) {
|
|
192
|
+
deleteShareCacheFile(outputFile);
|
|
192
193
|
return null;
|
|
193
194
|
}
|
|
194
195
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
196
|
+
try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
|
|
197
|
+
byte[] buffer = new byte[4096];
|
|
198
|
+
int bytesRead;
|
|
199
|
+
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
200
|
+
outputStream.write(buffer, 0, bytesRead);
|
|
201
|
+
}
|
|
199
202
|
}
|
|
203
|
+
} catch (Exception e) {
|
|
204
|
+
deleteShareCacheFile(outputFile);
|
|
205
|
+
Log.e(TAG, "Error copying file to cache", e);
|
|
206
|
+
return null;
|
|
200
207
|
}
|
|
201
208
|
|
|
202
209
|
return outputFile.getAbsolutePath();
|
|
@@ -206,6 +213,47 @@ public class CapacitorShareTargetPlugin extends Plugin {
|
|
|
206
213
|
}
|
|
207
214
|
}
|
|
208
215
|
|
|
216
|
+
private void deleteShareCacheFile(File file) {
|
|
217
|
+
if (!file.delete()) {
|
|
218
|
+
Log.w(TAG, "Could not delete share cache file after copy failed");
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private void evictStaleSharedFiles(File cacheDir) {
|
|
223
|
+
File[] entries = cacheDir.listFiles();
|
|
224
|
+
if (entries == null || entries.length == 0) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
long now = System.currentTimeMillis();
|
|
229
|
+
ArrayList<File> retained = new ArrayList<>();
|
|
230
|
+
for (File entry : entries) {
|
|
231
|
+
if (!entry.isFile()) {
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (now - entry.lastModified() > SHARED_FILE_MAX_AGE_MS) {
|
|
235
|
+
if (!entry.delete()) {
|
|
236
|
+
Log.w(TAG, "Could not delete stale share cache file");
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
retained.add(entry);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (retained.size() <= SHARED_FILE_MAX_COUNT) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
retained.sort((a, b) -> Long.compare(a.lastModified(), b.lastModified()));
|
|
248
|
+
int toRemove = retained.size() - SHARED_FILE_MAX_COUNT;
|
|
249
|
+
for (int i = 0; i < toRemove; i++) {
|
|
250
|
+
File entry = retained.get(i);
|
|
251
|
+
if (!entry.delete()) {
|
|
252
|
+
Log.w(TAG, "Could not delete excess share cache file");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
209
257
|
@PluginMethod
|
|
210
258
|
public void getPluginVersion(PluginCall call) {
|
|
211
259
|
try {
|
|
@@ -8,7 +8,7 @@ import UIKit
|
|
|
8
8
|
*/
|
|
9
9
|
@objc(CapacitorShareTargetPlugin)
|
|
10
10
|
public class CapacitorShareTargetPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
11
|
-
private let pluginVersion: String = "8.0.
|
|
11
|
+
private let pluginVersion: String = "8.0.58"
|
|
12
12
|
public let identifier = "CapacitorShareTargetPlugin"
|
|
13
13
|
public let jsName = "CapacitorShareTarget"
|
|
14
14
|
public let pluginMethods: [CAPPluginMethod] = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-share-target",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.58",
|
|
4
4
|
"description": "Receive shared content from other apps",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@ionic/eslint-config": "^0.5.0",
|
|
64
64
|
"@ionic/prettier-config": "^4.0.0",
|
|
65
65
|
"@ionic/swiftlint-config": "^2.0.0",
|
|
66
|
-
"@types/node": "^
|
|
66
|
+
"@types/node": "^26.0.0",
|
|
67
67
|
"@typescript-eslint/eslint-plugin": "^8.70.0",
|
|
68
68
|
"@typescript-eslint/parser": "^8.70.0",
|
|
69
69
|
"eslint": "^10.0.0",
|