@kesha-antonov/react-native-background-downloader 4.5.6 → 4.5.9
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 +5 -1
- package/android/src/main/java/com/eko/DownloadConstants.kt +7 -0
- package/android/src/main/java/com/eko/Downloader.kt +80 -111
- package/android/src/main/java/com/eko/PromiseExtensions.kt +36 -0
- package/android/src/main/java/com/eko/RNBGDTaskConfig.kt +4 -1
- package/android/src/main/java/com/eko/RNBackgroundDownloaderModuleImpl.kt +102 -144
- package/android/src/main/java/com/eko/ResumableDownloadService.kt +153 -37
- package/android/src/main/java/com/eko/ResumableDownloader.kt +66 -12
- package/android/src/main/java/com/eko/UIDTDownloadJobService.kt +25 -4
- package/android/src/main/java/com/eko/UnmeteredNetworkGate.kt +366 -0
- package/android/src/main/java/com/eko/uidt/UIDTJobManager.kt +76 -14
- package/android/src/main/java/com/eko/uidt/UIDTJobState.kt +11 -0
- package/android/src/main/java/com/eko/utils/NetworkRequestUtils.kt +43 -0
- package/android/src/main/java/com/eko/utils/ReadableConverters.kt +55 -0
- package/android/src/main/java/com/eko/utils/RedirectResolver.kt +97 -0
- package/android/src/main/java/com/eko/utils/StorageManager.kt +45 -45
- package/android/src/newarch/java/com/eko/RNBackgroundDownloaderModule.kt +18 -70
- package/android/src/oldarch/java/com/eko/RNBackgroundDownloaderModule.kt +18 -70
- package/ios/RNBackgroundDownloader.mm +187 -91
- package/lib/DownloadTask.js +8 -7
- package/lib/UploadTask.js +11 -10
- package/lib/config.d.ts +1 -10
- package/lib/config.js +1 -44
- package/lib/index.js +34 -32
- package/lib/logger.d.ts +2 -0
- package/lib/logger.js +16 -0
- package/lib/notifications.d.ts +8 -0
- package/lib/notifications.js +34 -0
- package/package.json +7 -3
- package/src/DownloadTask.ts +2 -1
- package/src/UploadTask.ts +2 -1
- package/src/config.ts +4 -45
- package/src/index.ts +3 -1
- package/src/logger.ts +16 -0
- package/src/notifications.ts +31 -0
package/lib/index.js
CHANGED
|
@@ -10,6 +10,8 @@ const react_native_1 = require("react-native");
|
|
|
10
10
|
const DownloadTask_1 = require("./DownloadTask");
|
|
11
11
|
const UploadTask_1 = require("./UploadTask");
|
|
12
12
|
const config_1 = require("./config");
|
|
13
|
+
const logger_1 = require("./logger");
|
|
14
|
+
const notifications_1 = require("./notifications");
|
|
13
15
|
// Lazy initialization state
|
|
14
16
|
let RNBackgroundDownloader = null;
|
|
15
17
|
let turboModule = null;
|
|
@@ -87,16 +89,16 @@ function initializeEventListeners() {
|
|
|
87
89
|
// iOS new architecture: use EventEmitter from TurboModule spec
|
|
88
90
|
turboModule.onDownloadBegin((data) => {
|
|
89
91
|
const { id, ...rest } = data;
|
|
90
|
-
(0,
|
|
92
|
+
(0, logger_1.log)('downloadBegin', id, rest);
|
|
91
93
|
const task = tasksMap.get(id);
|
|
92
94
|
if (!task) {
|
|
93
|
-
(0,
|
|
95
|
+
(0, logger_1.log)('downloadBegin: task not found in tasksMap', id);
|
|
94
96
|
return;
|
|
95
97
|
}
|
|
96
98
|
task.onBegin(rest);
|
|
97
99
|
});
|
|
98
100
|
turboModule.onDownloadProgress((events) => {
|
|
99
|
-
(0,
|
|
101
|
+
(0, logger_1.log)('downloadProgress', events);
|
|
100
102
|
for (const event of events) {
|
|
101
103
|
const { id, ...rest } = event;
|
|
102
104
|
const task = tasksMap.get(id);
|
|
@@ -106,20 +108,20 @@ function initializeEventListeners() {
|
|
|
106
108
|
});
|
|
107
109
|
turboModule.onDownloadComplete((data) => {
|
|
108
110
|
const { id, ...rest } = data;
|
|
109
|
-
(0,
|
|
111
|
+
(0, logger_1.log)('downloadComplete', id, rest);
|
|
110
112
|
const task = tasksMap.get(id);
|
|
111
113
|
if (!task)
|
|
112
|
-
(0,
|
|
114
|
+
(0, logger_1.log)('downloadComplete: task not found in tasksMap', id);
|
|
113
115
|
else
|
|
114
116
|
task.onDone(rest);
|
|
115
117
|
tasksMap.delete(id);
|
|
116
118
|
});
|
|
117
119
|
turboModule.onDownloadFailed((data) => {
|
|
118
120
|
const { id, ...rest } = data;
|
|
119
|
-
(0,
|
|
121
|
+
(0, logger_1.log)('downloadFailed', id, rest);
|
|
120
122
|
const task = tasksMap.get(id);
|
|
121
123
|
if (!task)
|
|
122
|
-
(0,
|
|
124
|
+
(0, logger_1.log)('downloadFailed: task not found in tasksMap', id);
|
|
123
125
|
else
|
|
124
126
|
task.onError(rest);
|
|
125
127
|
tasksMap.delete(id);
|
|
@@ -128,16 +130,16 @@ function initializeEventListeners() {
|
|
|
128
130
|
if (typeof turboModule.onUploadBegin === 'function') {
|
|
129
131
|
(_a = turboModule.onUploadBegin) === null || _a === void 0 ? void 0 : _a.call(turboModule, (data) => {
|
|
130
132
|
const { id, ...rest } = data;
|
|
131
|
-
(0,
|
|
133
|
+
(0, logger_1.log)('uploadBegin', id, rest);
|
|
132
134
|
const task = uploadTasksMap.get(id);
|
|
133
135
|
if (!task) {
|
|
134
|
-
(0,
|
|
136
|
+
(0, logger_1.log)('uploadBegin: task not found in uploadTasksMap', id);
|
|
135
137
|
return;
|
|
136
138
|
}
|
|
137
139
|
task.onBegin(rest);
|
|
138
140
|
});
|
|
139
141
|
(_b = turboModule.onUploadProgress) === null || _b === void 0 ? void 0 : _b.call(turboModule, (events) => {
|
|
140
|
-
(0,
|
|
142
|
+
(0, logger_1.log)('uploadProgress', events);
|
|
141
143
|
for (const event of events) {
|
|
142
144
|
const { id, ...rest } = event;
|
|
143
145
|
const task = uploadTasksMap.get(id);
|
|
@@ -147,20 +149,20 @@ function initializeEventListeners() {
|
|
|
147
149
|
});
|
|
148
150
|
(_c = turboModule.onUploadComplete) === null || _c === void 0 ? void 0 : _c.call(turboModule, (data) => {
|
|
149
151
|
const { id, ...rest } = data;
|
|
150
|
-
(0,
|
|
152
|
+
(0, logger_1.log)('uploadComplete', id, rest);
|
|
151
153
|
const task = uploadTasksMap.get(id);
|
|
152
154
|
if (!task)
|
|
153
|
-
(0,
|
|
155
|
+
(0, logger_1.log)('uploadComplete: task not found in uploadTasksMap', id);
|
|
154
156
|
else
|
|
155
157
|
task.onDone(rest);
|
|
156
158
|
uploadTasksMap.delete(id);
|
|
157
159
|
});
|
|
158
160
|
(_d = turboModule.onUploadFailed) === null || _d === void 0 ? void 0 : _d.call(turboModule, (data) => {
|
|
159
161
|
const { id, ...rest } = data;
|
|
160
|
-
(0,
|
|
162
|
+
(0, logger_1.log)('uploadFailed', id, rest);
|
|
161
163
|
const task = uploadTasksMap.get(id);
|
|
162
164
|
if (!task)
|
|
163
|
-
(0,
|
|
165
|
+
(0, logger_1.log)('uploadFailed: task not found in uploadTasksMap', id);
|
|
164
166
|
else
|
|
165
167
|
task.onError(rest);
|
|
166
168
|
uploadTasksMap.delete(id);
|
|
@@ -175,16 +177,16 @@ function initializeEventListeners() {
|
|
|
175
177
|
const eventEmitter = new react_native_1.NativeEventEmitter(RNBackgroundDownloader);
|
|
176
178
|
eventSubscriptions.push(eventEmitter.addListener('downloadBegin', (data) => {
|
|
177
179
|
const { id, ...rest } = data;
|
|
178
|
-
(0,
|
|
180
|
+
(0, logger_1.log)('downloadBegin', id, rest);
|
|
179
181
|
const task = tasksMap.get(id);
|
|
180
182
|
if (!task) {
|
|
181
|
-
(0,
|
|
183
|
+
(0, logger_1.log)('downloadBegin: task not found in tasksMap', id);
|
|
182
184
|
return;
|
|
183
185
|
}
|
|
184
186
|
task.onBegin(rest);
|
|
185
187
|
}));
|
|
186
188
|
eventSubscriptions.push(eventEmitter.addListener('downloadProgress', (events) => {
|
|
187
|
-
(0,
|
|
189
|
+
(0, logger_1.log)('downloadProgress', events);
|
|
188
190
|
for (const event of events) {
|
|
189
191
|
const { id, ...rest } = event;
|
|
190
192
|
const task = tasksMap.get(id);
|
|
@@ -194,20 +196,20 @@ function initializeEventListeners() {
|
|
|
194
196
|
}));
|
|
195
197
|
eventSubscriptions.push(eventEmitter.addListener('downloadComplete', (data) => {
|
|
196
198
|
const { id, ...rest } = data;
|
|
197
|
-
(0,
|
|
199
|
+
(0, logger_1.log)('downloadComplete', id, rest);
|
|
198
200
|
const task = tasksMap.get(id);
|
|
199
201
|
if (!task)
|
|
200
|
-
(0,
|
|
202
|
+
(0, logger_1.log)('downloadComplete: task not found in tasksMap', id);
|
|
201
203
|
else
|
|
202
204
|
task.onDone(rest);
|
|
203
205
|
tasksMap.delete(id);
|
|
204
206
|
}));
|
|
205
207
|
eventSubscriptions.push(eventEmitter.addListener('downloadFailed', (data) => {
|
|
206
208
|
const { id, ...rest } = data;
|
|
207
|
-
(0,
|
|
209
|
+
(0, logger_1.log)('downloadFailed', id, rest);
|
|
208
210
|
const task = tasksMap.get(id);
|
|
209
211
|
if (!task)
|
|
210
|
-
(0,
|
|
212
|
+
(0, logger_1.log)('downloadFailed: task not found in tasksMap', id);
|
|
211
213
|
else
|
|
212
214
|
task.onError(rest);
|
|
213
215
|
tasksMap.delete(id);
|
|
@@ -215,16 +217,16 @@ function initializeEventListeners() {
|
|
|
215
217
|
// Upload events for old architecture
|
|
216
218
|
eventSubscriptions.push(eventEmitter.addListener('uploadBegin', (data) => {
|
|
217
219
|
const { id, ...rest } = data;
|
|
218
|
-
(0,
|
|
220
|
+
(0, logger_1.log)('uploadBegin', id, rest);
|
|
219
221
|
const task = uploadTasksMap.get(id);
|
|
220
222
|
if (!task) {
|
|
221
|
-
(0,
|
|
223
|
+
(0, logger_1.log)('uploadBegin: task not found in uploadTasksMap', id);
|
|
222
224
|
return;
|
|
223
225
|
}
|
|
224
226
|
task.onBegin(rest);
|
|
225
227
|
}));
|
|
226
228
|
eventSubscriptions.push(eventEmitter.addListener('uploadProgress', (events) => {
|
|
227
|
-
(0,
|
|
229
|
+
(0, logger_1.log)('uploadProgress', events);
|
|
228
230
|
for (const event of events) {
|
|
229
231
|
const { id, ...rest } = event;
|
|
230
232
|
const task = uploadTasksMap.get(id);
|
|
@@ -234,27 +236,27 @@ function initializeEventListeners() {
|
|
|
234
236
|
}));
|
|
235
237
|
eventSubscriptions.push(eventEmitter.addListener('uploadComplete', (data) => {
|
|
236
238
|
const { id, ...rest } = data;
|
|
237
|
-
(0,
|
|
239
|
+
(0, logger_1.log)('uploadComplete', id, rest);
|
|
238
240
|
const task = uploadTasksMap.get(id);
|
|
239
241
|
if (!task)
|
|
240
|
-
(0,
|
|
242
|
+
(0, logger_1.log)('uploadComplete: task not found in uploadTasksMap', id);
|
|
241
243
|
else
|
|
242
244
|
task.onDone(rest);
|
|
243
245
|
uploadTasksMap.delete(id);
|
|
244
246
|
}));
|
|
245
247
|
eventSubscriptions.push(eventEmitter.addListener('uploadFailed', (data) => {
|
|
246
248
|
const { id, ...rest } = data;
|
|
247
|
-
(0,
|
|
249
|
+
(0, logger_1.log)('uploadFailed', id, rest);
|
|
248
250
|
const task = uploadTasksMap.get(id);
|
|
249
251
|
if (!task)
|
|
250
|
-
(0,
|
|
252
|
+
(0, logger_1.log)('uploadFailed: task not found in uploadTasksMap', id);
|
|
251
253
|
else
|
|
252
254
|
task.onError(rest);
|
|
253
255
|
uploadTasksMap.delete(id);
|
|
254
256
|
}));
|
|
255
257
|
// Native debug log events - forward native iOS logs to JS logCallback
|
|
256
258
|
eventSubscriptions.push(eventEmitter.addListener('nativeDebugLog', (data) => {
|
|
257
|
-
(0,
|
|
259
|
+
(0, logger_1.log)('[Native]', data.taskId || '', data.message);
|
|
258
260
|
}));
|
|
259
261
|
}
|
|
260
262
|
}
|
|
@@ -311,7 +313,7 @@ function setConfig({ headers = {}, progressInterval = config_1.DEFAULT_PROGRESS_
|
|
|
311
313
|
enabled: config_1.config.notificationsGrouping.enabled,
|
|
312
314
|
showNotificationsEnabled: (_c = config_1.config.showNotificationsEnabled) !== null && _c !== void 0 ? _c : false,
|
|
313
315
|
mode: config_1.config.notificationsGrouping.mode,
|
|
314
|
-
texts: (0,
|
|
316
|
+
texts: (0, notifications_1.getNotificationTextsForNative)(),
|
|
315
317
|
});
|
|
316
318
|
}
|
|
317
319
|
catch {
|
|
@@ -376,7 +378,7 @@ const getExistingDownloadTasks = async () => {
|
|
|
376
378
|
exports.getExistingDownloadTasks = getExistingDownloadTasks;
|
|
377
379
|
const completeHandler = (jobId) => {
|
|
378
380
|
if (jobId == null) {
|
|
379
|
-
(0,
|
|
381
|
+
(0, logger_1.log)('completeHandler: jobId is empty');
|
|
380
382
|
return;
|
|
381
383
|
}
|
|
382
384
|
const nativeModule = ensureNativeModuleInitialized();
|
|
@@ -405,7 +407,7 @@ function createDownloadTask({ isAllowedOverRoaming = true, isAllowedOverMetered
|
|
|
405
407
|
const getExistingUploadTasks = async () => {
|
|
406
408
|
const nativeModule = ensureNativeModuleInitialized();
|
|
407
409
|
if (!nativeModule.getExistingUploadTasks) {
|
|
408
|
-
(0,
|
|
410
|
+
(0, logger_1.log)('getExistingUploadTasks: not supported - native implementation missing');
|
|
409
411
|
return [];
|
|
410
412
|
}
|
|
411
413
|
const uploads = await nativeModule.getExistingUploadTasks();
|
package/lib/logger.d.ts
ADDED
package/lib/logger.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.log = void 0;
|
|
4
|
+
const config_1 = require("./config");
|
|
5
|
+
const log = (...args) => {
|
|
6
|
+
if (config_1.config.isLogsEnabled) {
|
|
7
|
+
console.log('[RNBackgroundDownloader]', ...args);
|
|
8
|
+
// Call external log callback if provided
|
|
9
|
+
if (config_1.config.logCallback) {
|
|
10
|
+
const message = args.length > 0 && typeof args[0] === 'string' ? args[0] : 'log';
|
|
11
|
+
const restArgs = args.length > 1 ? args.slice(1) : [];
|
|
12
|
+
config_1.config.logCallback('RNBD', message, ...restArgs);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
exports.log = log;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get notification text with proper pluralization.
|
|
3
|
+
*/
|
|
4
|
+
export declare function getGroupText(count: number): string;
|
|
5
|
+
/**
|
|
6
|
+
* Get notification texts config for native side (serializable).
|
|
7
|
+
*/
|
|
8
|
+
export declare function getNotificationTextsForNative(): Record<string, string>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGroupText = getGroupText;
|
|
4
|
+
exports.getNotificationTextsForNative = getNotificationTextsForNative;
|
|
5
|
+
const config_1 = require("./config");
|
|
6
|
+
/**
|
|
7
|
+
* Get notification text with proper pluralization.
|
|
8
|
+
*/
|
|
9
|
+
function getGroupText(count) {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
const groupText = (_b = (_a = config_1.config.notificationsGrouping.texts) === null || _a === void 0 ? void 0 : _a.groupText) !== null && _b !== void 0 ? _b : config_1.DEFAULT_NOTIFICATION_TEXTS.groupText;
|
|
12
|
+
if (typeof groupText === 'function')
|
|
13
|
+
return groupText(count);
|
|
14
|
+
return groupText.replace('{count}', String(count));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get notification texts config for native side (serializable).
|
|
18
|
+
*/
|
|
19
|
+
function getNotificationTextsForNative() {
|
|
20
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
21
|
+
const texts = (_a = config_1.config.notificationsGrouping.texts) !== null && _a !== void 0 ? _a : config_1.DEFAULT_NOTIFICATION_TEXTS;
|
|
22
|
+
return {
|
|
23
|
+
downloadTitle: (_b = texts.downloadTitle) !== null && _b !== void 0 ? _b : config_1.DEFAULT_NOTIFICATION_TEXTS.downloadTitle,
|
|
24
|
+
downloadStarting: (_c = texts.downloadStarting) !== null && _c !== void 0 ? _c : config_1.DEFAULT_NOTIFICATION_TEXTS.downloadStarting,
|
|
25
|
+
downloadProgress: (_d = texts.downloadProgress) !== null && _d !== void 0 ? _d : config_1.DEFAULT_NOTIFICATION_TEXTS.downloadProgress,
|
|
26
|
+
downloadPaused: (_e = texts.downloadPaused) !== null && _e !== void 0 ? _e : config_1.DEFAULT_NOTIFICATION_TEXTS.downloadPaused,
|
|
27
|
+
downloadFinished: (_f = texts.downloadFinished) !== null && _f !== void 0 ? _f : config_1.DEFAULT_NOTIFICATION_TEXTS.downloadFinished,
|
|
28
|
+
groupTitle: (_g = texts.groupTitle) !== null && _g !== void 0 ? _g : config_1.DEFAULT_NOTIFICATION_TEXTS.groupTitle,
|
|
29
|
+
// For native side, we send a pattern with {count} placeholder
|
|
30
|
+
groupText: typeof texts.groupText === 'function'
|
|
31
|
+
? '{count} download(s) in progress' // Default pattern if function provided
|
|
32
|
+
: ((_h = texts.groupText) !== null && _h !== void 0 ? _h : '{count} download(s) in progress'),
|
|
33
|
+
};
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kesha-antonov/react-native-background-downloader",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.9",
|
|
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",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"eslint-plugin-react-hooks": "^5.1.0",
|
|
106
106
|
"eslint-plugin-standard": "^5.0.0",
|
|
107
107
|
"immer": "^10.1.3",
|
|
108
|
-
"jest": "^
|
|
108
|
+
"jest": "^29.7.0",
|
|
109
109
|
"lint-staged": ">=16",
|
|
110
110
|
"metro-react-native-babel-preset": "^0.77.0",
|
|
111
111
|
"react": "19.1.0",
|
|
@@ -120,5 +120,9 @@
|
|
|
120
120
|
},
|
|
121
121
|
"publishConfig": {
|
|
122
122
|
"access": "public"
|
|
123
|
-
}
|
|
123
|
+
},
|
|
124
|
+
"resolutions": {
|
|
125
|
+
"uuid": "^11.1.1"
|
|
126
|
+
},
|
|
127
|
+
"packageManager": "yarn@4.17.1"
|
|
124
128
|
}
|
package/src/DownloadTask.ts
CHANGED
|
@@ -16,7 +16,8 @@ import {
|
|
|
16
16
|
UnsafeObject,
|
|
17
17
|
Headers,
|
|
18
18
|
} from './types'
|
|
19
|
-
import { config
|
|
19
|
+
import { config } from './config'
|
|
20
|
+
import { log } from './logger'
|
|
20
21
|
|
|
21
22
|
// Import shared native module getter to avoid duplicating TurboModule lookup
|
|
22
23
|
// This is lazily imported to avoid circular dependency issues at module load time
|
package/src/UploadTask.ts
CHANGED
|
@@ -16,7 +16,8 @@ import {
|
|
|
16
16
|
UnsafeObject,
|
|
17
17
|
Headers,
|
|
18
18
|
} from './types'
|
|
19
|
-
import { config
|
|
19
|
+
import { config } from './config'
|
|
20
|
+
import { log } from './logger'
|
|
20
21
|
|
|
21
22
|
// Import shared native module getter to avoid duplicating TurboModule lookup
|
|
22
23
|
// This is lazily imported to avoid circular dependency issues at module load time
|
package/src/config.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { Headers, IosDataProtection, NotificationGroupingMode, NotificationsGroupingConfig, NotificationTexts } from './types'
|
|
2
|
+
// Logging lives in ./logger (log, LogCallback); notification-text formatting
|
|
3
|
+
// lives in ./notifications (getGroupText, getNotificationTextsForNative).
|
|
4
|
+
// This module holds only the shared config state and its defaults.
|
|
5
|
+
import type { LogCallback } from './logger'
|
|
2
6
|
|
|
3
7
|
export const DEFAULT_PROGRESS_INTERVAL = 1000
|
|
4
8
|
export const DEFAULT_PROGRESS_MIN_BYTES = 1024 * 1024 // 1MB
|
|
@@ -19,9 +23,6 @@ export const DEFAULT_NOTIFICATION_TEXTS: Required<NotificationTexts> = {
|
|
|
19
23
|
groupText: (count: number) => `${count} download${count !== 1 ? 's' : ''} in progress`,
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
// External log callback for capturing logs in parent app
|
|
23
|
-
type LogCallback = (tag: string, message: string, ...args: unknown[]) => void
|
|
24
|
-
|
|
25
26
|
interface ConfigState {
|
|
26
27
|
headers: Headers
|
|
27
28
|
progressInterval: number
|
|
@@ -51,45 +52,3 @@ export const config: ConfigState = {
|
|
|
51
52
|
texts: DEFAULT_NOTIFICATION_TEXTS,
|
|
52
53
|
},
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Get notification text with proper pluralization.
|
|
57
|
-
*/
|
|
58
|
-
export function getGroupText (count: number): string {
|
|
59
|
-
const groupText = config.notificationsGrouping.texts?.groupText ?? DEFAULT_NOTIFICATION_TEXTS.groupText
|
|
60
|
-
if (typeof groupText === 'function')
|
|
61
|
-
return groupText(count)
|
|
62
|
-
|
|
63
|
-
return groupText.replace('{count}', String(count))
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Get notification texts config for native side (serializable).
|
|
68
|
-
*/
|
|
69
|
-
export function getNotificationTextsForNative (): Record<string, string> {
|
|
70
|
-
const texts = config.notificationsGrouping.texts ?? DEFAULT_NOTIFICATION_TEXTS
|
|
71
|
-
return {
|
|
72
|
-
downloadTitle: texts.downloadTitle ?? DEFAULT_NOTIFICATION_TEXTS.downloadTitle,
|
|
73
|
-
downloadStarting: texts.downloadStarting ?? DEFAULT_NOTIFICATION_TEXTS.downloadStarting,
|
|
74
|
-
downloadProgress: texts.downloadProgress ?? DEFAULT_NOTIFICATION_TEXTS.downloadProgress,
|
|
75
|
-
downloadPaused: texts.downloadPaused ?? DEFAULT_NOTIFICATION_TEXTS.downloadPaused,
|
|
76
|
-
downloadFinished: texts.downloadFinished ?? DEFAULT_NOTIFICATION_TEXTS.downloadFinished,
|
|
77
|
-
groupTitle: texts.groupTitle ?? DEFAULT_NOTIFICATION_TEXTS.groupTitle,
|
|
78
|
-
// For native side, we send a pattern with {count} placeholder
|
|
79
|
-
groupText: typeof texts.groupText === 'function'
|
|
80
|
-
? '{count} download(s) in progress' // Default pattern if function provided
|
|
81
|
-
: (texts.groupText ?? '{count} download(s) in progress'),
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export const log = (...args: unknown[]): void => {
|
|
86
|
-
if (config.isLogsEnabled) {
|
|
87
|
-
console.log('[RNBackgroundDownloader]', ...args)
|
|
88
|
-
// Call external log callback if provided
|
|
89
|
-
if (config.logCallback) {
|
|
90
|
-
const message = args.length > 0 && typeof args[0] === 'string' ? args[0] : 'log'
|
|
91
|
-
const restArgs = args.length > 1 ? args.slice(1) : []
|
|
92
|
-
config.logCallback('RNBD', message, ...restArgs)
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,9 @@ import { NativeModules, Platform, TurboModuleRegistry, NativeEventEmitter, Nativ
|
|
|
2
2
|
import { DownloadTask } from './DownloadTask'
|
|
3
3
|
import { UploadTask } from './UploadTask'
|
|
4
4
|
import { Config, DownloadParams, Headers, Metadata, TaskInfo, TaskInfoNative, UploadParams, UploadTaskInfo, UploadTaskInfoNative } from './types'
|
|
5
|
-
import { config,
|
|
5
|
+
import { config, DEFAULT_PROGRESS_INTERVAL, DEFAULT_PROGRESS_MIN_BYTES, DEFAULT_NOTIFICATION_TEXTS } from './config'
|
|
6
|
+
import { log } from './logger'
|
|
7
|
+
import { getNotificationTextsForNative } from './notifications'
|
|
6
8
|
import type { Spec } from './NativeRNBackgroundDownloader'
|
|
7
9
|
|
|
8
10
|
type RNBackgroundDownloaderModule = Spec & {
|
package/src/logger.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { config } from './config'
|
|
2
|
+
|
|
3
|
+
// External log callback for capturing logs in parent app
|
|
4
|
+
export type LogCallback = (tag: string, message: string, ...args: unknown[]) => void
|
|
5
|
+
|
|
6
|
+
export const log = (...args: unknown[]): void => {
|
|
7
|
+
if (config.isLogsEnabled) {
|
|
8
|
+
console.log('[RNBackgroundDownloader]', ...args)
|
|
9
|
+
// Call external log callback if provided
|
|
10
|
+
if (config.logCallback) {
|
|
11
|
+
const message = args.length > 0 && typeof args[0] === 'string' ? args[0] : 'log'
|
|
12
|
+
const restArgs = args.length > 1 ? args.slice(1) : []
|
|
13
|
+
config.logCallback('RNBD', message, ...restArgs)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { config, DEFAULT_NOTIFICATION_TEXTS } from './config'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get notification text with proper pluralization.
|
|
5
|
+
*/
|
|
6
|
+
export function getGroupText (count: number): string {
|
|
7
|
+
const groupText = config.notificationsGrouping.texts?.groupText ?? DEFAULT_NOTIFICATION_TEXTS.groupText
|
|
8
|
+
if (typeof groupText === 'function')
|
|
9
|
+
return groupText(count)
|
|
10
|
+
|
|
11
|
+
return groupText.replace('{count}', String(count))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Get notification texts config for native side (serializable).
|
|
16
|
+
*/
|
|
17
|
+
export function getNotificationTextsForNative (): Record<string, string> {
|
|
18
|
+
const texts = config.notificationsGrouping.texts ?? DEFAULT_NOTIFICATION_TEXTS
|
|
19
|
+
return {
|
|
20
|
+
downloadTitle: texts.downloadTitle ?? DEFAULT_NOTIFICATION_TEXTS.downloadTitle,
|
|
21
|
+
downloadStarting: texts.downloadStarting ?? DEFAULT_NOTIFICATION_TEXTS.downloadStarting,
|
|
22
|
+
downloadProgress: texts.downloadProgress ?? DEFAULT_NOTIFICATION_TEXTS.downloadProgress,
|
|
23
|
+
downloadPaused: texts.downloadPaused ?? DEFAULT_NOTIFICATION_TEXTS.downloadPaused,
|
|
24
|
+
downloadFinished: texts.downloadFinished ?? DEFAULT_NOTIFICATION_TEXTS.downloadFinished,
|
|
25
|
+
groupTitle: texts.groupTitle ?? DEFAULT_NOTIFICATION_TEXTS.groupTitle,
|
|
26
|
+
// For native side, we send a pattern with {count} placeholder
|
|
27
|
+
groupText: typeof texts.groupText === 'function'
|
|
28
|
+
? '{count} download(s) in progress' // Default pattern if function provided
|
|
29
|
+
: (texts.groupText ?? '{count} download(s) in progress'),
|
|
30
|
+
}
|
|
31
|
+
}
|