r/iosdev • u/ahstanin • Oct 23 '26
GitHub Building an iOS virtual desktop with iPhone Duo foldable hinge support and embedded Tor: Architecture and lessons learned
Hi everyone,
We recently shipped an update adding foldable iPhone Duo support to StealthOS, our sandboxed virtual desktop and privacy browser app on iOS. Since there is limited documentation out there for handling foldables and embedding Tor reproducibly on Apple platforms, I wanted to share some notes on our architecture, windowing system, and network routing.
1. Foldable Window Management & Hinge Awareness (iPhone Duo)
Supporting both the single cover display and the dual-screen inner layout required designing an internal window manager rather than relying solely on standard UIKit/SwiftUI navigation stacks.
- Hinge Detection: We query the device layout metrics to identify the physical occlusion boundary between the left and right halves when unfolded.
- Snapping & Spanning: Windows calculate their bounds based on layout states. A window can either snap to the left half, snap to the right half, or span the full inner resolution. When snapping to either side, window borders pad away from the hinge seam to prevent UI clipping.
- State Continuity Across Folds: When folding or unfolding occurs, the root layout transitions between display modes. Rather than recreating view hierarchies, running windows maintain their existing state machines, active scroll offsets, and subprocess sessions. Viewports recalculate frame geometry while preserving active responders.
2. Embedded Tor and Network Leak Prevention
Apple's platform sandbox presents unique challenges when embedding Tor:
- Reproducible Build: The Tor daemon is compiled for iOS as a static C library from verified sources, packaged reproducibly so developers can verify byte-for-byte outputs. We open-sourced this wrapper library as TorClient.
- Single-Route Routing: Browsers and web views can leak WebRTC, DNS lookups, or local network discovery packets. We route all network activity generated by the internal environment through a unified local SOCKS5 router that carries browser requests, domain verification (WHOIS/RDAP), and download tasks.
- Kill Switch: If the Tor circuit drops or the proxy fails, the socket handler halts traffic immediately rather than falling back to the default network interface.
3. Hardware-Backed Keys and Duress Erasure
- Key Derivation: Vault items and snapshots use AES-256-GCM. Keys are derived from the user password combined with a Secure Enclave-protected secret.
- Emergency Wipe: If the user enters an emergency duress password at the unlock screen, the app immediately purges encryption keys from memory, zeroes out local SQLite tables and cache directories, and drops the keychain item. Face ID and Touch ID are disabled at the keychain access level so biometric unlock cannot bypass a wipe state.
4. Open Source Libraries
We open-sourced the networking components for other developers building peer-to-peer or privacy-focused iOS applications:
- TorClient (iOS): Reproducible Tor client build for iOS: https://github.com/Olib-AI/TorClient
- StealthRelay (Rust): Self-hosted relay with a web client: https://github.com/Olib-AI/StealthRelay
- ConnectionPool: P2P networking library for local Bluetooth/Wi-Fi mesh and remote relays: https://github.com/Olib-AI/ConnectionPool
- PoolChat: End-to-end encrypted messaging engine: https://github.com/Olib-AI/PoolChat
For anyone working on foldable layouts, multi-window UIKit abstractions, or networking security on iOS, happy to discuss the implementation details or answer any questions.
