2021-10-24 19:31:36 +05:30
|
|
|
import AVFAudio
|
2021-09-25 13:48:22 +05:30
|
|
|
import Defaults
|
2022-02-17 02:40:57 +05:30
|
|
|
import MediaPlayer
|
2021-10-22 04:59:10 +05:30
|
|
|
import SDWebImage
|
|
|
|
import SDWebImagePINPlugin
|
|
|
|
import SDWebImageWebPCoder
|
2021-10-17 04:18:58 +05:30
|
|
|
import Siesta
|
2021-06-10 02:21:23 +05:30
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ContentView: View {
|
2022-11-25 02:06:05 +05:30
|
|
|
@ObservedObject private var navigation = NavigationModel.shared
|
|
|
|
@ObservedObject private var player = PlayerModel.shared
|
2021-11-09 04:44:28 +05:30
|
|
|
|
2021-07-12 02:22:49 +05:30
|
|
|
#if os(iOS)
|
|
|
|
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
|
|
|
#endif
|
2021-06-12 02:41:59 +05:30
|
|
|
|
2023-05-21 02:19:10 +05:30
|
|
|
@Default(.avPlayerUsesSystemControls) private var avPlayerUsesSystemControls
|
|
|
|
|
2021-06-10 02:21:23 +05:30
|
|
|
var body: some View {
|
2023-05-21 03:48:10 +05:30
|
|
|
GeometryReader { proxy in
|
|
|
|
Group {
|
|
|
|
#if os(iOS)
|
2023-05-20 19:34:58 +05:30
|
|
|
Group {
|
|
|
|
if Constants.isIPhone {
|
|
|
|
AppTabNavigation()
|
|
|
|
} else {
|
|
|
|
if horizontalSizeClass == .compact {
|
|
|
|
AppTabNavigation()
|
|
|
|
} else {
|
|
|
|
AppSidebarNavigation()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-21 03:48:10 +05:30
|
|
|
#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-12 02:22:49 +05:30
|
|
|
#endif
|
2021-07-30 04:04:13 +05:30
|
|
|
}
|
2022-05-29 17:59:43 +05:30
|
|
|
#if os(iOS)
|
2022-11-25 02:06:05 +05:30
|
|
|
.overlay(videoPlayer)
|
|
|
|
.sheet(isPresented: $navigation.presentingShareSheet) {
|
|
|
|
if let shareURL = navigation.shareURL {
|
|
|
|
ShareSheet(activityItems: [shareURL])
|
2022-06-26 17:27:02 +05:30
|
|
|
}
|
2022-11-25 02:06:05 +05:30
|
|
|
}
|
2021-08-02 04:31:24 +05:30
|
|
|
#endif
|
2022-05-29 03:11:23 +05:30
|
|
|
|
2022-11-25 02:06:05 +05:30
|
|
|
// 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-12 03:45:56 +05:30
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingAccounts) {
|
|
|
|
AccountsView()
|
|
|
|
}
|
|
|
|
)
|
2023-05-25 17:58:29 +05:30
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingHomeSettings) {
|
|
|
|
#if os(macOS)
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Button("Done") {
|
|
|
|
navigation.presentingHomeSettings = false
|
|
|
|
}
|
|
|
|
.padding()
|
|
|
|
.keyboardShortcut(.cancelAction)
|
|
|
|
|
|
|
|
HomeSettings()
|
|
|
|
}
|
|
|
|
.frame(width: 500, height: 800)
|
|
|
|
#else
|
|
|
|
NavigationView {
|
|
|
|
HomeSettings()
|
|
|
|
#if os(iOS)
|
|
|
|
.toolbar {
|
|
|
|
ToolbarItem(placement: .navigation) {
|
|
|
|
Button {
|
|
|
|
navigation.presentingHomeSettings = false
|
|
|
|
} label: {
|
|
|
|
Text("Done")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
)
|
2022-05-29 03:11:23 +05:30
|
|
|
#if !os(tvOS)
|
2022-11-25 02:06:05 +05:30
|
|
|
.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 23:20:13 +05:30
|
|
|
}
|
|
|
|
|
2022-11-25 02:06:05 +05:30
|
|
|
return url
|
2022-11-11 23:20:13 +05:30
|
|
|
}
|
|
|
|
|
2022-11-25 02:06:05 +05:30
|
|
|
OpenVideosModel.shared.openURLs(urlsToOpen)
|
|
|
|
} catch {
|
|
|
|
NavigationModel.shared.presentAlert(title: "Could not open Files")
|
2022-11-11 23:20:13 +05:30
|
|
|
}
|
2022-11-25 02:06:05 +05:30
|
|
|
|
|
|
|
NavigationModel.shared.presentingOpenVideos = false
|
|
|
|
}
|
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingAddToPlaylist) {
|
|
|
|
AddToPlaylistView(video: navigation.videoToAddToPlaylist)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingPlaylistForm) {
|
|
|
|
PlaylistFormView(playlist: $navigation.editedPlaylist)
|
|
|
|
}
|
|
|
|
)
|
2022-05-29 03:11:23 +05:30
|
|
|
#endif
|
2022-12-22 01:46:47 +05:30
|
|
|
#if os(iOS)
|
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingPlaybackSettings) {
|
|
|
|
PlaybackSettings()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
#endif
|
2022-11-25 02:06:05 +05:30
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingOpenVideos) {
|
|
|
|
OpenVideosView()
|
|
|
|
}
|
|
|
|
)
|
2023-04-22 14:26:42 +05:30
|
|
|
#if !os(macOS)
|
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingChannelSheet) {
|
|
|
|
NavigationView {
|
|
|
|
ChannelVideosView(channel: navigation.channelPresentedInSheet, showCloseButton: true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
#endif
|
2022-11-25 02:06:05 +05:30
|
|
|
.alert(isPresented: $navigation.presentingAlert) { navigation.alert }
|
2023-05-21 03:48:10 +05:30
|
|
|
#if os(iOS)
|
|
|
|
.statusBarHidden(player.playingFullScreen)
|
|
|
|
#endif
|
2023-09-26 21:17:00 +05:30
|
|
|
#if os(macOS)
|
2023-10-15 03:58:32 +05:30
|
|
|
.frame(minWidth: 1200)
|
2023-09-26 21:17:00 +05:30
|
|
|
#endif
|
2022-02-17 02:40:57 +05:30
|
|
|
}
|
|
|
|
|
2022-07-09 05:51:04 +05:30
|
|
|
@ViewBuilder var videoPlayer: some View {
|
2022-08-08 23:32:46 +05:30
|
|
|
if player.presentingPlayer {
|
2022-08-19 04:10:46 +05:30
|
|
|
playerView
|
2022-12-18 17:41:06 +05:30
|
|
|
.transition(.asymmetric(insertion: .identity, removal: .opacity))
|
2022-08-25 22:39:55 +05:30
|
|
|
.zIndex(3)
|
2023-05-21 02:19:10 +05:30
|
|
|
} else if player.activeBackend == .appleAVPlayer,
|
|
|
|
avPlayerUsesSystemControls || player.avPlayerBackend.isStartingPiP
|
|
|
|
{
|
2022-08-19 04:10:46 +05:30
|
|
|
#if os(iOS)
|
2023-05-21 02:19:10 +05:30
|
|
|
AppleAVPlayerLayerView().offset(y: UIScreen.main.bounds.height)
|
2022-08-19 04:10:46 +05:30
|
|
|
#endif
|
2022-08-08 23:32:46 +05:30
|
|
|
}
|
2022-05-29 03:11:23 +05:30
|
|
|
}
|
2022-08-19 04:10:46 +05:30
|
|
|
|
|
|
|
var playerView: some View {
|
|
|
|
VideoPlayerView()
|
|
|
|
}
|
2021-06-10 02:21:23 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
struct ContentView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
ContentView()
|
2021-09-29 17:15:00 +05:30
|
|
|
.injectFixtureEnvironmentObjects()
|
2021-06-10 02:21:23 +05:30
|
|
|
}
|
|
|
|
}
|