forked from shadowfacts/Tusker
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)
|
window = UIWindow(windowScene: windowScene)
|
||||||
|
|
||||||
showAppOrOnboardingUI(session: session)
|
showAppOrOnboardingUI(session: session)
|
||||||
if connectionOptions.urlContexts.count > 0 {
|
if !connectionOptions.urlContexts.isEmpty {
|
||||||
self.scene(scene, openURLContexts: connectionOptions.urlContexts)
|
self.scene(scene, openURLContexts: connectionOptions.urlContexts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,14 +50,21 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDelegate
|
||||||
}
|
}
|
||||||
|
|
||||||
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
|
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
|
||||||
if URLContexts.count > 1 {
|
guard let url = URLContexts.first?.url,
|
||||||
fatalError("Cannot open more than 1 URL")
|
var components = URLComponents(url: url, resolvingAgainstBaseURL: false),
|
||||||
|
let rootViewController else {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let url = URLContexts.first!.url
|
if components.host == "compose" {
|
||||||
|
if let mastodonController = window!.windowScene!.session.mastodonController {
|
||||||
if var components = URLComponents(url: url, resolvingAgainstBaseURL: false),
|
let draft = mastodonController.createDraft()
|
||||||
let rootViewController = rootViewController {
|
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"
|
components.scheme = "https"
|
||||||
let query = components.string!
|
let query = components.string!
|
||||||
rootViewController.performSearch(query: query)
|
rootViewController.performSearch(query: query)
|
||||||
|
|
Loading…
Reference in New Issue