Skip to content

Conversation

@ooii
Copy link

@ooii ooii commented Jan 18, 2026

Problem

The app was incorrectly entering offline mode even when server connections succeeded. Users would see the offline mode UI despite having working network connectivity to their server.

Root Cause

In TabRouterViewModel.swift, the loadLibraries() function had inverted boolean logic:

// Before (broken):
let allConnectionsUnavailable = await withTaskGroup(of: Bool.self) { group in
    // ... tasks return true on success, false on failure
    return await group.reduce(true) { $0 && $1 }
}

if allConnectionsUnavailable {
    await OfflineMode.shared.setEnabled(true)
}

The issue:

  • reduce(true) { $0 && $1 } returns true only when ALL connections succeed
  • But the variable was named allConnectionsUnavailable and triggered offline mode when true
  • This caused the app to go offline when connections worked, and stay online when they failed

Solution

// After (fixed):
let anyConnectionSucceeded = await withTaskGroup(of: Bool.self) { group in
    // ... tasks return true on success, false on failure
    return await group.reduce(false) { $0 || $1 }
}

if !anyConnectionSucceeded {
    await OfflineMode.shared.setEnabled(true)
}

Changes:

  • Renamed variable to anyConnectionSucceeded for clarity
  • Changed reduction to OR (||) with initial value false
  • Now correctly enables offline mode only when no connection succeeded

Test Plan

  • Launch app with valid server connection → should stay online and show library
  • Launch app with no network → should enter offline mode
  • Launch app with invalid server URL → should enter offline mode

🤖 Generated with Claude Code

The app was incorrectly entering offline mode even when connections
succeeded. The issue was in loadLibraries() where:

- reduce(true) { $0 && $1 } returns true only when ALL connections succeed
- But the variable was named 'allConnectionsUnavailable' and used to
  enable offline mode when true

This caused the app to go offline when connections worked, and stay
online when they failed - exactly backwards.

Fix: Rename to 'anyConnectionSucceeded', use OR reduction, and only
enable offline mode when no connection succeeded.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant