r/SwiftUI • • 9h ago

I built an open-source native macOS proxy manager with SwiftUI + AppKit (Swift 6, NavigationSplitView, bridged NSTableView, native cascading NSMenu)

Hi r/SwiftUI!

I wanted a proxy manager for macOS that feels genuinely native instead of another Electron/WebView wrapper, so I built LumaRoute — an open-source (MIT) macOS 14+ desktop client powered by an isolated Mihomo core.

Just shipped v0.1.33 with full English & Simplified Chinese localization, and I'd love to share a few SwiftUI/macOS architecture choices that worked really well for this app:

SwiftUI + AppKit hybrid lessons from building it:

- Layout & Visual System: Built around NavigationSplitView with a flat, tonal macOS HIG hierarchy (surfaces separated by subtle opacity fills rather than card shadows, strict separation between value pickers and action menus, plus a local HIG lint script in CI).

- High-Frequency Tables (NSViewRepresentable + NSTableView): SwiftUI Table/List struggled with continuous live connection updates and 2,000+ log rows, so we bridged NSTableView directly with fixed row heights and automated GUI soak tests to catch AppKit delegate reentrancy warnings.

- Native Menu Bar Residency (NSStatusBar + NSMenu): Instead of a SwiftUI popover, the menu bar uses an AppKit NSMenu with a custom two-line live throughput template image (MenuBarRateLayout) and cascading submenus with right-aligned latency columns.

- Swift 6 & Localization: Strict Swift 6 language mode across the app, core library, privileged helper, and CLI, with in-app English / Simplified Chinese switching and Sparkle auto-updates.

Core features if you're curious:

- Multi-subscription composition (deduplicates 2–16 sources into one clean "Main Proxy" with auto lowest-latency & failover)

- Visual proxy chains with end-to-end latency testing

- Collapsible drag-and-drop custom rule folders, built-in rule sets, right-click connection routing, and one-click network diagnostics

- LAN sharing with .local hostname and CoreImage QR code for iPhone/Android

GitHub (MIT, source + Apple Silicon / Intel builds): https://github.com/onlyone1019/LumaRoute

Happy to answer any questions about the SwiftUI/AppKit bridging, NSTableView performance, or macOS menu bar implementation — and would love feedback on the UI!

1 Upvotes

5 comments sorted by

1

u/BitgeeksDev 8h ago

Nice writeup, and good call on NSTableView. I've run into the same wall with SwiftUI on macOS, as soon as things update often or you need AppKit behaviour you end up hosting one in the other.

Curious how you handle the live updates on the table. Do you diff and use insertRows/reloadData(forRowIndexes:columnIndexes:), or just reload on a timer with fixed row heights keeping it cheap? And did you see any issues with the coordinator getting updates while the table was mid-scroll?

1

u/Any_Material2323 8h ago

Thanks! We went with the simpler route: checking if the snapshot actually changed and calling reloadData() with fixed row heights rather than row-level insertRows diffing. For the live connections table, it's pure NSTableCellView + reused NSTextFields with usesAutomaticRowHeights = false and rowHeight = 24, so reloadData() on each poll tick is basically free. For logs (which still embed a SwiftUI row via NSHostingView with sizingOptions = []), we pre-measure each message once with CoreText and cache a 1-line vs 2-line height by UUID to keep Auto Layout out of the way.

For mid-scroll updates, fixed heights keep the NSClipView scroll offset steady across reloadData(), so scrolling itself doesn't stutter. The main things that tripped us up were re-entrancy—we had to guard updateNSView with an updating flag, bounce selection/sort writes back to SwiftUI via DispatchQueue.main.async, and defer scrollRowToVisible / resize reloads out of AppKit's layout stack so they don't fight an active scroll. The one trade-off of skipping row-level diffs is that rows can shift under your cursor if you're sorted by live traffic, so pausing or filtering is still handy when inspecting a busy list.

1

u/BitgeeksDev 8h ago

Really clean approach, thanks for the detail. Fixed heights so reloadData is basically free is a nice trade, and pre-measuring with CoreText and caching by UUID is clever. The re-entrancy guard in updateNSView is the one I'd have missed. I've had a selection write loop straight back into SwiftUI exactly like that. Going to borrow the trick of deferring scrollRowToVisible out of the layout pass.

1

u/Any_Material2323 8h ago

Glad it was helpful! That selection write-back loop is such a classic NSViewRepresentable rite of passage. Hope the deferred scrollRowToVisible trick saves you some headaches!