mirror of
https://github.com/yattee/yattee.git
synced 2024-11-10 00:08:21 +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
107 lines
2.8 KiB
Swift
107 lines
2.8 KiB
Swift
import Foundation
|
|
import SwiftUI
|
|
|
|
final class NavigationModel: ObservableObject {
|
|
enum TabSelection: Hashable {
|
|
case favorites
|
|
case subscriptions
|
|
case popular
|
|
case trending
|
|
case playlists
|
|
case channel(String)
|
|
case playlist(String)
|
|
case recentlyOpened(String)
|
|
case nowPlaying
|
|
case search
|
|
|
|
var playlistID: Playlist.ID? {
|
|
if case let .playlist(id) = self {
|
|
return id
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
@Published var tabSelection: TabSelection!
|
|
|
|
@Published var presentingAddToPlaylist = false
|
|
@Published var videoToAddToPlaylist: Video!
|
|
|
|
@Published var presentingPlaylistForm = false
|
|
@Published var editedPlaylist: Playlist!
|
|
|
|
@Published var presentingUnsubscribeAlert = false
|
|
@Published var channelToUnsubscribe: Channel!
|
|
|
|
@Published var presentingChannel = false
|
|
@Published var presentingPlaylist = false
|
|
@Published var sidebarSectionChanged = false
|
|
|
|
@Published var presentingSettings = false
|
|
@Published var presentingWelcomeScreen = false
|
|
|
|
static func openChannel(
|
|
_ channel: Channel,
|
|
player: PlayerModel,
|
|
recents: RecentsModel,
|
|
navigation: NavigationModel,
|
|
navigationStyle: NavigationStyle
|
|
) {
|
|
let recent = RecentItem(from: channel)
|
|
#if os(macOS)
|
|
OpenWindow.main.open()
|
|
#else
|
|
player.hide()
|
|
#endif
|
|
|
|
let openRecent = {
|
|
recents.add(recent)
|
|
navigation.presentingChannel = true
|
|
}
|
|
|
|
if navigationStyle == .tab {
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
openRecent()
|
|
}
|
|
} else if navigationStyle == .sidebar {
|
|
openRecent()
|
|
navigation.sidebarSectionChanged.toggle()
|
|
navigation.tabSelection = .recentlyOpened(recent.tag)
|
|
}
|
|
}
|
|
|
|
var tabSelectionBinding: Binding<TabSelection> {
|
|
Binding<TabSelection>(
|
|
get: {
|
|
self.tabSelection ?? .favorites
|
|
},
|
|
set: { newValue in
|
|
self.tabSelection = newValue
|
|
}
|
|
)
|
|
}
|
|
|
|
func presentAddToPlaylist(_ video: Video) {
|
|
videoToAddToPlaylist = video
|
|
presentingAddToPlaylist = true
|
|
}
|
|
|
|
func presentEditPlaylistForm(_ playlist: Playlist?) {
|
|
editedPlaylist = playlist
|
|
presentingPlaylistForm = editedPlaylist != nil
|
|
}
|
|
|
|
func presentNewPlaylistForm() {
|
|
editedPlaylist = nil
|
|
presentingPlaylistForm = true
|
|
}
|
|
|
|
func presentUnsubscribeAlert(_ channel: Channel?) {
|
|
channelToUnsubscribe = channel
|
|
presentingUnsubscribeAlert = channelToUnsubscribe != nil
|
|
}
|
|
}
|
|
|
|
typealias TabSelection = NavigationModel.TabSelection
|