2021-12-25 00:50:05 +05:30
|
|
|
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 21:05:45 +05:30
|
|
|
guard url.host != Windows.player.location else {
|
2021-12-25 00:50:05 +05:30
|
|
|
return
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
let parser = VideoURLParser(url: url)
|
|
|
|
|
|
|
|
guard let id = parser.id,
|
|
|
|
id != player.currentVideo?.id
|
|
|
|
else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
#if os(macOS)
|
2022-01-06 21:05:45 +05:30
|
|
|
Windows.main.open()
|
2021-12-25 00:50:05 +05:30
|
|
|
#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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|