mirror of
https://github.com/yattee/yattee.git
synced 2024-11-10 08:18:19 +00:00
61a4951831
- player is now a separate window on macOS - add setting to disable pause when player is closed (fixes #40) - add PiP settings: * Close PiP when starting playing other video * Close PiP when player is opened * Close PiP and open player when application enters foreground (iOS/tvOS) (fixes #37) - new player placeholder when in PiP, context menu with exit option
152 lines
4.2 KiB
Swift
152 lines
4.2 KiB
Swift
import Defaults
|
|
import SwiftUI
|
|
|
|
struct VideoContextMenuView: View {
|
|
let video: Video
|
|
|
|
@Binding var playerNavigationLinkActive: Bool
|
|
|
|
@Environment(\.inNavigationView) private var inNavigationView
|
|
@Environment(\.inChannelView) private var inChannelView
|
|
@Environment(\.navigationStyle) private var navigationStyle
|
|
@Environment(\.currentPlaylistID) private var playlistID
|
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
|
@EnvironmentObject<PlayerModel> private var player
|
|
@EnvironmentObject<PlaylistsModel> private var playlists
|
|
@EnvironmentObject<RecentsModel> private var recents
|
|
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
|
|
|
var body: some View {
|
|
Section {
|
|
playNowButton
|
|
}
|
|
|
|
Section {
|
|
playNextButton
|
|
addToQueueButton
|
|
}
|
|
|
|
if !inChannelView {
|
|
Section {
|
|
openChannelButton
|
|
|
|
if accounts.app.supportsSubscriptions {
|
|
subscriptionButton
|
|
}
|
|
}
|
|
}
|
|
|
|
if accounts.app.supportsUserPlaylists {
|
|
Section {
|
|
addToPlaylistButton
|
|
|
|
if let id = navigation.tabSelection?.playlistID ?? playlistID {
|
|
removeFromPlaylistButton(playlistID: id)
|
|
}
|
|
}
|
|
}
|
|
|
|
#if os(tvOS)
|
|
Button("Cancel", role: .cancel) {}
|
|
#endif
|
|
}
|
|
|
|
private var playNowButton: some View {
|
|
Button {
|
|
player.playNow(video)
|
|
|
|
guard !player.playingInPictureInPicture else {
|
|
return
|
|
}
|
|
|
|
if inNavigationView {
|
|
playerNavigationLinkActive = true
|
|
} else {
|
|
player.show()
|
|
}
|
|
} label: {
|
|
Label("Play Now", systemImage: "play")
|
|
}
|
|
}
|
|
|
|
private var playNextButton: some View {
|
|
Button {
|
|
player.playNext(video)
|
|
} label: {
|
|
Label("Play Next", systemImage: "text.insert")
|
|
}
|
|
}
|
|
|
|
private var isShowingChannelButton: Bool {
|
|
if case .channel = navigation.tabSelection {
|
|
return false
|
|
}
|
|
|
|
return !inChannelView
|
|
}
|
|
|
|
private var addToQueueButton: some View {
|
|
Button {
|
|
player.enqueueVideo(video)
|
|
} label: {
|
|
Label("Play Last", systemImage: "text.append")
|
|
}
|
|
}
|
|
|
|
private var openChannelButton: some View {
|
|
Button {
|
|
NavigationModel.openChannel(
|
|
video.channel,
|
|
player: player,
|
|
recents: recents,
|
|
navigation: navigation,
|
|
navigationStyle: navigationStyle
|
|
)
|
|
} label: {
|
|
Label("\(video.author) Channel", systemImage: "rectangle.stack.fill.badge.person.crop")
|
|
}
|
|
}
|
|
|
|
private var subscriptionButton: some View {
|
|
Group {
|
|
if subscriptions.isSubscribing(video.channel.id) {
|
|
Button {
|
|
#if os(tvOS)
|
|
subscriptions.unsubscribe(video.channel.id)
|
|
#else
|
|
navigation.presentUnsubscribeAlert(video.channel)
|
|
#endif
|
|
} label: {
|
|
Label("Unsubscribe", systemImage: "xmark.circle")
|
|
}
|
|
} else {
|
|
Button {
|
|
subscriptions.subscribe(video.channel.id) {
|
|
navigation.sidebarSectionChanged.toggle()
|
|
}
|
|
} label: {
|
|
Label("Subscribe", systemImage: "star.circle")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private var addToPlaylistButton: some View {
|
|
Button {
|
|
navigation.presentAddToPlaylist(video)
|
|
} label: {
|
|
Label("Add to playlist...", systemImage: "text.badge.plus")
|
|
}
|
|
}
|
|
|
|
func removeFromPlaylistButton(playlistID: String) -> some View {
|
|
Button {
|
|
playlists.removeVideo(videoIndexID: video.indexID!, playlistID: playlistID)
|
|
} label: {
|
|
Label("Remove from playlist", systemImage: "text.badge.minus")
|
|
}
|
|
}
|
|
}
|