SPB Git

spb/zyquo-atlas Public License

The AI-native macOS web browser — every surface, intelligent.

Swift 75.2% JavaScript 22% Shell 2% Makefile 0.9%
2.1 KB · 57 lines swift
Raw Blame History
1//2//  ProfileStore.swift3//  Zyquo Atlas4//5//  Author: Simon-Pierre Boucher6//  Mail: contact@spboucher.ai7//8//  Owns WKWebView configuration per profile: the profile's WKWebsiteDataStore9//  (persistent for normal profiles, non-persistent for private ones). All tabs10//  of a profile share cookies/storage through the same data store. Modern11//  WebKit pools and reuses content processes automatically (WKProcessPool is a12//  deprecated no-op), so no explicit pool is kept.13//1415import Foundation16import WebKit1718@MainActor19final class ProfileStore {20    static let shared = ProfileStore()2122    private var dataStores: [UUID: WKWebsiteDataStore] = [:]2324    private init() {}2526    /// The data store for a profile, created on first use. Persistent profiles27    /// get a stable on-disk store keyed by profile id (macOS 14+ identifier28    /// API); older systems and private profiles use the default/non-persistent29    /// stores.30    func dataStore(for profile: Profile) -> WKWebsiteDataStore {31        if let existing = dataStores[profile.id] { return existing }32        let store: WKWebsiteDataStore33        if profile.isPrivate {34            store = .nonPersistent()35        } else if #available(macOS 14.0, *), profile.id != Profile.defaultProfile.id {36            store = WKWebsiteDataStore(forIdentifier: profile.id)37        } else {38            store = .default()39        }40        dataStores[profile.id] = store41        return store42    }4344    /// A fresh WKWebViewConfiguration for a tab in the given profile, wired to45    /// the shared process pool and the profile's data store.46    func makeConfiguration(for profile: Profile) -> WKWebViewConfiguration {47        let config = WKWebViewConfiguration()48        config.websiteDataStore = dataStore(for: profile)49        config.defaultWebpagePreferences.allowsContentJavaScript = true50        config.preferences.isElementFullscreenEnabled = true51        // Inject the content-extraction scripts into their isolated world so52        // every tab can produce a PageContext for AI actions.53        ContentExtractor.install(into: config)54        return config55    }56}57