Open videos via URL scheme

This commit is contained in:
Arkadiusz Fal
2021-10-24 11:16:04 +02:00
parent 8e0af22b94
commit 60c7027429
18 changed files with 230 additions and 189 deletions

View File

@@ -34,6 +34,10 @@ struct ContentView: View {
#endif
}
.onAppear(perform: configure)
.handlesExternalEvents(preferring: Set(["*"]), allowing: Set(["*"]))
.onOpenURL(perform: handleOpenedURL)
.environmentObject(accounts)
.environmentObject(instances)
.environmentObject(navigation)
@@ -113,6 +117,25 @@ struct ContentView: View {
navigation.presentingWelcomeScreen = true
}
func handleOpenedURL(_ url: URL) {
guard !accounts.current.isNil else {
return
}
let parser = VideoURLParser(url: url)
guard let id = parser.id else {
return
}
accounts.api.video(id).load().onSuccess { response in
if let video: Video = response.typedContent() {
self.player.playNow(video, at: parser.time)
self.player.presentPlayer()
}
}
}
}
struct ContentView_Previews: PreviewProvider {