From 346f8504824afe0091d03bc89e3c4274e5a89adc Mon Sep 17 00:00:00 2001 From: ZachNagengast Date: Mon, 3 Nov 2025 15:04:36 -0800 Subject: [PATCH 1/2] Assume connected by default until updated by network monitor --- Sources/Hub/HubApi.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/Hub/HubApi.swift b/Sources/Hub/HubApi.swift index e89dab0..276f5ff 100644 --- a/Sources/Hub/HubApi.swift +++ b/Sources/Hub/HubApi.swift @@ -575,8 +575,10 @@ public extension HubApi { .appendingPathComponent(".cache") .appendingPathComponent("huggingface") .appendingPathComponent("download") + + let shouldUseOfflineMode = await NetworkMonitor.shared.state.shouldUseOfflineMode() - if await NetworkMonitor.shared.state.shouldUseOfflineMode() || useOfflineMode == true { + if useOfflineMode ?? shouldUseOfflineMode { if !FileManager.default.fileExists(atPath: repoDestination.path) { throw EnvironmentError.offlineModeError(String(localized: "Repository not available locally")) } @@ -808,7 +810,8 @@ public extension HubApi { /// Network monitor helper class to help decide whether to use offline mode extension HubApi { private actor NetworkStateActor { - public var isConnected: Bool = false + /// Assume best case connection until updated by the monitor + public var isConnected: Bool = true public var isExpensive: Bool = false public var isConstrained: Bool = false @@ -822,7 +825,7 @@ extension HubApi { if ProcessInfo.processInfo.environment["CI_DISABLE_NETWORK_MONITOR"] == "1" { return false } - return !isConnected || isExpensive || isConstrained + return !isConnected } } From c365e888851b9463ef1f41caa66c656451941d36 Mon Sep 17 00:00:00 2001 From: ZachNagengast Date: Mon, 3 Nov 2025 15:46:14 -0800 Subject: [PATCH 2/2] Format --- Sources/Hub/HubApi.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Hub/HubApi.swift b/Sources/Hub/HubApi.swift index 276f5ff..167aa8d 100644 --- a/Sources/Hub/HubApi.swift +++ b/Sources/Hub/HubApi.swift @@ -575,7 +575,7 @@ public extension HubApi { .appendingPathComponent(".cache") .appendingPathComponent("huggingface") .appendingPathComponent("download") - + let shouldUseOfflineMode = await NetworkMonitor.shared.state.shouldUseOfflineMode() if useOfflineMode ?? shouldUseOfflineMode {