Skip to content

Commit ef18d80

Browse files
Optimistic default connectivity, respect useOfflineMode if set (#286)
* Assume connected by default until updated by network monitor * Format Co-authored-by: Anthony <anthony@depasquale.org>
1 parent 9dad29e commit ef18d80

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Sources/Hub/HubApi.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,9 @@ public extension HubApi {
576576
.appendingPathComponent("huggingface")
577577
.appendingPathComponent("download")
578578

579-
if await NetworkMonitor.shared.state.shouldUseOfflineMode() || useOfflineMode == true {
579+
let shouldUseOfflineMode = await NetworkMonitor.shared.state.shouldUseOfflineMode()
580+
581+
if useOfflineMode ?? shouldUseOfflineMode {
580582
if !FileManager.default.fileExists(atPath: repoDestination.path) {
581583
throw EnvironmentError.offlineModeError(String(localized: "Repository not available locally"))
582584
}
@@ -808,7 +810,8 @@ public extension HubApi {
808810
/// Network monitor helper class to help decide whether to use offline mode
809811
extension HubApi {
810812
private actor NetworkStateActor {
811-
public var isConnected: Bool = false
813+
/// Assume best case connection until updated by the monitor
814+
public var isConnected: Bool = true
812815
public var isExpensive: Bool = false
813816
public var isConstrained: Bool = false
814817

@@ -822,7 +825,7 @@ extension HubApi {
822825
if ProcessInfo.processInfo.environment["CI_DISABLE_NETWORK_MONITOR"] == "1" {
823826
return false
824827
}
825-
return !isConnected || isExpensive || isConstrained
828+
return !isConnected
826829
}
827830
}
828831

0 commit comments

Comments
 (0)