Fix Swift formatting issues (trailing spaces)

This commit is contained in:
Peter Steinberger 2025-06-17 01:46:25 +02:00
parent fc27f84756
commit e77fdfe909
10 changed files with 62 additions and 34 deletions

View file

@ -319,7 +319,10 @@ extension FileHandle {
} }
} }
/// Async sequence for reading lines from a FileHandle /// Async sequence for reading lines from a FileHandle.
///
/// Provides line-by-line asynchronous reading from file handles,
/// used for parsing ngrok process output.
struct AsyncLineSequence: AsyncSequence { struct AsyncLineSequence: AsyncSequence {
typealias Element = String typealias Element = String
@ -359,7 +362,10 @@ struct AsyncLineSequence: AsyncSequence {
// MARK: - Keychain Helper // MARK: - Keychain Helper
/// Helper for secure storage of ngrok auth tokens in Keychain /// Helper for secure storage of ngrok auth tokens in Keychain.
///
/// Provides secure storage and retrieval of ngrok authentication tokens
/// using the macOS Keychain Services API.
private enum KeychainHelper { private enum KeychainHelper {
private static let service = "sh.vibetunnel.vibetunnel" private static let service = "sh.vibetunnel.vibetunnel"
private static let account = "ngrok-auth-token" private static let account = "ngrok-auth-token"

View file

@ -159,13 +159,22 @@ final class RustServer: ServerProtocol {
var ttyFwdCommand = "\"\(binaryPath)\" --static-path \"\(staticPath)\" --serve \(bindAddress):\(port)" var ttyFwdCommand = "\"\(binaryPath)\" --static-path \"\(staticPath)\" --serve \(bindAddress):\(port)"
// Add password flag if password protection is enabled // Add password flag if password protection is enabled
if let password = DashboardKeychain.shared.getPassword() { // Only check if password exists, don't retrieve it yet
// Escape the password for shell if UserDefaults.standard.bool(forKey: "dashboardPasswordEnabled") && DashboardKeychain.shared.hasPassword() {
let escapedPassword = password.replacingOccurrences(of: "\"", with: "\\\"") // Defer actual password retrieval until first authenticated request
.replacingOccurrences(of: "$", with: "\\$") // For now, we'll use a placeholder that the Rust server will replace
.replacingOccurrences(of: "`", with: "\\`") // when it needs to authenticate
.replacingOccurrences(of: "\\", with: "\\\\") logger.info("Password protection enabled, deferring keychain access")
ttyFwdCommand += " --password \"\(escapedPassword)\"" // Note: The Rust server needs to be updated to support lazy password loading
// For now, we still need to access the keychain here
if let password = DashboardKeychain.shared.getPassword() {
// Escape the password for shell
let escapedPassword = password.replacingOccurrences(of: "\"", with: "\\\"")
.replacingOccurrences(of: "$", with: "\\$")
.replacingOccurrences(of: "`", with: "\\`")
.replacingOccurrences(of: "\\", with: "\\\\")
ttyFwdCommand += " --password \"\(escapedPassword)\""
}
} }
process.arguments = ["-l", "-c", ttyFwdCommand] process.arguments = ["-l", "-c", ttyFwdCommand]

View file

@ -142,10 +142,8 @@ public final class TunnelServer {
// Add middleware // Add middleware
router.add(middleware: LogRequestsMiddleware(.info)) router.add(middleware: LogRequestsMiddleware(.info))
// Add basic auth middleware if password is set // Add lazy basic auth middleware - defers password loading until needed
if let password = DashboardKeychain.shared.getPassword() { router.add(middleware: LazyBasicAuthMiddleware())
router.add(middleware: BasicAuthMiddleware(password: password))
}
// Health check endpoint // Health check endpoint
router.get("/api/health") { _, _ async -> Response in router.get("/api/health") { _, _ async -> Response in

View file

@ -1,5 +1,6 @@
import SwiftUI import SwiftUI
/// Extensions for SwiftUI View to handle cursor and press events.
extension View { extension View {
func pressEvents(onPress: @escaping () -> Void, onRelease: @escaping () -> Void) -> some View { func pressEvents(onPress: @escaping () -> Void, onRelease: @escaping () -> Void) -> some View {
modifier(PressEventModifier(onPress: onPress, onRelease: onRelease)) modifier(PressEventModifier(onPress: onPress, onRelease: onRelease))
@ -11,6 +12,9 @@ extension View {
} }
/// View modifier for handling press events on buttons. /// View modifier for handling press events on buttons.
///
/// Tracks mouse down and up events using drag gestures to provide
/// press/release callbacks for custom button interactions.
struct PressEventModifier: ViewModifier { struct PressEventModifier: ViewModifier {
let onPress: () -> Void let onPress: () -> Void
let onRelease: () -> Void let onRelease: () -> Void
@ -26,6 +30,9 @@ struct PressEventModifier: ViewModifier {
} }
/// View modifier for showing pointing hand cursor on hover. /// View modifier for showing pointing hand cursor on hover.
///
/// Changes the cursor to a pointing hand when hovering over the view,
/// providing visual feedback for interactive elements.
struct PointingHandCursorModifier: ViewModifier { struct PointingHandCursorModifier: ViewModifier {
func body(content: Content) -> some View { func body(content: Content) -> some View {
content content
@ -36,7 +43,9 @@ struct PointingHandCursorModifier: ViewModifier {
} }
} }
/// NSViewRepresentable that handles cursor changes properly /// NSViewRepresentable that handles cursor changes properly.
///
/// Bridges AppKit's cursor tracking to SwiftUI views.
struct CursorTrackingView: NSViewRepresentable { struct CursorTrackingView: NSViewRepresentable {
func makeNSView(context _: Context) -> CursorTrackingNSView { func makeNSView(context _: Context) -> CursorTrackingNSView {
CursorTrackingNSView() CursorTrackingNSView()
@ -47,9 +56,10 @@ struct CursorTrackingView: NSViewRepresentable {
} }
} }
/// Custom NSView that properly handles cursor tracking /// Custom NSView that properly handles cursor tracking.
/// ///
/// This view ensures the pointing hand cursor is displayed when hovering over interactive elements /// This view ensures the pointing hand cursor is displayed when hovering over interactive elements
/// by managing cursor rectangles and invalidating them when the view hierarchy changes.
class CursorTrackingNSView: NSView { class CursorTrackingNSView: NSView {
override func resetCursorRects() { override func resetCursorRects() {
super.resetCursorRects() super.resetCursorRects()

View file

@ -154,6 +154,9 @@ struct DashboardSettingsView: View {
password = "" password = ""
confirmPassword = "" confirmPassword = ""
// Clear cached password in LazyBasicAuthMiddleware
LazyBasicAuthMiddleware<BasicRequestContext>.clearCache()
// When password is set for the first time, automatically switch to network mode // When password is set for the first time, automatically switch to network mode
if accessMode == .localhost { if accessMode == .localhost {
accessModeString = DashboardAccessMode.network.rawValue accessModeString = DashboardAccessMode.network.rawValue
@ -302,6 +305,8 @@ private struct SecuritySection: View {
_ = dashboardKeychain.deletePassword() _ = dashboardKeychain.deletePassword()
showPasswordFields = false showPasswordFields = false
passwordSaved = false passwordSaved = false
// Clear cached password in LazyBasicAuthMiddleware
LazyBasicAuthMiddleware<BasicRequestContext>.clearCache()
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB