// // ProfileStore.swift // Zyquo Atlas // // Author: Simon-Pierre Boucher // Mail: contact@spboucher.ai // // Owns WKWebView configuration per profile: the profile's WKWebsiteDataStore // (persistent for normal profiles, non-persistent for private ones). All tabs // of a profile share cookies/storage through the same data store. Modern // WebKit pools and reuses content processes automatically (WKProcessPool is a // deprecated no-op), so no explicit pool is kept. // import Foundation import WebKit @MainActor final class ProfileStore { static let shared = ProfileStore() private var dataStores: [UUID: WKWebsiteDataStore] = [:] private init() {} /// The data store for a profile, created on first use. Persistent profiles /// get a stable on-disk store keyed by profile id (macOS 14+ identifier /// API); older systems and private profiles use the default/non-persistent /// stores. func dataStore(for profile: Profile) -> WKWebsiteDataStore { if let existing = dataStores[profile.id] { return existing } let store: WKWebsiteDataStore if profile.isPrivate { store = .nonPersistent() } else if #available(macOS 14.0, *), profile.id != Profile.defaultProfile.id { store = WKWebsiteDataStore(forIdentifier: profile.id) } else { store = .default() } dataStores[profile.id] = store return store } /// A fresh WKWebViewConfiguration for a tab in the given profile, wired to /// the shared process pool and the profile's data store. func makeConfiguration(for profile: Profile) -> WKWebViewConfiguration { let config = WKWebViewConfiguration() config.websiteDataStore = dataStore(for: profile) config.defaultWebpagePreferences.allowsContentJavaScript = true config.preferences.isElementFullscreenEnabled = true // Inject the content-extraction scripts into their isolated world so // every tab can produce a PageContext for AI actions. ContentExtractor.install(into: config) return config } }