Add URL handler for opening Compose window
This commit is contained in:
parent
e57ef210fd
commit
4c5da1b5a9
|
@ -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<UIOpenURLContext>) {
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue