mirror of
https://github.com/samsonjs/vibetunnel.git
synced 2026-04-20 13:45:54 +00:00
- Change default server port from 800 to 4020 to avoid privileged port restrictions - Rename TunnelServerDemo.swift to TunnelServer.swift for clarity - Remove redundant TunnelServerExample.swift - Update tty-fwd binary - Add SettingsWindowDelegate for improved window management - Update UI components and session monitoring - Add modern Swift refactoring documentation The server was failing to start because it was trying to bind to port 800, which requires root privileges on macOS. Port 4020 is now used as the default.
3.5 KiB
3.5 KiB
Modern Swift Refactoring Summary
This document summarizes the modernization changes made to the VibeTunnel codebase to align with modern Swift best practices as outlined in modern-swift.md.
Key Changes
1. Converted @ObservableObject to @Observable
-
SessionMonitor.swift: Converted from
@ObservableObjectwith@Publishedproperties to@Observableclass- Removed
import Combine - Replaced
@Publishedwith regular properties - Changed from
ObservableObjectto@Observable
- Removed
-
TunnelServerDemo.swift: Converted from
@ObservableObjectto@Observable- Removed
import Combine - Simplified property declarations
- Removed
-
SparkleViewModel: Converted stub implementation to use
@Observable
2. Replaced Combine with Async/Await
-
SessionMonitor.swift:
- Replaced
TimerwithTaskfor periodic monitoring - Used
Task.sleep(for:)instead of Timer callbacks - Eliminated nested
Task { }blocks
- Replaced
-
TunnelClient.swift:
- Removed
PassthroughSubjectfrom WebSocket implementation - Replaced with
AsyncStream<WSMessage>for message handling - Updated delegate methods to use
continuation.yield()instead ofsubject.send()
- Removed
3. Simplified State Management
-
VibeTunnelApp.swift:
- Changed
@StateObjectto@Statefor SessionMonitor - Updated
.environmentObject()to.environment()for modern environment injection
- Changed
-
MenuBarView.swift:
- Changed
@EnvironmentObjectto@Environment(SessionMonitor.self)
- Changed
-
SettingsView.swift:
- Removed
ServerObserverViewModel completely - Moved server state directly into view as
@State private var httpServer - Simplified server state access with computed properties
- Removed
4. Modernized Async Operations
-
VibeTunnelApp.swift:
- Replaced
DispatchQueue.main.asyncAfterwithTask.sleep(for:) - Updated all
Task.sleep(nanoseconds:)toTask.sleep(for:)with Duration
- Replaced
-
SettingsView.swift:
- Replaced
.onAppearwith.taskfor async initialization - Modernized Task.sleep usage throughout
- Replaced
5. Removed Unnecessary Abstractions
- Eliminated
ServerObserverclass - moved logic directly into views - Removed Combine imports where no longer needed
- Simplified state ownership by keeping it close to where it's used
6. Updated Error Handling
- Maintained proper async/await error handling with try/catch
- Removed completion handler patterns where applicable
- Simplified error state management
Benefits Achieved
- Reduced Dependencies: Removed Combine dependency from most files
- Simpler Code: Eliminated unnecessary ViewModels and abstractions
- Better Performance: Native SwiftUI state management with @Observable
- Modern Patterns: Consistent use of async/await throughout
- Cleaner Architecture: State lives closer to where it's used
Migration Notes
- All @Observable classes require iOS 17+ / macOS 14+
- AsyncStream provides a more natural API than Combine subjects
- Task-based monitoring is more efficient than Timer-based
- SwiftUI's built-in state management eliminates need for custom ViewModels
Files Modified
/VibeTunnel/Core/Services/SessionMonitor.swift/VibeTunnel/Core/Services/TunnelClient.swift/VibeTunnel/Core/Services/TunnelServerDemo.swift/VibeTunnel/Core/Services/SparkleUpdaterManager.swift/VibeTunnel/VibeTunnelApp.swift/VibeTunnel/Views/MenuBarView.swift/VibeTunnel/SettingsView.swift
All changes follow the principles outlined in the Modern Swift guidelines, embracing SwiftUI's native patterns and avoiding unnecessary complexity.