Skip to content

Commit

Permalink
fixing linux build
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Sep 10, 2024
1 parent ce89626 commit 7e58b1c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 30 deletions.
11 changes: 10 additions & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"originHash" : "7dbbfe6e7ba99beefb676628070350ed6a5430090637d0dd168f20c9fcf95618",
"originHash" : "0cd2dcc1e220681712709df5bd794ab7f349d718bc63840353fae6e361bc50c4",
"pins" : [
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "9cb486020ebf03bfa5b5df985387a14a98744537",
"version" : "1.6.1"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
Expand Down
4 changes: 4 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/swiftlang/swift-testing.git", from: "0.12.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
],
targets: [
.target(
Expand All @@ -69,6 +70,9 @@ let package = Package(
),
.target(
name: "RadiantProgress",
dependencies: [
.product(name: "Logging", package: "swift-log", condition: .when(platforms: [.linux]))
],
swiftSettings: swiftSettings
),
.testTarget(
Expand Down
10 changes: 7 additions & 3 deletions Sources/RadiantProgress/CopyOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

#if canImport(Observation) && (os(macOS) || os(iOS))
#if canImport(Observation)
public import Foundation
import Observation
public import Observation

public import OSLog
#if canImport(OSLog)
public import OSLog
#else
public import Logging
#endif

@MainActor @Observable
public final class CopyOperation<ValueType: BinaryInteger & Sendable>: Identifiable {
Expand Down
55 changes: 38 additions & 17 deletions Sources/RadiantProgress/DownloadOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,30 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

#if canImport(Observation) && (os(macOS) || os(iOS))
@MainActor public protocol Downloader {
var totalBytesWritten: Int64 { get }
var totalBytesExpectedToWrite: Int64? { get }
func begin(
from downloadSourceURL: URL,
to destinationFileURL: URL,
_ completion: @escaping @Sendable (Result<Void, any Error>) -> Void
)
}

#if canImport(Observation)
public import Foundation
import Observation
public import Observation

#if canImport(FoundationNetworking)
public import FoundationNetworking
#endif

@MainActor @Observable
public final class DownloadOperation<ValueType: BinaryInteger & Sendable>:

Identifiable, ProgressOperation, Sendable
{
private let download: ObservableDownloader
private let download: Downloader
private let sourceURL: URL
private let destinationURL: URL

Expand All @@ -46,22 +60,29 @@

public var totalValue: ValueType? { download.totalBytesExpectedToWrite.map(ValueType.init(_:)) }

public init(
sourceURL: URL,
destinationURL: URL,
totalBytesExpectedToWrite: ValueType?,
configuration: URLSessionConfiguration? = nil,
queue: OperationQueue? = nil
) {
assert(!sourceURL.isFileURL)
assert(totalBytesExpectedToWrite != nil)
#if canImport(Combine)
public init(
sourceURL: URL,
destinationURL: URL,
totalBytesExpectedToWrite: ValueType?,
configuration: URLSessionConfiguration? = nil,
queue: OperationQueue? = nil
) {
assert(!sourceURL.isFileURL)
assert(totalBytesExpectedToWrite != nil)
self.sourceURL = sourceURL
self.destinationURL = destinationURL
self.download = ObservableDownloader(
totalBytesExpectedToWrite: totalBytesExpectedToWrite,
configuration: configuration,
queue: queue
)
}
#endif
public init(sourceURL: URL, destinationURL: URL, download: Downloader) {
self.download = download
self.sourceURL = sourceURL
self.destinationURL = destinationURL
self.download = .init(
totalBytesExpectedToWrite: totalBytesExpectedToWrite,
configuration: configuration,
queue: queue
)
}

public func execute() async throws {
Expand Down
2 changes: 1 addition & 1 deletion Sources/RadiantProgress/FileOperationProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#if canImport(Observation)
public import Foundation
import Observation
public import Observation

@MainActor @Observable
public final class FileOperationProgress<ValueType: BinaryInteger>: Identifiable {
Expand Down
17 changes: 9 additions & 8 deletions Sources/RadiantProgress/ObservableDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
internal let totalBytesExpectedToWrite: Int64?
}

@Observable @MainActor public final class ObservableDownloader: DownloadObserver {
@Observable @MainActor public final class ObservableDownloader: DownloadObserver, Downloader {
internal struct DownloadRequest {
internal let downloadSourceURL: URL
internal let destinationFileURL: URL
Expand Down Expand Up @@ -213,12 +213,13 @@
resumeDataSubject.send(resumeData)
}
}

// deinit {
// self.cancellables.forEach { $0.cancel() }
// self.cancellables.removeAll()
// self.session = nil
// self.task = nil
// }
deinit {
MainActor.assumeIsolated {
self.cancellables.forEach { $0.cancel() }
self.cancellables.removeAll()
self.session = nil
self.task = nil
}
}
}
#endif

0 comments on commit 7e58b1c

Please sign in to comment.