Skip to content

Commit e81718b

Browse files
committed
fixing linting issues
1 parent 1b216d1 commit e81718b

File tree

6 files changed

+178
-84
lines changed

6 files changed

+178
-84
lines changed

.swiftlint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ type_body_length:
9999
- 125
100100
- 200
101101
file_length:
102-
- 175
102+
- 200
103103
- 250
104104
function_body_length:
105105
- 25
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// DownloadDelegate.swift
3+
// RadiantKit
4+
//
5+
// Created by Leo Dion.
6+
// Copyright © 2025 BrightDigit.
7+
//
8+
// Permission is hereby granted, free of charge, to any person
9+
// obtaining a copy of this software and associated documentation
10+
// files (the “Software”), to deal in the Software without
11+
// restriction, including without limitation the rights to use,
12+
// copy, modify, merge, publish, distribute, sublicense, and/or
13+
// sell copies of the Software, and to permit persons to whom the
14+
// Software is furnished to do so, subject to the following
15+
// conditions:
16+
//
17+
// The above copyright notice and this permission notice shall be
18+
// included in all copies or substantial portions of the Software.
19+
//
20+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
21+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27+
// OTHER DEALINGS IN THE SOFTWARE.
28+
//
29+
30+
import Foundation
31+
32+
internal final class DownloadDelegate: NSObject, URLSessionDownloadDelegate {
33+
private let container = ObserverContainer()
34+
35+
internal func setObserver(_ observer: DownloadObserver) {
36+
self.container.setObserver(observer)
37+
}
38+
39+
internal func urlSession(
40+
_: URLSession,
41+
downloadTask _: URLSessionDownloadTask,
42+
didFinishDownloadingTo location: URL
43+
) {
44+
let newLocation = FileManager
45+
.default.temporaryDirectory
46+
.appendingPathComponent(UUID().uuidString)
47+
.appendingPathExtension(location.pathExtension)
48+
do {
49+
try FileManager.default.copyItem(at: location, to: newLocation)
50+
} catch {
51+
container.on { observer in observer.didComplete(withError: error) }
52+
return
53+
}
54+
container.on { observer in observer.finishedDownloadingTo(newLocation) }
55+
}
56+
57+
internal func urlSession(
58+
_: URLSession,
59+
downloadTask _: URLSessionDownloadTask,
60+
didWriteData _: Int64,
61+
totalBytesWritten: Int64,
62+
totalBytesExpectedToWrite: Int64
63+
) {
64+
container.on { observer in
65+
observer.progressUpdated(
66+
.init(
67+
totalBytesWritten: totalBytesWritten,
68+
totalBytesExpectedToWrite: totalBytesExpectedToWrite
69+
)
70+
)
71+
}
72+
}
73+
74+
internal func urlSession(
75+
_: URLSession,
76+
task _: URLSessionTask,
77+
didCompleteWithError error: (any Error)?
78+
) {
79+
container.on { observer in observer.didComplete(withError: error) }
80+
}
81+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// DownloadObserver.swift
3+
// RadiantKit
4+
//
5+
// Created by Leo Dion.
6+
// Copyright © 2025 BrightDigit.
7+
//
8+
// Permission is hereby granted, free of charge, to any person
9+
// obtaining a copy of this software and associated documentation
10+
// files (the “Software”), to deal in the Software without
11+
// restriction, including without limitation the rights to use,
12+
// copy, modify, merge, publish, distribute, sublicense, and/or
13+
// sell copies of the Software, and to permit persons to whom the
14+
// Software is furnished to do so, subject to the following
15+
// conditions:
16+
//
17+
// The above copyright notice and this permission notice shall be
18+
// included in all copies or substantial portions of the Software.
19+
//
20+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
21+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27+
// OTHER DEALINGS IN THE SOFTWARE.
28+
//
29+
30+
import Foundation
31+
32+
internal protocol DownloadObserver {
33+
func finishedDownloadingTo(_ location: URL)
34+
func progressUpdated(_ progress: DownloadUpdate)
35+
func didComplete(withError error: Error?)
36+
}

Sources/RadiantProgress/ObservableDownloader.swift

Lines changed: 3 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -31,85 +31,6 @@
3131
public import Combine
3232
public import Foundation
3333

34-
private protocol DownloadObserver {
35-
func finishedDownloadingTo(_ location: URL)
36-
func progressUpdated(_ progress: DownloadUpdate)
37-
func didComplete(withError error: Error?)
38-
}
39-
40-
private actor ObserverContainer {
41-
private nonisolated(unsafe) var observer: DownloadObserver?
42-
43-
nonisolated func setObserver(_ observer: DownloadObserver) {
44-
assert(self.observer == nil)
45-
self.observer = observer
46-
}
47-
48-
nonisolated func on(_ closure: @escaping @Sendable (DownloadObserver) -> Void) {
49-
Task { await self.withObserver(closure) }
50-
}
51-
52-
private func withObserver(_ closure: @escaping @Sendable (DownloadObserver) -> Void) {
53-
assert(self.observer != nil)
54-
guard let observer else {
55-
return
56-
}
57-
58-
closure(observer)
59-
}
60-
}
61-
62-
private final class DownloadDelegate: NSObject, URLSessionDownloadDelegate {
63-
let container = ObserverContainer()
64-
65-
func setObserver(_ observer: DownloadObserver) {
66-
self.container.setObserver(observer)
67-
}
68-
69-
func urlSession(
70-
_: URLSession,
71-
downloadTask _: URLSessionDownloadTask,
72-
didFinishDownloadingTo location: URL
73-
) {
74-
let newLocation = FileManager
75-
.default.temporaryDirectory
76-
.appendingPathComponent(UUID().uuidString)
77-
.appendingPathExtension(location.pathExtension)
78-
do {
79-
try FileManager.default.copyItem(at: location, to: newLocation)
80-
} catch {
81-
container.on { observer in observer.didComplete(withError: error) }
82-
return
83-
}
84-
container.on { observer in observer.finishedDownloadingTo(newLocation) }
85-
}
86-
87-
func urlSession(
88-
_: URLSession,
89-
downloadTask _: URLSessionDownloadTask,
90-
didWriteData _: Int64,
91-
totalBytesWritten: Int64,
92-
totalBytesExpectedToWrite: Int64
93-
) {
94-
container.on { observer in
95-
observer.progressUpdated(
96-
.init(
97-
totalBytesWritten: totalBytesWritten,
98-
totalBytesExpectedToWrite: totalBytesExpectedToWrite
99-
)
100-
)
101-
}
102-
}
103-
104-
func urlSession(
105-
_: URLSession,
106-
task _: URLSessionTask,
107-
didCompleteWithError error: (any Error)?
108-
) {
109-
container.on { observer in observer.didComplete(withError: error) }
110-
}
111-
}
112-
11334
@Observable
11435
@MainActor
11536
public final class ObservableDownloader: DownloadObserver, Downloader {
@@ -214,15 +135,15 @@
214135
)
215136
}
216137

217-
nonisolated fileprivate func finishedDownloadingTo(_ location: URL) {
138+
nonisolated internal func finishedDownloadingTo(_ location: URL) {
218139
Task { @MainActor in self.finishedDownloadingToAsync(location) }
219140
}
220141

221-
nonisolated fileprivate func progressUpdated(_ progress: DownloadUpdate) {
142+
nonisolated internal func progressUpdated(_ progress: DownloadUpdate) {
222143
Task { @MainActor in self.progressUpdatedAsync(progress) }
223144
}
224145

225-
nonisolated fileprivate func didComplete(withError error: (any Error)?) {
146+
nonisolated internal func didComplete(withError error: (any Error)?) {
226147
Task { @MainActor in self.didCompleteAsync(withError: error) }
227148
}
228149

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// ObserverContainer.swift
3+
// RadiantKit
4+
//
5+
// Created by Leo Dion.
6+
// Copyright © 2025 BrightDigit.
7+
//
8+
// Permission is hereby granted, free of charge, to any person
9+
// obtaining a copy of this software and associated documentation
10+
// files (the “Software”), to deal in the Software without
11+
// restriction, including without limitation the rights to use,
12+
// copy, modify, merge, publish, distribute, sublicense, and/or
13+
// sell copies of the Software, and to permit persons to whom the
14+
// Software is furnished to do so, subject to the following
15+
// conditions:
16+
//
17+
// The above copyright notice and this permission notice shall be
18+
// included in all copies or substantial portions of the Software.
19+
//
20+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
21+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27+
// OTHER DEALINGS IN THE SOFTWARE.
28+
//
29+
30+
internal actor ObserverContainer {
31+
private nonisolated(unsafe) var observer: DownloadObserver?
32+
33+
nonisolated internal func setObserver(_ observer: DownloadObserver) {
34+
assert(self.observer == nil)
35+
self.observer = observer
36+
}
37+
38+
nonisolated internal func on(
39+
_ closure: @escaping @Sendable (DownloadObserver) -> Void
40+
) {
41+
Task { await self.withObserver(closure) }
42+
}
43+
44+
private func withObserver(
45+
_ closure: @escaping @Sendable (DownloadObserver) -> Void
46+
) {
47+
assert(self.observer != nil)
48+
guard let observer else {
49+
return
50+
}
51+
52+
closure(observer)
53+
}
54+
}

Sources/RadiantProgress/SetupPublishers.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import Foundation
3434

3535
#warning(
36+
// swiftlint:disable:next line_length
3637
"logging-note: can we have some operators for logging the recieved stuff in these subscriptions"
3738
)
3839
internal struct SetupPublishers {
@@ -98,7 +99,8 @@
9899
.map { sourceURL, destinationURL in
99100
Result { try FileManager.default.moveItem(at: sourceURL, to: destinationURL) }
100101
}
101-
.receive(on: DispatchQueue.main).sink(receiveValue: downloader.onCompletion)
102+
.receive(on: DispatchQueue.main)
103+
.sink(receiveValue: downloader.onCompletion)
102104
.store(in: &cancellables)
103105

104106
cancellables.append(contentsOf: setupByteUpdatPublishers(downloader))

0 commit comments

Comments
 (0)