yattee/Shared/OpenURLHandler.swift

42 lines
927 B
Swift
Raw Normal View History

2021-12-24 19:20:05 +00:00
import Foundation
struct OpenURLHandler {
var accounts: AccountsModel
var player: PlayerModel
func handle(_ url: URL) {
if accounts.current.isNil {
accounts.setCurrent(accounts.any)
}
guard !accounts.current.isNil else {
return
}
#if os(macOS)
2022-01-06 15:35:45 +00:00
guard url.host != Windows.player.location else {
2021-12-24 19:20:05 +00:00
return
}
#endif
let parser = VideoURLParser(url: url)
guard let id = parser.id,
id != player.currentVideo?.id
else {
return
}
#if os(macOS)
2022-01-06 15:35:45 +00:00
Windows.main.open()
2021-12-24 19:20:05 +00:00
#endif
accounts.api.video(id).load().onSuccess { response in
if let video: Video = response.typedContent() {
self.player.playNow(video, at: parser.time)
self.player.show()
}
}
}
}