Extract open URL action

This commit is contained in:
Arkadiusz Fal
2021-12-24 20:20:05 +01:00
parent 18d6000976
commit 91fa4ea2ff
6 changed files with 65 additions and 54 deletions

View File

@@ -65,7 +65,7 @@ struct ContentView: View {
}
)
#if !os(tvOS)
.onOpenURL(perform: handleOpenedURL)
.onOpenURL { OpenURLHandler(accounts: accounts, player: player).handle($0) }
.background(
EmptyView().sheet(isPresented: $navigation.presentingAddToPlaylist) {
AddToPlaylistView(video: navigation.videoToAddToPlaylist)
@@ -161,28 +161,6 @@ struct ContentView: View {
navigation.presentingWelcomeScreen = true
}
#if !os(tvOS)
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() {
player.addCurrentItemToHistory()
self.player.playNow(video, at: parser.time)
self.player.show()
}
}
}
#endif
}
struct ContentView_Previews: PreviewProvider {