@capgo/capacitor-downloader 8.3.21 → 8.5.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.
Files changed (22) hide show
  1. package/README.md +66 -10
  2. package/android/build.gradle +3 -0
  3. package/android/src/main/AndroidManifest.xml +1 -0
  4. package/android/src/main/java/ee/forgr/capacitor/plugin/downloader/AndroidDownloadDestination.java +143 -0
  5. package/android/src/main/java/ee/forgr/capacitor/plugin/downloader/AndroidHttpEngineSelector.java +33 -0
  6. package/android/src/main/java/ee/forgr/capacitor/plugin/downloader/CapacitorDownloaderPlugin.java +357 -27
  7. package/android/src/main/java/ee/forgr/capacitor/plugin/downloader/DownloadCompletedNotificationPresenter.java +91 -0
  8. package/android/src/main/java/ee/forgr/capacitor/plugin/downloader/DownloadCompletedNotificationStore.java +138 -0
  9. package/android/src/main/java/ee/forgr/capacitor/plugin/downloader/DownloadCompletedNotificationText.java +14 -0
  10. package/android/src/main/java/ee/forgr/capacitor/plugin/downloader/DownloadCompletionNotifier.java +70 -0
  11. package/android/src/main/java/ee/forgr/capacitor/plugin/downloader/OkHttpDownloadExecutor.java +420 -0
  12. package/dist/docs.json +27 -3
  13. package/dist/esm/definitions.d.ts +51 -5
  14. package/dist/esm/definitions.js.map +1 -1
  15. package/ios/Sources/CapacitorDownloaderPlugin/CapacitorDownloaderPlugin.swift +86 -6
  16. package/ios/Sources/CapacitorDownloaderPlugin/DownloadCompletedNotificationPresenter.swift +38 -0
  17. package/ios/Sources/CapacitorDownloaderPlugin/DownloadCompletedNotificationStore.swift +74 -0
  18. package/ios/Sources/CapacitorDownloaderPlugin/DownloadCompletedNotificationText.swift +11 -0
  19. package/ios/Sources/CapacitorDownloaderPlugin/DownloadIdGenerationStore.swift +39 -0
  20. package/ios/Sources/CapacitorDownloaderPlugin/DownloadTaskGenerationStore.swift +47 -0
  21. package/ios/Tests/CapacitorDownloaderPluginTests/CapacitorDownloaderPluginTests.swift +121 -0
  22. package/package.json +1 -1
@@ -87,6 +87,127 @@ final class DownloadDestinationStoreTests: XCTestCase {
87
87
  }
88
88
  }
89
89
 
90
+ final class DownloadCompletedNotificationTextTests: XCTestCase {
91
+ func testNormalizeRejectsBlank() {
92
+ XCTAssertNil(DownloadCompletedNotificationText.normalize(nil))
93
+ XCTAssertNil(DownloadCompletedNotificationText.normalize(""))
94
+ XCTAssertNil(DownloadCompletedNotificationText.normalize(" "))
95
+ }
96
+
97
+ func testNormalizeTrims() {
98
+ XCTAssertEqual(DownloadCompletedNotificationText.normalize(" Ready "), "Ready")
99
+ }
100
+ }
101
+
102
+ final class DownloadCompletedNotificationStoreTests: XCTestCase {
103
+ private var defaults: UserDefaults!
104
+ private var store: DownloadCompletedNotificationStore!
105
+
106
+ override func setUp() {
107
+ super.setUp()
108
+ defaults = UserDefaults(suiteName: "CapacitorDownloaderNotificationTests")!
109
+ defaults.removePersistentDomain(forName: "CapacitorDownloaderNotificationTests")
110
+ store = DownloadCompletedNotificationStore(defaults: defaults)
111
+ }
112
+
113
+ override func tearDown() {
114
+ defaults.removePersistentDomain(forName: "CapacitorDownloaderNotificationTests")
115
+ super.tearDown()
116
+ }
117
+
118
+ func testSetAndTakeText() {
119
+ store.setText(" Finished ", for: "task-1", generation: 1)
120
+
121
+ XCTAssertEqual(store.takeText(for: "task-1", generation: 1), "Finished")
122
+ XCTAssertNil(store.takeText(for: "task-1", generation: 1))
123
+ }
124
+
125
+ func testRemoveText() {
126
+ store.setText("Done", for: "task-1", generation: 1)
127
+ store.removeText(for: "task-1", generation: 1)
128
+ XCTAssertNil(store.takeText(for: "task-1", generation: 1))
129
+ }
130
+
131
+ func testGenerationMismatchLeavesStoredText() {
132
+ store.setText("New", for: "task-1", generation: 2)
133
+ store.removeText(for: "task-1", generation: 1)
134
+ XCTAssertEqual(store.takeText(for: "task-1", generation: 2), "New")
135
+ }
136
+
137
+ func testTakeTextWithoutTaskGenerationUsesStoredEntry() {
138
+ store.setText("Ready", for: "task-1", generation: 3)
139
+ XCTAssertEqual(store.takeText(for: "task-1", generation: nil), "Ready")
140
+ }
141
+
142
+ func testConcurrentUpdatesDoNotDropEntries() {
143
+ let ids = (0..<50).map { "task-\($0)" }
144
+ DispatchQueue.concurrentPerform(iterations: ids.count) { index in
145
+ store.setText("Body \(index)", for: ids[index], generation: 1)
146
+ }
147
+
148
+ for (index, id) in ids.enumerated() {
149
+ XCTAssertEqual(store.takeText(for: id, generation: 1), "Body \(index)")
150
+ }
151
+ }
152
+ }
153
+
154
+ final class DownloadIdGenerationStoreTests: XCTestCase {
155
+ private var defaults: UserDefaults!
156
+ private var store: DownloadIdGenerationStore!
157
+
158
+ override func setUp() {
159
+ super.setUp()
160
+ defaults = UserDefaults(suiteName: "CapacitorDownloaderIdGenerationTests")!
161
+ defaults.removePersistentDomain(forName: "CapacitorDownloaderIdGenerationTests")
162
+ store = DownloadIdGenerationStore(defaults: defaults)
163
+ }
164
+
165
+ override func tearDown() {
166
+ defaults.removePersistentDomain(forName: "CapacitorDownloaderIdGenerationTests")
167
+ super.tearDown()
168
+ }
169
+
170
+ func testPersistedGenerationSurvivesRelaunch() {
171
+ store.setGeneration(3, forDownloadId: "episode-12")
172
+ let restored = DownloadIdGenerationStore(defaults: defaults)
173
+ XCTAssertEqual(restored.allGenerations()["episode-12"], 3)
174
+ let next = (restored.allGenerations()["episode-12"] ?? 0) &+ 1
175
+ XCTAssertEqual(next, 4)
176
+ }
177
+
178
+ func testNextGenerationAfterRelaunchDoesNotReuseStoredValue() {
179
+ store.setGeneration(1, forDownloadId: "shared-id")
180
+ let relaunched = DownloadIdGenerationStore(defaults: defaults)
181
+ let generations = relaunched.allGenerations()
182
+ let next = (generations["shared-id"] ?? 0) &+ 1
183
+ XCTAssertEqual(next, 2)
184
+ }
185
+ }
186
+
187
+ final class DownloadTaskGenerationStoreTests: XCTestCase {
188
+ private var defaults: UserDefaults!
189
+ private var store: DownloadTaskGenerationStore!
190
+
191
+ override func setUp() {
192
+ super.setUp()
193
+ defaults = UserDefaults(suiteName: "CapacitorDownloaderTaskGenerationTests")!
194
+ defaults.removePersistentDomain(forName: "CapacitorDownloaderTaskGenerationTests")
195
+ store = DownloadTaskGenerationStore(defaults: defaults)
196
+ }
197
+
198
+ override func tearDown() {
199
+ defaults.removePersistentDomain(forName: "CapacitorDownloaderTaskGenerationTests")
200
+ super.tearDown()
201
+ }
202
+
203
+ func testPersistAndRestoreGeneration() {
204
+ store.setGeneration(7, forTaskIdentifier: 42)
205
+ XCTAssertEqual(store.allGenerations()[42], 7)
206
+ store.removeGeneration(forTaskIdentifier: 42)
207
+ XCTAssertNil(store.allGenerations()[42])
208
+ }
209
+ }
210
+
90
211
  final class DownloadHTTPValidatorTests: XCTestCase {
91
212
  func testSuccessfulStatusCodes() {
92
213
  XCTAssertTrue(DownloadHTTPValidator.isSuccessfulStatusCode(200))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-downloader",
3
- "version": "8.3.21",
3
+ "version": "8.5.0",
4
4
  "description": "Download file in background or foreground",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",