Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Sources/Hub/HubApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public struct HubApi: Sendable {
private let backgroundUncachedClient: HubClient
#endif

private let networkMonitor = NetworkMonitor()
private let networkMonitor = NetworkMonitor.shared
Comment thread
atdrendel marked this conversation as resolved.
public typealias RepoType = Hub.RepoType
public typealias Repo = Hub.Repo

Expand Down Expand Up @@ -188,20 +188,19 @@ public struct HubApi: Sendable {
useBackgroundSession: false
)
#if !canImport(FoundationNetworking)
self.backgroundCachedClient = Self.buildHubClient(
self.backgroundCachedClient = useBackgroundSession ? Self.buildHubClient(
host: hostURL,
tokenProvider: tokenProvider,
cache: cache,
useBackgroundSession: true
)
self.backgroundUncachedClient = Self.buildHubClient(
) : self.foregroundCachedClient
self.backgroundUncachedClient = useBackgroundSession ? Self.buildHubClient(
host: hostURL,
tokenProvider: tokenProvider,
cache: nil,
useBackgroundSession: true
)
) : self.foregroundUncachedClient
#endif
NetworkMonitor.shared.startMonitoring()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need to manually call startMonitoring() because NetworkMonitor.init() calls it.

Copy link
Copy Markdown
Collaborator

@mattt mattt Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like the correct fix — especially if we're keeping shared instance around. Related discussion in #259.

}

/// The shared Hub API instance with default configuration.
Expand Down Expand Up @@ -1144,7 +1143,7 @@ extension HubApi {

static let shared = NetworkMonitor()

init() {
private init() {
#if canImport(Network)
monitor = NWPathMonitor()
queue = DispatchQueue(label: "HubApi.NetworkMonitor")
Expand Down
Loading