diff --git a/Tusker/Scenes/MainSceneDelegate.swift b/Tusker/Scenes/MainSceneDelegate.swift index 984bc8b7..3379ddc8 100644 --- a/Tusker/Scenes/MainSceneDelegate.swift +++ b/Tusker/Scenes/MainSceneDelegate.swift @@ -35,7 +35,7 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDelegate window = UIWindow(windowScene: windowScene) showAppOrOnboardingUI(session: session) - if connectionOptions.urlContexts.count > 0 { + if !connectionOptions.urlContexts.isEmpty { self.scene(scene, openURLContexts: connectionOptions.urlContexts) } @@ -50,14 +50,21 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDelegate } func scene(_ scene: UIScene, openURLContexts URLContexts: Set) { - if URLContexts.count > 1 { - fatalError("Cannot open more than 1 URL") + guard let url = URLContexts.first?.url, + var components = URLComponents(url: url, resolvingAgainstBaseURL: false), + let rootViewController else { + return } - let url = URLContexts.first!.url - - if var components = URLComponents(url: url, resolvingAgainstBaseURL: false), - let rootViewController = rootViewController { + if components.host == "compose" { + if let mastodonController = window!.windowScene!.session.mastodonController { + let draft = mastodonController.createDraft() + let text = components.queryItems?.first(where: { $0.name == "text" })?.value + draft.text = text ?? "" + rootViewController.compose(editing: draft, animated: true, isDucked: false) + } + } else { + // Assume anything else is a search query components.scheme = "https" let query = components.string! rootViewController.performSearch(query: query)