import RastrilloApple import SwiftUI /// Another app asking to open Base: `works.oficina.base://open`, or /// `…://open?path=/a/page`, handled by the kit's NativeConnection (its /// `onOpen`, Task 1), which holds the path to a page on Base's own origin. /// Base comes forward with Ask; a page Base doesn't draw natively (Store, /// People) opens on the web. @MainActor public final class BaseOpenURL { public static let scheme = "works.oficina.base" private let connection: NativeConnection public init(defaults: UserDefaults = UserDefaults(suiteName: "works.oficina.base.open") ?? .standard, showAsk: @escaping @MainActor () -> Void, openWeb: @escaping @MainActor (String) -> Void) { connection = NativeConnection(defaultServer: "https://base.oficina.works", callbackScheme: Self.scheme, defaults: defaults) connection.onOpen = { path in guard let path, path != "/", path != "/ask" else { showAsk(); return } openWeb(path) } } /// Hand every URL the app is opened with here; anything else is ignored. public func handle(_ url: URL) { connection.handleOpenURL(url) } }