60 lines · 2.2 KB · Swift
RawDownload
import CodexBarCoreimport CodexBarMacroSupportimport Foundationimport SwiftUI @ProviderImplementationRegistrationstruct CursorProviderImplementation: ProviderImplementation {    let id: UsageProvider = .cursor    let supportsLoginFlow: Bool = true     @MainActor    func settingsPickers(context: ProviderSettingsContext) -> [ProviderSettingsPickerDescriptor] {        let cookieBinding = Binding(            get: { context.settings.cursorCookieSource.rawValue },            set: { raw in                context.settings.cursorCookieSource = ProviderCookieSource(rawValue: raw) ?? .auto            })        let cookieOptions = ProviderCookieSourceUI.options(            allowsOff: false,            keychainDisabled: context.settings.debugDisableKeychainAccess)         let cookieSubtitle: () -> String? = {            ProviderCookieSourceUI.subtitle(                source: context.settings.cursorCookieSource,                keychainDisabled: context.settings.debugDisableKeychainAccess,                auto: "Automatic imports browser cookies or stored sessions.",                manual: "Paste a Cookie header from a cursor.com request.",                off: "Cursor cookies are disabled.")        }         return [            ProviderSettingsPickerDescriptor(                id: "cursor-cookie-source",                title: "Cookie source",                subtitle: "Automatic imports browser cookies or stored sessions.",                dynamicSubtitle: cookieSubtitle,                binding: cookieBinding,                options: cookieOptions,                isVisible: nil,                onChange: nil,                trailingText: {                    guard let entry = CookieHeaderCache.load(provider: .cursor) else { return nil }                    let when = entry.storedAt.relativeDescription()                    return "Cached: \(entry.sourceLabel) • \(when)"                }),        ]    }     @MainActor    func settingsFields(context: ProviderSettingsContext) -> [ProviderSettingsFieldDescriptor] {        _ = context        return []    }     @MainActor    func runLoginFlow(context: ProviderLoginContext) async -> Bool {        await context.controller.runCursorLoginFlow()        return true    }}