mirror of
https://github.com/yattee/yattee.git
synced 2024-12-13 05:40:32 +05:30
Fix crashes
This commit is contained in:
parent
6594d5ba95
commit
18cbbd3c90
@ -42,7 +42,7 @@ final class CommentsModel: ObservableObject {
|
||||
|
||||
firstPage = page.isNil || page!.isEmpty
|
||||
|
||||
player.playerAPI(video).comments(video.videoID, page: page)?
|
||||
player.playerAPI(video)?.comments(video.videoID, page: page)?
|
||||
.load()
|
||||
.onSuccess { [weak self] response in
|
||||
if let page: CommentsPage = response.typedContent() {
|
||||
|
@ -438,6 +438,7 @@ final class MPVClient: ObservableObject {
|
||||
}
|
||||
|
||||
private func setString(_ name: String, _ value: String) {
|
||||
guard mpv != nil else { return }
|
||||
mpv_set_property_string(mpv, name, value)
|
||||
}
|
||||
|
||||
|
@ -724,7 +724,7 @@ final class PlayerModel: ObservableObject {
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 3) { [weak self] in
|
||||
guard let self else { return }
|
||||
self.playerAPI(item.video).loadDetails(item, completionHandler: { newItem in
|
||||
self.playerAPI(item.video)?.loadDetails(item, completionHandler: { newItem in
|
||||
guard newItem.videoID == self.autoplayItem?.videoID else { return }
|
||||
self.autoplayItem = newItem
|
||||
self.updateRemoteCommandCenter()
|
||||
|
@ -100,7 +100,7 @@ extension PlayerModel {
|
||||
InstancesModel.shared.forPlayer ?? accounts.current?.instance ?? InstancesModel.shared.all.first
|
||||
}
|
||||
|
||||
func playerAPI(_ video: Video) -> VideosAPI! {
|
||||
func playerAPI(_ video: Video) -> VideosAPI? {
|
||||
guard let url = video.instanceURL else { return accounts.api }
|
||||
switch video.app {
|
||||
case .local:
|
||||
@ -181,7 +181,7 @@ extension PlayerModel {
|
||||
|
||||
let playTime = currentItem.shouldRestartPlaying ? CMTime.zero : time
|
||||
guard let video = newItem.video else { return }
|
||||
playerAPI(video).loadDetails(currentItem, failureHandler: { self.videoLoadFailureHandler($0, video: self.currentItem.video) }) { newItem in
|
||||
playerAPI(video)?.loadDetails(currentItem, failureHandler: { self.videoLoadFailureHandler($0, video: video) }) { newItem in
|
||||
self.playItem(newItem, at: playTime)
|
||||
}
|
||||
}
|
||||
@ -228,7 +228,7 @@ extension PlayerModel {
|
||||
}
|
||||
|
||||
if loadDetails {
|
||||
playerAPI(item.video).loadDetails(item, failureHandler: { self.videoLoadFailureHandler($0, video: video) }) { [weak self] newItem in
|
||||
playerAPI(item.video)?.loadDetails(item, failureHandler: { self.videoLoadFailureHandler($0, video: video) }) { [weak self] newItem in
|
||||
guard let self else { return }
|
||||
videoDetailsLoadHandler(newItem.video, newItem)
|
||||
|
||||
|
@ -20,8 +20,9 @@ extension PlayerModel {
|
||||
|
||||
guard let playerInstance else { return }
|
||||
|
||||
guard let api = playerAPI(video) else { return }
|
||||
logger.info("loading streams from \(playerInstance.description)")
|
||||
fetchStreams(playerAPI(video).video(video.videoID), instance: playerInstance, video: video, onCompletion: onCompletion)
|
||||
fetchStreams(api.video(video.videoID), instance: playerInstance, video: video, onCompletion: onCompletion)
|
||||
}
|
||||
|
||||
private func fetchStreams(
|
||||
|
@ -99,10 +99,11 @@ struct OpenURLHandler {
|
||||
Windows.main.open()
|
||||
#endif
|
||||
|
||||
player.videoBeingOpened = Video(app: accounts.current.app!, videoID: id)
|
||||
let video = Video(app: accounts.current.app!, videoID: id)
|
||||
player.videoBeingOpened = video
|
||||
|
||||
player
|
||||
.playerAPI(player.videoBeingOpened!)
|
||||
.playerAPI(video)?
|
||||
.video(id)
|
||||
.load()
|
||||
.onSuccess { response in
|
||||
|
@ -40,7 +40,9 @@ struct WatchView: View {
|
||||
if finished, let watch {
|
||||
PlayerModel.shared.removeWatch(watch)
|
||||
} else {
|
||||
Watch.markAsWatched(videoID: watch?.videoID ?? videoID, account: AccountsModel.shared.current, duration: watch?.videoDuration ?? duration, context: backgroundContext)
|
||||
if let account = AccountsModel.shared.current {
|
||||
Watch.markAsWatched(videoID: watch?.videoID ?? videoID, account: account, duration: watch?.videoDuration ?? duration, context: backgroundContext)
|
||||
}
|
||||
}
|
||||
|
||||
FeedModel.shared.calculateUnwatchedFeed()
|
||||
|
@ -47,7 +47,7 @@ struct ShareButton<LabelView: View>: View {
|
||||
private var instanceActions: some View {
|
||||
Group {
|
||||
Button(labelForShareURL(accounts.app.name)) {
|
||||
if let url = player.playerAPI(contentItem.video).shareURL(contentItem) {
|
||||
if let url = player.playerAPI(contentItem.video)?.shareURL(contentItem) {
|
||||
shareAction(url)
|
||||
} else {
|
||||
navigation.presentAlert(
|
||||
@ -59,8 +59,11 @@ struct ShareButton<LabelView: View>: View {
|
||||
|
||||
if contentItemIsPlayerCurrentVideo {
|
||||
Button(labelForShareURL(accounts.app.name, withTime: true)) {
|
||||
if let video = player.videoForDisplay,
|
||||
let api = player.playerAPI(video)
|
||||
{
|
||||
shareAction(
|
||||
player.playerAPI(player.currentVideo!).shareURL(
|
||||
api.shareURL(
|
||||
contentItem,
|
||||
time: player.backend.currentTime
|
||||
)!
|
||||
@ -69,6 +72,7 @@ struct ShareButton<LabelView: View>: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var youtubeActions: some View {
|
||||
Group {
|
||||
@ -93,7 +97,7 @@ struct ShareButton<LabelView: View>: View {
|
||||
}
|
||||
|
||||
private var contentItemIsPlayerCurrentVideo: Bool {
|
||||
contentItem.contentType == .video && contentItem.video?.videoID == player.currentVideo?.videoID
|
||||
contentItem.contentType == .video && contentItem.video?.videoID == player.videoForDisplay?.videoID
|
||||
}
|
||||
|
||||
@ViewBuilder private var remoteURLAction: some View {
|
||||
|
Loading…
Reference in New Issue
Block a user