@kesha-antonov/react-native-background-downloader 4.5.9 → 4.6.0
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 +30 -3
- package/android/build.gradle +17 -0
- package/android/src/main/AndroidManifest.xml +24 -0
- package/android/src/main/java/com/eko/DownloadConstants.kt +14 -2
- package/android/src/main/java/com/eko/Downloader.kt +77 -12
- package/android/src/main/java/com/eko/RNBackgroundDownloaderModuleImpl.kt +81 -11
- package/android/src/main/java/com/eko/ResumableDownloadService.kt +0 -4
- package/android/src/main/java/com/eko/ResumableDownloader.kt +121 -12
- package/android/src/main/java/com/eko/UIDTDownloadJobService.kt +65 -9
- package/android/src/main/java/com/eko/uidt/CancelDownloadReceiver.kt +64 -0
- package/android/src/main/java/com/eko/uidt/RNBGDFileProvider.kt +17 -0
- package/android/src/main/java/com/eko/uidt/UIDTJobIds.kt +112 -0
- package/android/src/main/java/com/eko/uidt/UIDTJobManager.kt +178 -17
- package/android/src/main/java/com/eko/uidt/UIDTJobState.kt +23 -1
- package/android/src/main/java/com/eko/uidt/UIDTNotificationIds.kt +73 -0
- package/android/src/main/java/com/eko/uidt/UIDTNotificationManager.kt +246 -19
- package/android/src/main/res/xml/rnbgd_file_paths.xml +23 -0
- package/android/src/test/java/com/eko/ResumableDownloaderConcurrencyTest.kt +199 -0
- package/android/src/test/java/com/eko/uidt/UIDTJobIdsTest.kt +159 -0
- package/android/src/test/java/com/eko/uidt/UIDTJobManagerTest.kt +192 -0
- package/android/src/test/java/com/eko/uidt/UIDTNotificationIdsTest.kt +99 -0
- package/lib/NativeRNBackgroundDownloader.d.ts +2 -0
- package/lib/config.d.ts +2 -0
- package/lib/config.js +3 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +9 -2
- package/lib/notifications.js +4 -3
- package/lib/types.d.ts +19 -0
- package/package.json +3 -2
- package/src/NativeRNBackgroundDownloader.ts +8 -1
- package/src/config.ts +5 -0
- package/src/index.ts +19 -1
- package/src/notifications.ts +1 -0
- package/src/types.ts +19 -0
package/lib/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { Spec } from './NativeRNBackgroundDownloader';
|
|
|
7
7
|
* This prevents memory leaks from accumulated event listeners.
|
|
8
8
|
*/
|
|
9
9
|
export declare function cleanup(): void;
|
|
10
|
-
export declare function setConfig({ headers, progressInterval, progressMinBytes, isLogsEnabled, logCallback, maxParallelDownloads, allowsCellularAccess, showNotificationsEnabled, notificationsGrouping, iosDataProtection, }: Config): void;
|
|
10
|
+
export declare function setConfig({ headers, progressInterval, progressMinBytes, isLogsEnabled, logCallback, maxParallelDownloads, allowsCellularAccess, showNotificationsEnabled, showCompletionNotification, showCancelAction, notificationsGrouping, iosDataProtection, }: Config): void;
|
|
11
11
|
export declare const getExistingDownloadTasks: () => Promise<DownloadTask[]>;
|
|
12
12
|
export declare const completeHandler: (jobId: string) => Promise<void> | undefined;
|
|
13
13
|
export declare function createDownloadTask({ isAllowedOverRoaming, isAllowedOverMetered, metadata, ...rest }: TaskInfo & DownloadParams): DownloadTask;
|
package/lib/index.js
CHANGED
|
@@ -262,8 +262,8 @@ function initializeEventListeners() {
|
|
|
262
262
|
}
|
|
263
263
|
// Event listeners are now initialized lazily when ensureNativeModuleInitialized() is called
|
|
264
264
|
// This ensures the bridge is ready before any native module access
|
|
265
|
-
function setConfig({ headers = {}, progressInterval = config_1.DEFAULT_PROGRESS_INTERVAL, progressMinBytes = config_1.DEFAULT_PROGRESS_MIN_BYTES, isLogsEnabled = false, logCallback, maxParallelDownloads, allowsCellularAccess, showNotificationsEnabled, notificationsGrouping, iosDataProtection, }) {
|
|
266
|
-
var _a, _b, _c;
|
|
265
|
+
function setConfig({ headers = {}, progressInterval = config_1.DEFAULT_PROGRESS_INTERVAL, progressMinBytes = config_1.DEFAULT_PROGRESS_MIN_BYTES, isLogsEnabled = false, logCallback, maxParallelDownloads, allowsCellularAccess, showNotificationsEnabled, showCompletionNotification, showCancelAction, notificationsGrouping, iosDataProtection, }) {
|
|
266
|
+
var _a, _b, _c, _d, _e;
|
|
267
267
|
config_1.config.headers = headers;
|
|
268
268
|
if (iosDataProtection !== undefined)
|
|
269
269
|
config_1.config.iosDataProtection = iosDataProtection;
|
|
@@ -285,6 +285,11 @@ function setConfig({ headers = {}, progressInterval = config_1.DEFAULT_PROGRESS_
|
|
|
285
285
|
// Update showNotificationsEnabled
|
|
286
286
|
if (showNotificationsEnabled !== undefined)
|
|
287
287
|
config_1.config.showNotificationsEnabled = showNotificationsEnabled;
|
|
288
|
+
// Android 14+ notification extras - both opt-in
|
|
289
|
+
if (showCompletionNotification !== undefined)
|
|
290
|
+
config_1.config.showCompletionNotification = showCompletionNotification;
|
|
291
|
+
if (showCancelAction !== undefined)
|
|
292
|
+
config_1.config.showCancelAction = showCancelAction;
|
|
288
293
|
// Update notification grouping config
|
|
289
294
|
if (notificationsGrouping !== undefined)
|
|
290
295
|
config_1.config.notificationsGrouping = {
|
|
@@ -312,6 +317,8 @@ function setConfig({ headers = {}, progressInterval = config_1.DEFAULT_PROGRESS_
|
|
|
312
317
|
nativeModule.setNotificationGroupingConfig({
|
|
313
318
|
enabled: config_1.config.notificationsGrouping.enabled,
|
|
314
319
|
showNotificationsEnabled: (_c = config_1.config.showNotificationsEnabled) !== null && _c !== void 0 ? _c : false,
|
|
320
|
+
showCompletionNotification: (_d = config_1.config.showCompletionNotification) !== null && _d !== void 0 ? _d : false,
|
|
321
|
+
showCancelAction: (_e = config_1.config.showCancelAction) !== null && _e !== void 0 ? _e : false,
|
|
315
322
|
mode: config_1.config.notificationsGrouping.mode,
|
|
316
323
|
texts: (0, notifications_1.getNotificationTextsForNative)(),
|
|
317
324
|
});
|
package/lib/notifications.js
CHANGED
|
@@ -17,7 +17,7 @@ function getGroupText(count) {
|
|
|
17
17
|
* Get notification texts config for native side (serializable).
|
|
18
18
|
*/
|
|
19
19
|
function getNotificationTextsForNative() {
|
|
20
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
20
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
21
21
|
const texts = (_a = config_1.config.notificationsGrouping.texts) !== null && _a !== void 0 ? _a : config_1.DEFAULT_NOTIFICATION_TEXTS;
|
|
22
22
|
return {
|
|
23
23
|
downloadTitle: (_b = texts.downloadTitle) !== null && _b !== void 0 ? _b : config_1.DEFAULT_NOTIFICATION_TEXTS.downloadTitle,
|
|
@@ -25,10 +25,11 @@ function getNotificationTextsForNative() {
|
|
|
25
25
|
downloadProgress: (_d = texts.downloadProgress) !== null && _d !== void 0 ? _d : config_1.DEFAULT_NOTIFICATION_TEXTS.downloadProgress,
|
|
26
26
|
downloadPaused: (_e = texts.downloadPaused) !== null && _e !== void 0 ? _e : config_1.DEFAULT_NOTIFICATION_TEXTS.downloadPaused,
|
|
27
27
|
downloadFinished: (_f = texts.downloadFinished) !== null && _f !== void 0 ? _f : config_1.DEFAULT_NOTIFICATION_TEXTS.downloadFinished,
|
|
28
|
-
|
|
28
|
+
downloadCancel: (_g = texts.downloadCancel) !== null && _g !== void 0 ? _g : config_1.DEFAULT_NOTIFICATION_TEXTS.downloadCancel,
|
|
29
|
+
groupTitle: (_h = texts.groupTitle) !== null && _h !== void 0 ? _h : config_1.DEFAULT_NOTIFICATION_TEXTS.groupTitle,
|
|
29
30
|
// For native side, we send a pattern with {count} placeholder
|
|
30
31
|
groupText: typeof texts.groupText === 'function'
|
|
31
32
|
? '{count} download(s) in progress' // Default pattern if function provided
|
|
32
|
-
: ((
|
|
33
|
+
: ((_j = texts.groupText) !== null && _j !== void 0 ? _j : '{count} download(s) in progress'),
|
|
33
34
|
};
|
|
34
35
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -18,6 +18,9 @@ export interface NotificationTexts {
|
|
|
18
18
|
downloadPaused?: string;
|
|
19
19
|
/** Text shown when download is finished (default: "Download complete") */
|
|
20
20
|
downloadFinished?: string;
|
|
21
|
+
/** Label of the Cancel action on the progress notification (default: "Cancel").
|
|
22
|
+
* Android 14+ only, and only when `showCancelAction` is enabled */
|
|
23
|
+
downloadCancel?: string;
|
|
21
24
|
/** Title for group summary notification (default: "Downloads") */
|
|
22
25
|
groupTitle?: string;
|
|
23
26
|
/** Text pattern for group summary. Use {count} for number of downloads.
|
|
@@ -63,6 +66,19 @@ export interface Config {
|
|
|
63
66
|
allowsCellularAccess?: boolean;
|
|
64
67
|
/** Show download notifications (Android only, default: false). When false, creates minimal silent notifications (UIDT requires a notification) */
|
|
65
68
|
showNotificationsEnabled?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Post a "download complete" notification when a download finishes
|
|
71
|
+
* (Android 14+ only, default: false). Tapping it opens the saved file.
|
|
72
|
+
* Requires `showNotificationsEnabled`; ignored in `summaryOnly` grouping mode.
|
|
73
|
+
*/
|
|
74
|
+
showCompletionNotification?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Add a Cancel button to the download notification (Android 14+ only, default: false).
|
|
77
|
+
* Tapping it stops the download and fires the task's `.error()` handler with
|
|
78
|
+
* `errorCode = -1`, so only enable it if your app handles that.
|
|
79
|
+
* Requires `showNotificationsEnabled`.
|
|
80
|
+
*/
|
|
81
|
+
showCancelAction?: boolean;
|
|
66
82
|
/** Configuration for notifications grouping on Android */
|
|
67
83
|
notificationsGrouping?: NotificationsGroupingConfig;
|
|
68
84
|
/**
|
|
@@ -119,6 +135,9 @@ export type DownloadParams = {
|
|
|
119
135
|
groupId?: string;
|
|
120
136
|
/** Group name displayed in notification (only used when grouping is enabled) */
|
|
121
137
|
groupName?: string;
|
|
138
|
+
/** Notification title for this download, overriding `groupName` and the
|
|
139
|
+
* configured `downloadTitle` text (Android 14+ only) */
|
|
140
|
+
notificationTitle?: string;
|
|
122
141
|
/**
|
|
123
142
|
* iOS Data Protection level for this download's file (iOS only).
|
|
124
143
|
* Overrides the global `iosDataProtection` from setConfig.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kesha-antonov/react-native-background-downloader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "A library for React-Native to help you download large files on iOS and Android both in the foreground and most importantly in the background.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -59,7 +59,8 @@
|
|
|
59
59
|
"prepublishOnly": "npm run build-plugin && npm run build && npm run typecheck && jest && npm run lint",
|
|
60
60
|
"build-plugin": "tsc plugin/src/index.ts --outDir plugin/build --target ES2018 --module commonjs --declaration --esModuleInterop --strict --skipLibCheck",
|
|
61
61
|
"release": "npm publish",
|
|
62
|
-
"test": "jest"
|
|
62
|
+
"test": "jest",
|
|
63
|
+
"test:android": "cd example/android && ./gradlew :kesha-antonov_react-native-background-downloader:testDebugUnitTest"
|
|
63
64
|
},
|
|
64
65
|
"lint-staged": {
|
|
65
66
|
"*.js": "eslint --cache"
|
|
@@ -92,7 +92,14 @@ export interface Spec extends TurboModule {
|
|
|
92
92
|
setLogsEnabled(enabled: boolean): void
|
|
93
93
|
setMaxParallelDownloads(max: number): void
|
|
94
94
|
setAllowsCellularAccess(allows: boolean): void
|
|
95
|
-
setNotificationGroupingConfig?(config: {
|
|
95
|
+
setNotificationGroupingConfig?(config: {
|
|
96
|
+
enabled: boolean
|
|
97
|
+
showNotificationsEnabled: boolean
|
|
98
|
+
showCompletionNotification: boolean
|
|
99
|
+
showCancelAction: boolean
|
|
100
|
+
mode: string
|
|
101
|
+
texts: UnsafeObject
|
|
102
|
+
}): void
|
|
96
103
|
|
|
97
104
|
getExistingDownloadTasks(): Promise<Array<{
|
|
98
105
|
id: string
|
package/src/config.ts
CHANGED
|
@@ -19,6 +19,7 @@ export const DEFAULT_NOTIFICATION_TEXTS: Required<NotificationTexts> = {
|
|
|
19
19
|
downloadProgress: 'Downloading... {progress}%',
|
|
20
20
|
downloadPaused: 'Paused',
|
|
21
21
|
downloadFinished: 'Download complete',
|
|
22
|
+
downloadCancel: 'Cancel',
|
|
22
23
|
groupTitle: 'Downloads',
|
|
23
24
|
groupText: (count: number) => `${count} download${count !== 1 ? 's' : ''} in progress`,
|
|
24
25
|
}
|
|
@@ -32,6 +33,8 @@ interface ConfigState {
|
|
|
32
33
|
maxParallelDownloads: number
|
|
33
34
|
allowsCellularAccess: boolean
|
|
34
35
|
showNotificationsEnabled: boolean
|
|
36
|
+
showCompletionNotification: boolean
|
|
37
|
+
showCancelAction: boolean
|
|
35
38
|
notificationsGrouping: NotificationsGroupingConfig & { mode: NotificationGroupingMode }
|
|
36
39
|
iosDataProtection: IosDataProtection
|
|
37
40
|
}
|
|
@@ -45,6 +48,8 @@ export const config: ConfigState = {
|
|
|
45
48
|
maxParallelDownloads: DEFAULT_MAX_PARALLEL_DOWNLOADS,
|
|
46
49
|
allowsCellularAccess: DEFAULT_ALLOWS_CELLULAR_ACCESS,
|
|
47
50
|
showNotificationsEnabled: false,
|
|
51
|
+
showCompletionNotification: false,
|
|
52
|
+
showCancelAction: false,
|
|
48
53
|
iosDataProtection: DEFAULT_IOS_DATA_PROTECTION,
|
|
49
54
|
notificationsGrouping: {
|
|
50
55
|
enabled: false,
|
package/src/index.ts
CHANGED
|
@@ -373,6 +373,8 @@ export function setConfig ({
|
|
|
373
373
|
maxParallelDownloads,
|
|
374
374
|
allowsCellularAccess,
|
|
375
375
|
showNotificationsEnabled,
|
|
376
|
+
showCompletionNotification,
|
|
377
|
+
showCancelAction,
|
|
376
378
|
notificationsGrouping,
|
|
377
379
|
iosDataProtection,
|
|
378
380
|
}: Config) {
|
|
@@ -404,6 +406,13 @@ export function setConfig ({
|
|
|
404
406
|
if (showNotificationsEnabled !== undefined)
|
|
405
407
|
config.showNotificationsEnabled = showNotificationsEnabled
|
|
406
408
|
|
|
409
|
+
// Android 14+ notification extras - both opt-in
|
|
410
|
+
if (showCompletionNotification !== undefined)
|
|
411
|
+
config.showCompletionNotification = showCompletionNotification
|
|
412
|
+
|
|
413
|
+
if (showCancelAction !== undefined)
|
|
414
|
+
config.showCancelAction = showCancelAction
|
|
415
|
+
|
|
407
416
|
// Update notification grouping config
|
|
408
417
|
if (notificationsGrouping !== undefined)
|
|
409
418
|
config.notificationsGrouping = {
|
|
@@ -424,7 +433,14 @@ export function setConfig ({
|
|
|
424
433
|
setLogsEnabled?: (enabled: boolean) => void
|
|
425
434
|
setMaxParallelDownloads?: (max: number) => void
|
|
426
435
|
setAllowsCellularAccess?: (allows: boolean) => void
|
|
427
|
-
setNotificationGroupingConfig?: (config: {
|
|
436
|
+
setNotificationGroupingConfig?: (config: {
|
|
437
|
+
enabled: boolean
|
|
438
|
+
showNotificationsEnabled: boolean
|
|
439
|
+
showCompletionNotification: boolean
|
|
440
|
+
showCancelAction: boolean
|
|
441
|
+
mode: string
|
|
442
|
+
texts: Record<string, string>
|
|
443
|
+
}) => void
|
|
428
444
|
}
|
|
429
445
|
if (nativeModule.setLogsEnabled)
|
|
430
446
|
nativeModule.setLogsEnabled(isLogsEnabled)
|
|
@@ -438,6 +454,8 @@ export function setConfig ({
|
|
|
438
454
|
nativeModule.setNotificationGroupingConfig({
|
|
439
455
|
enabled: config.notificationsGrouping.enabled,
|
|
440
456
|
showNotificationsEnabled: config.showNotificationsEnabled ?? false,
|
|
457
|
+
showCompletionNotification: config.showCompletionNotification ?? false,
|
|
458
|
+
showCancelAction: config.showCancelAction ?? false,
|
|
441
459
|
mode: config.notificationsGrouping.mode,
|
|
442
460
|
texts: getNotificationTextsForNative(),
|
|
443
461
|
})
|
package/src/notifications.ts
CHANGED
|
@@ -22,6 +22,7 @@ export function getNotificationTextsForNative (): Record<string, string> {
|
|
|
22
22
|
downloadProgress: texts.downloadProgress ?? DEFAULT_NOTIFICATION_TEXTS.downloadProgress,
|
|
23
23
|
downloadPaused: texts.downloadPaused ?? DEFAULT_NOTIFICATION_TEXTS.downloadPaused,
|
|
24
24
|
downloadFinished: texts.downloadFinished ?? DEFAULT_NOTIFICATION_TEXTS.downloadFinished,
|
|
25
|
+
downloadCancel: texts.downloadCancel ?? DEFAULT_NOTIFICATION_TEXTS.downloadCancel,
|
|
25
26
|
groupTitle: texts.groupTitle ?? DEFAULT_NOTIFICATION_TEXTS.groupTitle,
|
|
26
27
|
// For native side, we send a pattern with {count} placeholder
|
|
27
28
|
groupText: typeof texts.groupText === 'function'
|
package/src/types.ts
CHANGED
|
@@ -21,6 +21,9 @@ export interface NotificationTexts {
|
|
|
21
21
|
downloadPaused?: string
|
|
22
22
|
/** Text shown when download is finished (default: "Download complete") */
|
|
23
23
|
downloadFinished?: string
|
|
24
|
+
/** Label of the Cancel action on the progress notification (default: "Cancel").
|
|
25
|
+
* Android 14+ only, and only when `showCancelAction` is enabled */
|
|
26
|
+
downloadCancel?: string
|
|
24
27
|
/** Title for group summary notification (default: "Downloads") */
|
|
25
28
|
groupTitle?: string
|
|
26
29
|
/** Text pattern for group summary. Use {count} for number of downloads.
|
|
@@ -74,6 +77,19 @@ export interface Config {
|
|
|
74
77
|
allowsCellularAccess?: boolean
|
|
75
78
|
/** Show download notifications (Android only, default: false). When false, creates minimal silent notifications (UIDT requires a notification) */
|
|
76
79
|
showNotificationsEnabled?: boolean
|
|
80
|
+
/**
|
|
81
|
+
* Post a "download complete" notification when a download finishes
|
|
82
|
+
* (Android 14+ only, default: false). Tapping it opens the saved file.
|
|
83
|
+
* Requires `showNotificationsEnabled`; ignored in `summaryOnly` grouping mode.
|
|
84
|
+
*/
|
|
85
|
+
showCompletionNotification?: boolean
|
|
86
|
+
/**
|
|
87
|
+
* Add a Cancel button to the download notification (Android 14+ only, default: false).
|
|
88
|
+
* Tapping it stops the download and fires the task's `.error()` handler with
|
|
89
|
+
* `errorCode = -1`, so only enable it if your app handles that.
|
|
90
|
+
* Requires `showNotificationsEnabled`.
|
|
91
|
+
*/
|
|
92
|
+
showCancelAction?: boolean
|
|
77
93
|
/** Configuration for notifications grouping on Android */
|
|
78
94
|
notificationsGrouping?: NotificationsGroupingConfig
|
|
79
95
|
/**
|
|
@@ -151,6 +167,9 @@ export type DownloadParams = {
|
|
|
151
167
|
groupId?: string
|
|
152
168
|
/** Group name displayed in notification (only used when grouping is enabled) */
|
|
153
169
|
groupName?: string
|
|
170
|
+
/** Notification title for this download, overriding `groupName` and the
|
|
171
|
+
* configured `downloadTitle` text (Android 14+ only) */
|
|
172
|
+
notificationTitle?: string
|
|
154
173
|
/**
|
|
155
174
|
* iOS Data Protection level for this download's file (iOS only).
|
|
156
175
|
* Overrides the global `iosDataProtection` from setConfig.
|