1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30

Fix crashes

This commit is contained in:
Arkadiusz Fal 2022-12-21 18:13:41 +01:00
parent 6594d5ba95
commit 18cbbd3c90
8 changed files with 26 additions and 17 deletions

View File

@ -42,7 +42,7 @@ final class CommentsModel: ObservableObject {
firstPage = page.isNil || page!.isEmpty firstPage = page.isNil || page!.isEmpty
player.playerAPI(video).comments(video.videoID, page: page)? player.playerAPI(video)?.comments(video.videoID, page: page)?
.load() .load()
.onSuccess { [weak self] response in .onSuccess { [weak self] response in
if let page: CommentsPage = response.typedContent() { if let page: CommentsPage = response.typedContent() {

View File

@ -438,6 +438,7 @@ final class MPVClient: ObservableObject {
} }
private func setString(_ name: String, _ value: String) { private func setString(_ name: String, _ value: String) {
guard mpv != nil else { return }
mpv_set_property_string(mpv, name, value) mpv_set_property_string(mpv, name, value)
} }

View File

@ -724,7 +724,7 @@ final class PlayerModel: ObservableObject {
DispatchQueue.main.asyncAfter(deadline: .now() + 3) { [weak self] in DispatchQueue.main.asyncAfter(deadline: .now() + 3) { [weak self] in
guard let self else { return } 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 } guard newItem.videoID == self.autoplayItem?.videoID else { return }
self.autoplayItem = newItem self.autoplayItem = newItem
self.updateRemoteCommandCenter() self.updateRemoteCommandCenter()

View File

@ -100,7 +100,7 @@ extension PlayerModel {
InstancesModel.shared.forPlayer ?? accounts.current?.instance ?? InstancesModel.shared.all.first 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 } guard let url = video.instanceURL else { return accounts.api }
switch video.app { switch video.app {
case .local: case .local:
@ -181,7 +181,7 @@ extension PlayerModel {
let playTime = currentItem.shouldRestartPlaying ? CMTime.zero : time let playTime = currentItem.shouldRestartPlaying ? CMTime.zero : time
guard let video = newItem.video else { return } 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) self.playItem(newItem, at: playTime)
} }
} }
@ -228,7 +228,7 @@ extension PlayerModel {
} }
if loadDetails { 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 } guard let self else { return }
videoDetailsLoadHandler(newItem.video, newItem) videoDetailsLoadHandler(newItem.video, newItem)

View File

@ -20,8 +20,9 @@ extension PlayerModel {
guard let playerInstance else { return } guard let playerInstance else { return }
guard let api = playerAPI(video) else { return }
logger.info("loading streams from \(playerInstance.description)") 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( private func fetchStreams(

View File

@ -99,10 +99,11 @@ struct OpenURLHandler {
Windows.main.open() Windows.main.open()
#endif #endif
player.videoBeingOpened = Video(app: accounts.current.app!, videoID: id) let video = Video(app: accounts.current.app!, videoID: id)
player.videoBeingOpened = video
player player
.playerAPI(player.videoBeingOpened!) .playerAPI(video)?
.video(id) .video(id)
.load() .load()
.onSuccess { response in .onSuccess { response in

View File

@ -40,7 +40,9 @@ struct WatchView: View {
if finished, let watch { if finished, let watch {
PlayerModel.shared.removeWatch(watch) PlayerModel.shared.removeWatch(watch)
} else { } 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() FeedModel.shared.calculateUnwatchedFeed()

View File

@ -47,7 +47,7 @@ struct ShareButton<LabelView: View>: View {
private var instanceActions: some View { private var instanceActions: some View {
Group { Group {
Button(labelForShareURL(accounts.app.name)) { 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) shareAction(url)
} else { } else {
navigation.presentAlert( navigation.presentAlert(
@ -59,12 +59,16 @@ struct ShareButton<LabelView: View>: View {
if contentItemIsPlayerCurrentVideo { if contentItemIsPlayerCurrentVideo {
Button(labelForShareURL(accounts.app.name, withTime: true)) { Button(labelForShareURL(accounts.app.name, withTime: true)) {
shareAction( if let video = player.videoForDisplay,
player.playerAPI(player.currentVideo!).shareURL( let api = player.playerAPI(video)
contentItem, {
time: player.backend.currentTime shareAction(
)! api.shareURL(
) contentItem,
time: player.backend.currentTime
)!
)
}
} }
} }
} }
@ -93,7 +97,7 @@ struct ShareButton<LabelView: View>: View {
} }
private var contentItemIsPlayerCurrentVideo: Bool { 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 { @ViewBuilder private var remoteURLAction: some View {