@capgo/capacitor-downloader 7.1.5 → 7.2.1

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
@@ -44,15 +44,20 @@ npx cap sync
44
44
  <docgen-api>
45
45
  <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
46
46
 
47
+ Capacitor plugin for downloading files with background support.
48
+ Provides resumable downloads with progress tracking.
49
+
47
50
  ### download(...)
48
51
 
49
52
  ```typescript
50
53
  download(options: DownloadOptions) => Promise<DownloadTask>
51
54
  ```
52
55
 
53
- | Param | Type |
54
- | ------------- | ----------------------------------------------------------- |
55
- | **`options`** | <code><a href="#downloadoptions">DownloadOptions</a></code> |
56
+ Start a new download task.
57
+
58
+ | Param | Type | Description |
59
+ | ------------- | ----------------------------------------------------------- | ------------------------ |
60
+ | **`options`** | <code><a href="#downloadoptions">DownloadOptions</a></code> | - Download configuration |
56
61
 
57
62
  **Returns:** <code>Promise&lt;<a href="#downloadtask">DownloadTask</a>&gt;</code>
58
63
 
@@ -65,9 +70,12 @@ download(options: DownloadOptions) => Promise<DownloadTask>
65
70
  pause(id: string) => Promise<void>
66
71
  ```
67
72
 
68
- | Param | Type |
69
- | -------- | ------------------- |
70
- | **`id`** | <code>string</code> |
73
+ Pause an active download.
74
+ Download can be resumed later from the same position.
75
+
76
+ | Param | Type | Description |
77
+ | -------- | ------------------- | ---------------------------------- |
78
+ | **`id`** | <code>string</code> | - ID of the download task to pause |
71
79
 
72
80
  --------------------
73
81
 
@@ -78,9 +86,12 @@ pause(id: string) => Promise<void>
78
86
  resume(id: string) => Promise<void>
79
87
  ```
80
88
 
81
- | Param | Type |
82
- | -------- | ------------------- |
83
- | **`id`** | <code>string</code> |
89
+ Resume a paused download.
90
+ Continues from where it was paused.
91
+
92
+ | Param | Type | Description |
93
+ | -------- | ------------------- | ----------------------------------- |
94
+ | **`id`** | <code>string</code> | - ID of the download task to resume |
84
95
 
85
96
  --------------------
86
97
 
@@ -91,9 +102,12 @@ resume(id: string) => Promise<void>
91
102
  stop(id: string) => Promise<void>
92
103
  ```
93
104
 
94
- | Param | Type |
95
- | -------- | ------------------- |
96
- | **`id`** | <code>string</code> |
105
+ Stop and cancel a download permanently.
106
+ Downloaded data will be deleted.
107
+
108
+ | Param | Type | Description |
109
+ | -------- | ------------------- | --------------------------------- |
110
+ | **`id`** | <code>string</code> | - ID of the download task to stop |
97
111
 
98
112
  --------------------
99
113
 
@@ -104,9 +118,11 @@ stop(id: string) => Promise<void>
104
118
  checkStatus(id: string) => Promise<DownloadTask>
105
119
  ```
106
120
 
107
- | Param | Type |
108
- | -------- | ------------------- |
109
- | **`id`** | <code>string</code> |
121
+ Check the current status of a download.
122
+
123
+ | Param | Type | Description |
124
+ | -------- | ------------------- | ---------------------------------- |
125
+ | **`id`** | <code>string</code> | - ID of the download task to check |
110
126
 
111
127
  **Returns:** <code>Promise&lt;<a href="#downloadtask">DownloadTask</a>&gt;</code>
112
128
 
@@ -119,9 +135,11 @@ checkStatus(id: string) => Promise<DownloadTask>
119
135
  getFileInfo(path: string) => Promise<{ size: number; type: string; }>
120
136
  ```
121
137
 
122
- | Param | Type |
123
- | ---------- | ------------------- |
124
- | **`path`** | <code>string</code> |
138
+ Get information about a downloaded file.
139
+
140
+ | Param | Type | Description |
141
+ | ---------- | ------------------- | ---------------------------- |
142
+ | **`path`** | <code>string</code> | - Local file path to inspect |
125
143
 
126
144
  **Returns:** <code>Promise&lt;{ size: number; type: string; }&gt;</code>
127
145
 
@@ -134,10 +152,13 @@ getFileInfo(path: string) => Promise<{ size: number; type: string; }>
134
152
  addListener(eventName: 'downloadProgress', listenerFunc: (progress: { id: string; progress: number; }) => void) => Promise<PluginListenerHandle>
135
153
  ```
136
154
 
137
- | Param | Type |
138
- | ------------------ | --------------------------------------------------------------------- |
139
- | **`eventName`** | <code>'downloadProgress'</code> |
140
- | **`listenerFunc`** | <code>(progress: { id: string; progress: number; }) =&gt; void</code> |
155
+ Listen for download progress updates.
156
+ Fired periodically as download progresses.
157
+
158
+ | Param | Type | Description |
159
+ | ------------------ | --------------------------------------------------------------------- | ------------------------------------- |
160
+ | **`eventName`** | <code>'downloadProgress'</code> | - Must be 'downloadProgress' |
161
+ | **`listenerFunc`** | <code>(progress: { id: string; progress: number; }) =&gt; void</code> | - Callback receiving progress updates |
141
162
 
142
163
  **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
143
164
 
@@ -150,10 +171,13 @@ addListener(eventName: 'downloadProgress', listenerFunc: (progress: { id: string
150
171
  addListener(eventName: 'downloadCompleted', listenerFunc: (result: { id: string; }) => void) => Promise<PluginListenerHandle>
151
172
  ```
152
173
 
153
- | Param | Type |
154
- | ------------------ | ------------------------------------------------- |
155
- | **`eventName`** | <code>'downloadCompleted'</code> |
156
- | **`listenerFunc`** | <code>(result: { id: string; }) =&gt; void</code> |
174
+ Listen for download completion.
175
+ Fired when a download finishes successfully.
176
+
177
+ | Param | Type | Description |
178
+ | ------------------ | ------------------------------------------------- | -------------------------------------------- |
179
+ | **`eventName`** | <code>'downloadCompleted'</code> | - Must be 'downloadCompleted' |
180
+ | **`listenerFunc`** | <code>(result: { id: string; }) =&gt; void</code> | - Callback receiving completion notification |
157
181
 
158
182
  **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
159
183
 
@@ -166,10 +190,13 @@ addListener(eventName: 'downloadCompleted', listenerFunc: (result: { id: string;
166
190
  addListener(eventName: 'downloadFailed', listenerFunc: (error: { id: string; error: string; }) => void) => Promise<PluginListenerHandle>
167
191
  ```
168
192
 
169
- | Param | Type |
170
- | ------------------ | --------------------------------------------------------------- |
171
- | **`eventName`** | <code>'downloadFailed'</code> |
172
- | **`listenerFunc`** | <code>(error: { id: string; error: string; }) =&gt; void</code> |
193
+ Listen for download failures.
194
+ Fired when a download encounters an error.
195
+
196
+ | Param | Type | Description |
197
+ | ------------------ | --------------------------------------------------------------- | -------------------------------------- |
198
+ | **`eventName`** | <code>'downloadFailed'</code> | - Must be 'downloadFailed' |
199
+ | **`listenerFunc`** | <code>(error: { id: string; error: string; }) =&gt; void</code> | - Callback receiving error information |
173
200
 
174
201
  **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
175
202
 
@@ -182,6 +209,9 @@ addListener(eventName: 'downloadFailed', listenerFunc: (error: { id: string; err
182
209
  removeAllListeners() => Promise<void>
183
210
  ```
184
211
 
212
+ Remove all event listeners.
213
+ Cleanup method to prevent memory leaks.
214
+
185
215
  --------------------
186
216
 
187
217
 
@@ -191,7 +221,7 @@ removeAllListeners() => Promise<void>
191
221
  getPluginVersion() => Promise<{ version: string; }>
192
222
  ```
193
223
 
194
- Get the native Capacitor plugin version
224
+ Get the plugin version number.
195
225
 
196
226
  **Returns:** <code>Promise&lt;{ version: string; }&gt;</code>
197
227
 
@@ -203,23 +233,27 @@ Get the native Capacitor plugin version
203
233
 
204
234
  #### DownloadTask
205
235
 
206
- | Prop | Type |
207
- | -------------- | -------------------------------------------------------------------- |
208
- | **`id`** | <code>string</code> |
209
- | **`progress`** | <code>number</code> |
210
- | **`state`** | <code>'PENDING' \| 'RUNNING' \| 'PAUSED' \| 'DONE' \| 'ERROR'</code> |
236
+ Represents the current state and progress of a download task.
237
+
238
+ | Prop | Type | Description |
239
+ | -------------- | -------------------------------------------------------------------- | --------------------------------------- |
240
+ | **`id`** | <code>string</code> | Unique identifier for the download task |
241
+ | **`progress`** | <code>number</code> | Download progress from 0 to 100 |
242
+ | **`state`** | <code>'PENDING' \| 'RUNNING' \| 'PAUSED' \| 'DONE' \| 'ERROR'</code> | Current state of the download |
211
243
 
212
244
 
213
245
  #### DownloadOptions
214
246
 
215
- | Prop | Type |
216
- | ----------------- | ---------------------------------------- |
217
- | **`id`** | <code>string</code> |
218
- | **`url`** | <code>string</code> |
219
- | **`destination`** | <code>string</code> |
220
- | **`headers`** | <code>{ [key: string]: string; }</code> |
221
- | **`network`** | <code>'cellular' \| 'wifi-only'</code> |
222
- | **`priority`** | <code>'high' \| 'normal' \| 'low'</code> |
247
+ Configuration options for starting a download.
248
+
249
+ | Prop | Type | Description |
250
+ | ----------------- | ---------------------------------------- | ------------------------------------------------ |
251
+ | **`id`** | <code>string</code> | Unique identifier for this download task |
252
+ | **`url`** | <code>string</code> | URL of the file to download |
253
+ | **`destination`** | <code>string</code> | Local file path where the download will be saved |
254
+ | **`headers`** | <code>{ [key: string]: string; }</code> | Optional HTTP headers to include in the request |
255
+ | **`network`** | <code>'cellular' \| 'wifi-only'</code> | Network type requirement for download |
256
+ | **`priority`** | <code>'high' \| 'normal' \| 'low'</code> | Download priority level |
223
257
 
224
258
 
225
259
  #### PluginListenerHandle
@@ -22,7 +22,7 @@ import java.util.Map;
22
22
  @CapacitorPlugin(name = "CapacitorDownloader")
23
23
  public class CapacitorDownloaderPlugin extends Plugin {
24
24
 
25
- private final String PLUGIN_VERSION = "7.1.5";
25
+ private final String PLUGIN_VERSION = "7.2.1";
26
26
 
27
27
  private DownloadManager downloadManager;
28
28
  private final Map<String, Long> downloads = new HashMap<>();
package/dist/docs.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "api": {
3
3
  "name": "CapacitorDownloaderPlugin",
4
4
  "slug": "capacitordownloaderplugin",
5
- "docs": "",
5
+ "docs": "Capacitor plugin for downloading files with background support.\nProvides resumable downloads with progress tracking.",
6
6
  "tags": [],
7
7
  "methods": [
8
8
  {
@@ -11,13 +11,26 @@
11
11
  "parameters": [
12
12
  {
13
13
  "name": "options",
14
- "docs": "",
14
+ "docs": "- Download configuration",
15
15
  "type": "DownloadOptions"
16
16
  }
17
17
  ],
18
18
  "returns": "Promise<DownloadTask>",
19
- "tags": [],
20
- "docs": "",
19
+ "tags": [
20
+ {
21
+ "name": "param",
22
+ "text": "options - Download configuration"
23
+ },
24
+ {
25
+ "name": "returns",
26
+ "text": "Promise with initial download task status"
27
+ },
28
+ {
29
+ "name": "example",
30
+ "text": "```typescript\nconst task = await Downloader.download({\n id: 'my-download',\n url: 'https://example.com/file.pdf',\n destination: 'downloads/file.pdf'\n});\n```"
31
+ }
32
+ ],
33
+ "docs": "Start a new download task.",
21
34
  "complexTypes": [
22
35
  "DownloadTask",
23
36
  "DownloadOptions"
@@ -30,13 +43,22 @@
30
43
  "parameters": [
31
44
  {
32
45
  "name": "id",
33
- "docs": "",
46
+ "docs": "- ID of the download task to pause",
34
47
  "type": "string"
35
48
  }
36
49
  ],
37
50
  "returns": "Promise<void>",
38
- "tags": [],
39
- "docs": "",
51
+ "tags": [
52
+ {
53
+ "name": "param",
54
+ "text": "id - ID of the download task to pause"
55
+ },
56
+ {
57
+ "name": "returns",
58
+ "text": "Promise that resolves when paused"
59
+ }
60
+ ],
61
+ "docs": "Pause an active download.\nDownload can be resumed later from the same position.",
40
62
  "complexTypes": [],
41
63
  "slug": "pause"
42
64
  },
@@ -46,13 +68,22 @@
46
68
  "parameters": [
47
69
  {
48
70
  "name": "id",
49
- "docs": "",
71
+ "docs": "- ID of the download task to resume",
50
72
  "type": "string"
51
73
  }
52
74
  ],
53
75
  "returns": "Promise<void>",
54
- "tags": [],
55
- "docs": "",
76
+ "tags": [
77
+ {
78
+ "name": "param",
79
+ "text": "id - ID of the download task to resume"
80
+ },
81
+ {
82
+ "name": "returns",
83
+ "text": "Promise that resolves when resumed"
84
+ }
85
+ ],
86
+ "docs": "Resume a paused download.\nContinues from where it was paused.",
56
87
  "complexTypes": [],
57
88
  "slug": "resume"
58
89
  },
@@ -62,13 +93,22 @@
62
93
  "parameters": [
63
94
  {
64
95
  "name": "id",
65
- "docs": "",
96
+ "docs": "- ID of the download task to stop",
66
97
  "type": "string"
67
98
  }
68
99
  ],
69
100
  "returns": "Promise<void>",
70
- "tags": [],
71
- "docs": "",
101
+ "tags": [
102
+ {
103
+ "name": "param",
104
+ "text": "id - ID of the download task to stop"
105
+ },
106
+ {
107
+ "name": "returns",
108
+ "text": "Promise that resolves when stopped"
109
+ }
110
+ ],
111
+ "docs": "Stop and cancel a download permanently.\nDownloaded data will be deleted.",
72
112
  "complexTypes": [],
73
113
  "slug": "stop"
74
114
  },
@@ -78,13 +118,22 @@
78
118
  "parameters": [
79
119
  {
80
120
  "name": "id",
81
- "docs": "",
121
+ "docs": "- ID of the download task to check",
82
122
  "type": "string"
83
123
  }
84
124
  ],
85
125
  "returns": "Promise<DownloadTask>",
86
- "tags": [],
87
- "docs": "",
126
+ "tags": [
127
+ {
128
+ "name": "param",
129
+ "text": "id - ID of the download task to check"
130
+ },
131
+ {
132
+ "name": "returns",
133
+ "text": "Promise with current download task status"
134
+ }
135
+ ],
136
+ "docs": "Check the current status of a download.",
88
137
  "complexTypes": [
89
138
  "DownloadTask"
90
139
  ],
@@ -96,13 +145,22 @@
96
145
  "parameters": [
97
146
  {
98
147
  "name": "path",
99
- "docs": "",
148
+ "docs": "- Local file path to inspect",
100
149
  "type": "string"
101
150
  }
102
151
  ],
103
152
  "returns": "Promise<{ size: number; type: string; }>",
104
- "tags": [],
105
- "docs": "",
153
+ "tags": [
154
+ {
155
+ "name": "param",
156
+ "text": "path - Local file path to inspect"
157
+ },
158
+ {
159
+ "name": "returns",
160
+ "text": "Promise with file size and MIME type"
161
+ }
162
+ ],
163
+ "docs": "Get information about a downloaded file.",
106
164
  "complexTypes": [],
107
165
  "slug": "getfileinfo"
108
166
  },
@@ -112,18 +170,35 @@
112
170
  "parameters": [
113
171
  {
114
172
  "name": "eventName",
115
- "docs": "",
173
+ "docs": "- Must be 'downloadProgress'",
116
174
  "type": "'downloadProgress'"
117
175
  },
118
176
  {
119
177
  "name": "listenerFunc",
120
- "docs": "",
178
+ "docs": "- Callback receiving progress updates",
121
179
  "type": "(progress: { id: string; progress: number; }) => void"
122
180
  }
123
181
  ],
124
182
  "returns": "Promise<PluginListenerHandle>",
125
- "tags": [],
126
- "docs": "",
183
+ "tags": [
184
+ {
185
+ "name": "param",
186
+ "text": "eventName - Must be 'downloadProgress'"
187
+ },
188
+ {
189
+ "name": "param",
190
+ "text": "listenerFunc - Callback receiving progress updates"
191
+ },
192
+ {
193
+ "name": "returns",
194
+ "text": "Promise with listener handle for removal"
195
+ },
196
+ {
197
+ "name": "example",
198
+ "text": "```typescript\nconst listener = await Downloader.addListener('downloadProgress', (data) => {\n console.log(`Download ${data.id}: ${data.progress}%`);\n});\n```"
199
+ }
200
+ ],
201
+ "docs": "Listen for download progress updates.\nFired periodically as download progresses.",
127
202
  "complexTypes": [
128
203
  "PluginListenerHandle"
129
204
  ],
@@ -135,18 +210,31 @@
135
210
  "parameters": [
136
211
  {
137
212
  "name": "eventName",
138
- "docs": "",
213
+ "docs": "- Must be 'downloadCompleted'",
139
214
  "type": "'downloadCompleted'"
140
215
  },
141
216
  {
142
217
  "name": "listenerFunc",
143
- "docs": "",
218
+ "docs": "- Callback receiving completion notification",
144
219
  "type": "(result: { id: string; }) => void"
145
220
  }
146
221
  ],
147
222
  "returns": "Promise<PluginListenerHandle>",
148
- "tags": [],
149
- "docs": "",
223
+ "tags": [
224
+ {
225
+ "name": "param",
226
+ "text": "eventName - Must be 'downloadCompleted'"
227
+ },
228
+ {
229
+ "name": "param",
230
+ "text": "listenerFunc - Callback receiving completion notification"
231
+ },
232
+ {
233
+ "name": "returns",
234
+ "text": "Promise with listener handle for removal"
235
+ }
236
+ ],
237
+ "docs": "Listen for download completion.\nFired when a download finishes successfully.",
150
238
  "complexTypes": [
151
239
  "PluginListenerHandle"
152
240
  ],
@@ -158,18 +246,31 @@
158
246
  "parameters": [
159
247
  {
160
248
  "name": "eventName",
161
- "docs": "",
249
+ "docs": "- Must be 'downloadFailed'",
162
250
  "type": "'downloadFailed'"
163
251
  },
164
252
  {
165
253
  "name": "listenerFunc",
166
- "docs": "",
254
+ "docs": "- Callback receiving error information",
167
255
  "type": "(error: { id: string; error: string; }) => void"
168
256
  }
169
257
  ],
170
258
  "returns": "Promise<PluginListenerHandle>",
171
- "tags": [],
172
- "docs": "",
259
+ "tags": [
260
+ {
261
+ "name": "param",
262
+ "text": "eventName - Must be 'downloadFailed'"
263
+ },
264
+ {
265
+ "name": "param",
266
+ "text": "listenerFunc - Callback receiving error information"
267
+ },
268
+ {
269
+ "name": "returns",
270
+ "text": "Promise with listener handle for removal"
271
+ }
272
+ ],
273
+ "docs": "Listen for download failures.\nFired when a download encounters an error.",
173
274
  "complexTypes": [
174
275
  "PluginListenerHandle"
175
276
  ],
@@ -180,8 +281,13 @@
180
281
  "signature": "() => Promise<void>",
181
282
  "parameters": [],
182
283
  "returns": "Promise<void>",
183
- "tags": [],
184
- "docs": "",
284
+ "tags": [
285
+ {
286
+ "name": "returns",
287
+ "text": "Promise that resolves when all listeners removed"
288
+ }
289
+ ],
290
+ "docs": "Remove all event listeners.\nCleanup method to prevent memory leaks.",
185
291
  "complexTypes": [],
186
292
  "slug": "removealllisteners"
187
293
  },
@@ -193,14 +299,10 @@
193
299
  "tags": [
194
300
  {
195
301
  "name": "returns",
196
- "text": "an Promise with version for this device"
197
- },
198
- {
199
- "name": "throws",
200
- "text": "An error if the something went wrong"
302
+ "text": "Promise with version string"
201
303
  }
202
304
  ],
203
- "docs": "Get the native Capacitor plugin version",
305
+ "docs": "Get the plugin version number.",
204
306
  "complexTypes": [],
205
307
  "slug": "getpluginversion"
206
308
  }
@@ -211,28 +313,28 @@
211
313
  {
212
314
  "name": "DownloadTask",
213
315
  "slug": "downloadtask",
214
- "docs": "",
316
+ "docs": "Represents the current state and progress of a download task.",
215
317
  "tags": [],
216
318
  "methods": [],
217
319
  "properties": [
218
320
  {
219
321
  "name": "id",
220
322
  "tags": [],
221
- "docs": "",
323
+ "docs": "Unique identifier for the download task",
222
324
  "complexTypes": [],
223
325
  "type": "string"
224
326
  },
225
327
  {
226
328
  "name": "progress",
227
329
  "tags": [],
228
- "docs": "",
330
+ "docs": "Download progress from 0 to 100",
229
331
  "complexTypes": [],
230
332
  "type": "number"
231
333
  },
232
334
  {
233
335
  "name": "state",
234
336
  "tags": [],
235
- "docs": "",
337
+ "docs": "Current state of the download",
236
338
  "complexTypes": [],
237
339
  "type": "'PENDING' | 'RUNNING' | 'PAUSED' | 'DONE' | 'ERROR'"
238
340
  }
@@ -241,49 +343,49 @@
241
343
  {
242
344
  "name": "DownloadOptions",
243
345
  "slug": "downloadoptions",
244
- "docs": "",
346
+ "docs": "Configuration options for starting a download.",
245
347
  "tags": [],
246
348
  "methods": [],
247
349
  "properties": [
248
350
  {
249
351
  "name": "id",
250
352
  "tags": [],
251
- "docs": "",
353
+ "docs": "Unique identifier for this download task",
252
354
  "complexTypes": [],
253
355
  "type": "string"
254
356
  },
255
357
  {
256
358
  "name": "url",
257
359
  "tags": [],
258
- "docs": "",
360
+ "docs": "URL of the file to download",
259
361
  "complexTypes": [],
260
362
  "type": "string"
261
363
  },
262
364
  {
263
365
  "name": "destination",
264
366
  "tags": [],
265
- "docs": "",
367
+ "docs": "Local file path where the download will be saved",
266
368
  "complexTypes": [],
267
369
  "type": "string"
268
370
  },
269
371
  {
270
372
  "name": "headers",
271
373
  "tags": [],
272
- "docs": "",
374
+ "docs": "Optional HTTP headers to include in the request",
273
375
  "complexTypes": [],
274
376
  "type": "{ [key: string]: string; } | undefined"
275
377
  },
276
378
  {
277
379
  "name": "network",
278
380
  "tags": [],
279
- "docs": "",
381
+ "docs": "Network type requirement for download",
280
382
  "complexTypes": [],
281
383
  "type": "'cellular' | 'wifi-only' | undefined"
282
384
  },
283
385
  {
284
386
  "name": "priority",
285
387
  "tags": [],
286
- "docs": "",
388
+ "docs": "Download priority level",
287
389
  "complexTypes": [],
288
390
  "type": "'high' | 'normal' | 'low' | undefined"
289
391
  }
@@ -1,46 +1,147 @@
1
1
  import type { PluginListenerHandle } from '@capacitor/core';
2
+ /**
3
+ * Represents the current state and progress of a download task.
4
+ */
2
5
  export interface DownloadTask {
6
+ /** Unique identifier for the download task */
3
7
  id: string;
8
+ /** Download progress from 0 to 100 */
4
9
  progress: number;
10
+ /** Current state of the download */
5
11
  state: 'PENDING' | 'RUNNING' | 'PAUSED' | 'DONE' | 'ERROR';
6
12
  }
13
+ /**
14
+ * Configuration options for starting a download.
15
+ */
7
16
  export interface DownloadOptions {
17
+ /** Unique identifier for this download task */
8
18
  id: string;
19
+ /** URL of the file to download */
9
20
  url: string;
21
+ /** Local file path where the download will be saved */
10
22
  destination: string;
23
+ /** Optional HTTP headers to include in the request */
11
24
  headers?: {
12
25
  [key: string]: string;
13
26
  };
27
+ /** Network type requirement for download */
14
28
  network?: 'cellular' | 'wifi-only';
29
+ /** Download priority level */
15
30
  priority?: 'high' | 'normal' | 'low';
16
31
  }
32
+ /**
33
+ * Capacitor plugin for downloading files with background support.
34
+ * Provides resumable downloads with progress tracking.
35
+ */
17
36
  export interface CapacitorDownloaderPlugin {
37
+ /**
38
+ * Start a new download task.
39
+ *
40
+ * @param options - Download configuration
41
+ * @returns Promise with initial download task status
42
+ * @example
43
+ * ```typescript
44
+ * const task = await Downloader.download({
45
+ * id: 'my-download',
46
+ * url: 'https://example.com/file.pdf',
47
+ * destination: 'downloads/file.pdf'
48
+ * });
49
+ * ```
50
+ */
18
51
  download(options: DownloadOptions): Promise<DownloadTask>;
52
+ /**
53
+ * Pause an active download.
54
+ * Download can be resumed later from the same position.
55
+ *
56
+ * @param id - ID of the download task to pause
57
+ * @returns Promise that resolves when paused
58
+ */
19
59
  pause(id: string): Promise<void>;
60
+ /**
61
+ * Resume a paused download.
62
+ * Continues from where it was paused.
63
+ *
64
+ * @param id - ID of the download task to resume
65
+ * @returns Promise that resolves when resumed
66
+ */
20
67
  resume(id: string): Promise<void>;
68
+ /**
69
+ * Stop and cancel a download permanently.
70
+ * Downloaded data will be deleted.
71
+ *
72
+ * @param id - ID of the download task to stop
73
+ * @returns Promise that resolves when stopped
74
+ */
21
75
  stop(id: string): Promise<void>;
76
+ /**
77
+ * Check the current status of a download.
78
+ *
79
+ * @param id - ID of the download task to check
80
+ * @returns Promise with current download task status
81
+ */
22
82
  checkStatus(id: string): Promise<DownloadTask>;
83
+ /**
84
+ * Get information about a downloaded file.
85
+ *
86
+ * @param path - Local file path to inspect
87
+ * @returns Promise with file size and MIME type
88
+ */
23
89
  getFileInfo(path: string): Promise<{
24
90
  size: number;
25
91
  type: string;
26
92
  }>;
93
+ /**
94
+ * Listen for download progress updates.
95
+ * Fired periodically as download progresses.
96
+ *
97
+ * @param eventName - Must be 'downloadProgress'
98
+ * @param listenerFunc - Callback receiving progress updates
99
+ * @returns Promise with listener handle for removal
100
+ * @example
101
+ * ```typescript
102
+ * const listener = await Downloader.addListener('downloadProgress', (data) => {
103
+ * console.log(`Download ${data.id}: ${data.progress}%`);
104
+ * });
105
+ * ```
106
+ */
27
107
  addListener(eventName: 'downloadProgress', listenerFunc: (progress: {
28
108
  id: string;
29
109
  progress: number;
30
110
  }) => void): Promise<PluginListenerHandle>;
111
+ /**
112
+ * Listen for download completion.
113
+ * Fired when a download finishes successfully.
114
+ *
115
+ * @param eventName - Must be 'downloadCompleted'
116
+ * @param listenerFunc - Callback receiving completion notification
117
+ * @returns Promise with listener handle for removal
118
+ */
31
119
  addListener(eventName: 'downloadCompleted', listenerFunc: (result: {
32
120
  id: string;
33
121
  }) => void): Promise<PluginListenerHandle>;
122
+ /**
123
+ * Listen for download failures.
124
+ * Fired when a download encounters an error.
125
+ *
126
+ * @param eventName - Must be 'downloadFailed'
127
+ * @param listenerFunc - Callback receiving error information
128
+ * @returns Promise with listener handle for removal
129
+ */
34
130
  addListener(eventName: 'downloadFailed', listenerFunc: (error: {
35
131
  id: string;
36
132
  error: string;
37
133
  }) => void): Promise<PluginListenerHandle>;
134
+ /**
135
+ * Remove all event listeners.
136
+ * Cleanup method to prevent memory leaks.
137
+ *
138
+ * @returns Promise that resolves when all listeners removed
139
+ */
38
140
  removeAllListeners(): Promise<void>;
39
141
  /**
40
- * Get the native Capacitor plugin version
142
+ * Get the plugin version number.
41
143
  *
42
- * @returns {Promise<{ id: string }>} an Promise with version for this device
43
- * @throws An error if the something went wrong
144
+ * @returns Promise with version string
44
145
  */
45
146
  getPluginVersion(): Promise<{
46
147
  version: string;
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface DownloadTask {\n id: string;\n progress: number;\n state: 'PENDING' | 'RUNNING' | 'PAUSED' | 'DONE' | 'ERROR';\n}\n\nexport interface DownloadOptions {\n id: string;\n url: string;\n destination: string;\n headers?: { [key: string]: string };\n network?: 'cellular' | 'wifi-only';\n priority?: 'high' | 'normal' | 'low';\n}\n\nexport interface CapacitorDownloaderPlugin {\n download(options: DownloadOptions): Promise<DownloadTask>;\n pause(id: string): Promise<void>;\n resume(id: string): Promise<void>;\n stop(id: string): Promise<void>;\n checkStatus(id: string): Promise<DownloadTask>;\n getFileInfo(path: string): Promise<{ size: number; type: string }>;\n\n addListener(\n eventName: 'downloadProgress',\n listenerFunc: (progress: { id: string; progress: number }) => void,\n ): Promise<PluginListenerHandle>;\n addListener(\n eventName: 'downloadCompleted',\n listenerFunc: (result: { id: string }) => void,\n ): Promise<PluginListenerHandle>;\n addListener(\n eventName: 'downloadFailed',\n listenerFunc: (error: { id: string; error: string }) => void,\n ): Promise<PluginListenerHandle>;\n removeAllListeners(): Promise<void>;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ id: string }>} an Promise with version for this device\n * @throws An error if the something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/**\n * Represents the current state and progress of a download task.\n */\nexport interface DownloadTask {\n /** Unique identifier for the download task */\n id: string;\n /** Download progress from 0 to 100 */\n progress: number;\n /** Current state of the download */\n state: 'PENDING' | 'RUNNING' | 'PAUSED' | 'DONE' | 'ERROR';\n}\n\n/**\n * Configuration options for starting a download.\n */\nexport interface DownloadOptions {\n /** Unique identifier for this download task */\n id: string;\n /** URL of the file to download */\n url: string;\n /** Local file path where the download will be saved */\n destination: string;\n /** Optional HTTP headers to include in the request */\n headers?: { [key: string]: string };\n /** Network type requirement for download */\n network?: 'cellular' | 'wifi-only';\n /** Download priority level */\n priority?: 'high' | 'normal' | 'low';\n}\n\n/**\n * Capacitor plugin for downloading files with background support.\n * Provides resumable downloads with progress tracking.\n */\nexport interface CapacitorDownloaderPlugin {\n /**\n * Start a new download task.\n *\n * @param options - Download configuration\n * @returns Promise with initial download task status\n * @example\n * ```typescript\n * const task = await Downloader.download({\n * id: 'my-download',\n * url: 'https://example.com/file.pdf',\n * destination: 'downloads/file.pdf'\n * });\n * ```\n */\n download(options: DownloadOptions): Promise<DownloadTask>;\n\n /**\n * Pause an active download.\n * Download can be resumed later from the same position.\n *\n * @param id - ID of the download task to pause\n * @returns Promise that resolves when paused\n */\n pause(id: string): Promise<void>;\n\n /**\n * Resume a paused download.\n * Continues from where it was paused.\n *\n * @param id - ID of the download task to resume\n * @returns Promise that resolves when resumed\n */\n resume(id: string): Promise<void>;\n\n /**\n * Stop and cancel a download permanently.\n * Downloaded data will be deleted.\n *\n * @param id - ID of the download task to stop\n * @returns Promise that resolves when stopped\n */\n stop(id: string): Promise<void>;\n\n /**\n * Check the current status of a download.\n *\n * @param id - ID of the download task to check\n * @returns Promise with current download task status\n */\n checkStatus(id: string): Promise<DownloadTask>;\n\n /**\n * Get information about a downloaded file.\n *\n * @param path - Local file path to inspect\n * @returns Promise with file size and MIME type\n */\n getFileInfo(path: string): Promise<{ size: number; type: string }>;\n\n /**\n * Listen for download progress updates.\n * Fired periodically as download progresses.\n *\n * @param eventName - Must be 'downloadProgress'\n * @param listenerFunc - Callback receiving progress updates\n * @returns Promise with listener handle for removal\n * @example\n * ```typescript\n * const listener = await Downloader.addListener('downloadProgress', (data) => {\n * console.log(`Download ${data.id}: ${data.progress}%`);\n * });\n * ```\n */\n addListener(\n eventName: 'downloadProgress',\n listenerFunc: (progress: { id: string; progress: number }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Listen for download completion.\n * Fired when a download finishes successfully.\n *\n * @param eventName - Must be 'downloadCompleted'\n * @param listenerFunc - Callback receiving completion notification\n * @returns Promise with listener handle for removal\n */\n addListener(\n eventName: 'downloadCompleted',\n listenerFunc: (result: { id: string }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Listen for download failures.\n * Fired when a download encounters an error.\n *\n * @param eventName - Must be 'downloadFailed'\n * @param listenerFunc - Callback receiving error information\n * @returns Promise with listener handle for removal\n */\n addListener(\n eventName: 'downloadFailed',\n listenerFunc: (error: { id: string; error: string }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Remove all event listeners.\n * Cleanup method to prevent memory leaks.\n *\n * @returns Promise that resolves when all listeners removed\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Get the plugin version number.\n *\n * @returns Promise with version string\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n"]}
@@ -8,7 +8,7 @@ import Capacitor
8
8
 
9
9
  @objc(CapacitorDownloaderPlugin)
10
10
  public class CapacitorDownloaderPlugin: CAPPlugin, CAPBridgedPlugin {
11
- private let PLUGIN_VERSION: String = "7.1.5"
11
+ private let PLUGIN_VERSION: String = "7.2.1"
12
12
  public let identifier = "CapacitorDownloaderPlugin"
13
13
  public let jsName = "CapacitorDownloader"
14
14
  public let pluginMethods: [CAPPluginMethod] = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-downloader",
3
- "version": "7.1.5",
3
+ "version": "7.2.1",
4
4
  "description": "Download file in background or foreground",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -40,7 +40,7 @@
40
40
  "verify:android": "cd android && ./gradlew clean build test && cd ..",
41
41
  "verify:web": "npm run build",
42
42
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
43
- "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --autocorrect --format",
43
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
44
44
  "eslint": "eslint . --ext .ts",
45
45
  "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
46
46
  "swiftlint": "node-swiftlint",