import SwiftUI import UIKit /// Zielbildschirm, der über Home-Screen-Shortcut oder URL angesprungen wird. enum Route: String { case checkin case checkout } final class Router: ObservableObject { @Published var route: Route? func handle(shortcut type: String) { if type.hasSuffix("checkin") { route = .checkin } if type.hasSuffix("checkout") { route = .checkout } } /// projectgood://checkin bzw. projectgood://checkout func handle(url: URL) { guard url.scheme == "projectgood" else { return } let target = (url.host ?? url.path.replacingOccurrences(of: "/", with: "")).lowercased() if let route = Route(rawValue: target) { self.route = route } } } @main struct ProjectGoodApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate @StateObject private var session = Session.shared @StateObject private var router = Router() var body: some Scene { WindowGroup { RootView() .environmentObject(session) .environmentObject(router) .onOpenURL { router.handle(url: $0) } .onAppear { if let type = AppDelegate.pendingShortcut { router.handle(shortcut: type) AppDelegate.pendingShortcut = nil } } .onReceive(NotificationCenter.default.publisher(for: AppDelegate.shortcutNotification)) { note in if let type = note.object as? String { router.handle(shortcut: type) } } } } } /// Nimmt Home-Screen-Quick-Actions entgegen (auch beim Kaltstart). final class AppDelegate: NSObject, UIApplicationDelegate { static let shortcutNotification = Notification.Name("ProjectGoodShortcut") static var pendingShortcut: String? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { if let item = launchOptions?[.shortcutItem] as? UIApplicationShortcutItem { AppDelegate.pendingShortcut = item.type } return true } // Bewusst die Variante mit Completion-Handler: Bei der async-Fassung muesste // das nicht-Sendable UIApplicationShortcutItem ueber eine Actor-Grenze // gereicht werden (Warnung heute, Fehler im Swift-6-Sprachmodus). func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { NotificationCenter.default.post(name: AppDelegate.shortcutNotification, object: shortcutItem.type) completionHandler(true) } }