2021-10-24 14:01:36 +00:00
|
|
|
import AVFAudio
|
2021-09-25 08:18:22 +00:00
|
|
|
import Defaults
|
2022-02-16 21:10:57 +00:00
|
|
|
import MediaPlayer
|
2021-10-21 23:29:10 +00:00
|
|
|
import SDWebImage
|
|
|
|
import SDWebImagePINPlugin
|
|
|
|
import SDWebImageWebPCoder
|
2021-10-16 22:48:58 +00:00
|
|
|
import Siesta
|
2021-06-09 20:51:23 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ContentView: View {
|
2022-11-24 20:36:05 +00:00
|
|
|
@ObservedObject private var navigation = NavigationModel.shared
|
|
|
|
@ObservedObject private var player = PlayerModel.shared
|
2021-11-08 23:14:28 +00:00
|
|
|
|
2021-07-11 20:52:49 +00:00
|
|
|
#if os(iOS)
|
|
|
|
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
|
|
|
#endif
|
2021-06-11 21:11:59 +00:00
|
|
|
|
2023-05-20 20:49:10 +00:00
|
|
|
@Default(.avPlayerUsesSystemControls) private var avPlayerUsesSystemControls
|
|
|
|
|
2021-06-09 20:51:23 +00:00
|
|
|
var body: some View {
|
2023-05-20 22:18:10 +00:00
|
|
|
GeometryReader { proxy in
|
|
|
|
Group {
|
|
|
|
#if os(iOS)
|
2023-05-20 14:04:58 +00:00
|
|
|
Group {
|
|
|
|
if Constants.isIPhone {
|
|
|
|
AppTabNavigation()
|
|
|
|
} else {
|
|
|
|
if horizontalSizeClass == .compact {
|
|
|
|
AppTabNavigation()
|
|
|
|
} else {
|
|
|
|
AppSidebarNavigation()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-20 22:18:10 +00:00
|
|
|
#elseif os(macOS)
|
|
|
|
AppSidebarNavigation()
|
|
|
|
#elseif os(tvOS)
|
|
|
|
TVNavigationView()
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#if !os(macOS)
|
|
|
|
.onAppear {
|
|
|
|
SafeAreaModel.shared.safeArea = proxy.safeAreaInsets
|
|
|
|
}
|
|
|
|
.onChange(of: proxy.safeAreaInsets) { newValue in
|
|
|
|
SafeAreaModel.shared.safeArea = newValue
|
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
#endif
|
2021-07-29 22:34:13 +00:00
|
|
|
}
|
2022-05-29 12:29:43 +00:00
|
|
|
#if os(iOS)
|
2022-11-24 20:36:05 +00:00
|
|
|
.overlay(videoPlayer)
|
|
|
|
.sheet(isPresented: $navigation.presentingShareSheet) {
|
|
|
|
if let shareURL = navigation.shareURL {
|
|
|
|
ShareSheet(activityItems: [shareURL])
|
2022-06-26 11:57:02 +00:00
|
|
|
}
|
2022-11-24 20:36:05 +00:00
|
|
|
}
|
2021-08-01 23:01:24 +00:00
|
|
|
#endif
|
2022-05-28 21:41:23 +00:00
|
|
|
|
2022-11-24 20:36:05 +00:00
|
|
|
// iOS 14 has problem with multiple sheets in one view
|
|
|
|
// but it's ok when it's in background
|
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingWelcomeScreen) {
|
|
|
|
WelcomeScreen()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingSettings) {
|
|
|
|
SettingsView()
|
|
|
|
}
|
|
|
|
)
|
2022-12-11 22:15:56 +00:00
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingAccounts) {
|
|
|
|
AccountsView()
|
|
|
|
}
|
|
|
|
)
|
2022-05-28 21:41:23 +00:00
|
|
|
#if !os(tvOS)
|
2022-11-24 20:36:05 +00:00
|
|
|
.fileImporter(
|
|
|
|
isPresented: $navigation.presentingFileImporter,
|
|
|
|
allowedContentTypes: [.audiovisualContent],
|
|
|
|
allowsMultipleSelection: true
|
|
|
|
) { result in
|
|
|
|
do {
|
|
|
|
let selectedFiles = try result.get()
|
|
|
|
let urlsToOpen = selectedFiles.map { url in
|
|
|
|
if let bookmarkURL = URLBookmarkModel.shared.loadBookmark(url) {
|
|
|
|
return bookmarkURL
|
|
|
|
}
|
|
|
|
|
|
|
|
if url.startAccessingSecurityScopedResource() {
|
|
|
|
URLBookmarkModel.shared.saveBookmark(url)
|
2022-11-11 17:50:13 +00:00
|
|
|
}
|
|
|
|
|
2022-11-24 20:36:05 +00:00
|
|
|
return url
|
2022-11-11 17:50:13 +00:00
|
|
|
}
|
|
|
|
|
2022-11-24 20:36:05 +00:00
|
|
|
OpenVideosModel.shared.openURLs(urlsToOpen)
|
|
|
|
} catch {
|
|
|
|
NavigationModel.shared.presentAlert(title: "Could not open Files")
|
2022-11-11 17:50:13 +00:00
|
|
|
}
|
2022-11-24 20:36:05 +00:00
|
|
|
|
|
|
|
NavigationModel.shared.presentingOpenVideos = false
|
|
|
|
}
|
2022-12-04 12:21:50 +00:00
|
|
|
.onOpenURL { url in
|
|
|
|
URLBookmarkModel.shared.saveBookmark(url)
|
|
|
|
OpenURLHandler.shared.handle(url)
|
|
|
|
}
|
2022-11-24 20:36:05 +00:00
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingAddToPlaylist) {
|
|
|
|
AddToPlaylistView(video: navigation.videoToAddToPlaylist)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingPlaylistForm) {
|
|
|
|
PlaylistFormView(playlist: $navigation.editedPlaylist)
|
|
|
|
}
|
|
|
|
)
|
2022-05-28 21:41:23 +00:00
|
|
|
#endif
|
2022-12-21 20:16:47 +00:00
|
|
|
#if os(iOS)
|
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingPlaybackSettings) {
|
|
|
|
PlaybackSettings()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
#endif
|
2022-11-24 20:36:05 +00:00
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingOpenVideos) {
|
|
|
|
OpenVideosView()
|
|
|
|
}
|
|
|
|
)
|
2023-04-22 08:56:42 +00:00
|
|
|
#if !os(macOS)
|
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingChannelSheet) {
|
|
|
|
NavigationView {
|
|
|
|
ChannelVideosView(channel: navigation.channelPresentedInSheet, showCloseButton: true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
#endif
|
2022-11-24 20:36:05 +00:00
|
|
|
.alert(isPresented: $navigation.presentingAlert) { navigation.alert }
|
2023-05-20 22:18:10 +00:00
|
|
|
#if os(iOS)
|
|
|
|
.statusBarHidden(player.playingFullScreen)
|
|
|
|
#endif
|
2022-02-16 21:10:57 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 08:05:32 +00:00
|
|
|
var navigationStyle: NavigationStyle {
|
|
|
|
#if os(iOS)
|
|
|
|
return horizontalSizeClass == .compact ? .tab : .sidebar
|
|
|
|
#elseif os(tvOS)
|
|
|
|
return .tab
|
|
|
|
#else
|
|
|
|
return .sidebar
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-07-09 00:21:04 +00:00
|
|
|
@ViewBuilder var videoPlayer: some View {
|
2022-08-08 18:02:46 +00:00
|
|
|
if player.presentingPlayer {
|
2022-08-18 22:40:46 +00:00
|
|
|
playerView
|
2022-12-18 12:11:06 +00:00
|
|
|
.transition(.asymmetric(insertion: .identity, removal: .opacity))
|
2022-08-25 17:09:55 +00:00
|
|
|
.zIndex(3)
|
2023-05-20 20:49:10 +00:00
|
|
|
} else if player.activeBackend == .appleAVPlayer,
|
|
|
|
avPlayerUsesSystemControls || player.avPlayerBackend.isStartingPiP
|
|
|
|
{
|
2022-08-18 22:40:46 +00:00
|
|
|
#if os(iOS)
|
2023-05-20 20:49:10 +00:00
|
|
|
AppleAVPlayerLayerView().offset(y: UIScreen.main.bounds.height)
|
2022-08-18 22:40:46 +00:00
|
|
|
#endif
|
2022-08-08 18:02:46 +00:00
|
|
|
}
|
2022-05-28 21:41:23 +00:00
|
|
|
}
|
2022-08-18 22:40:46 +00:00
|
|
|
|
|
|
|
var playerView: some View {
|
|
|
|
VideoPlayerView()
|
|
|
|
.environment(\.navigationStyle, navigationStyle)
|
|
|
|
}
|
2021-06-09 20:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ContentView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
ContentView()
|
2021-09-29 11:45:00 +00:00
|
|
|
.injectFixtureEnvironmentObjects()
|
2021-06-09 20:51:23 +00:00
|
|
|
}
|
|
|
|
}
|