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 {
|
2021-12-19 17:17:04 +00:00
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
|
|
|
@EnvironmentObject<CommentsModel> private var comments
|
|
|
|
@EnvironmentObject<InstancesModel> private var instances
|
|
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
2022-06-18 12:39:49 +00:00
|
|
|
@EnvironmentObject<NetworkStateModel> private var networkState
|
2021-12-19 17:17:04 +00:00
|
|
|
@EnvironmentObject<PlayerModel> private var player
|
2022-02-16 20:23:11 +00:00
|
|
|
@EnvironmentObject<PlayerControlsModel> private var playerControls
|
2022-06-18 12:39:49 +00:00
|
|
|
@EnvironmentObject<PlayerTimeModel> private var playerTime
|
2021-12-19 17:17:04 +00:00
|
|
|
@EnvironmentObject<PlaylistsModel> private var playlists
|
|
|
|
@EnvironmentObject<RecentsModel> private var recents
|
|
|
|
@EnvironmentObject<SearchModel> private var search
|
|
|
|
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
|
|
|
@EnvironmentObject<ThumbnailsModel> private var thumbnailsModel
|
2021-09-25 08:18:22 +00:00
|
|
|
|
2021-11-08 23:14:28 +00:00
|
|
|
@EnvironmentObject<MenuModel> private var menu
|
|
|
|
|
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
|
|
|
|
2022-05-29 18:26:56 +00:00
|
|
|
let persistenceController = PersistenceController.shared
|
|
|
|
|
2021-06-09 20:51:23 +00:00
|
|
|
var body: some View {
|
2021-11-30 22:58:11 +00:00
|
|
|
Group {
|
2021-07-11 20:52:49 +00:00
|
|
|
#if os(iOS)
|
|
|
|
if horizontalSizeClass == .compact {
|
|
|
|
AppTabNavigation()
|
|
|
|
} else {
|
|
|
|
AppSidebarNavigation()
|
2021-06-11 21:11:59 +00:00
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
#elseif os(macOS)
|
|
|
|
AppSidebarNavigation()
|
|
|
|
#elseif os(tvOS)
|
|
|
|
TVNavigationView()
|
|
|
|
#endif
|
2021-07-29 22:34:13 +00:00
|
|
|
}
|
2021-12-19 22:27:20 +00:00
|
|
|
.onChange(of: accounts.signedIn) { _ in
|
|
|
|
subscriptions.load(force: true)
|
|
|
|
playlists.load(force: true)
|
|
|
|
}
|
2021-10-24 09:16:04 +00:00
|
|
|
|
2021-10-16 22:48:58 +00:00
|
|
|
.environmentObject(accounts)
|
2021-12-04 19:35:41 +00:00
|
|
|
.environmentObject(comments)
|
2021-10-05 20:20:09 +00:00
|
|
|
.environmentObject(instances)
|
2021-09-25 08:18:22 +00:00
|
|
|
.environmentObject(navigation)
|
2022-06-18 12:39:49 +00:00
|
|
|
.environmentObject(networkState)
|
2021-10-05 20:20:09 +00:00
|
|
|
.environmentObject(player)
|
2022-06-18 12:39:49 +00:00
|
|
|
.environmentObject(playerTime)
|
2021-10-05 20:20:09 +00:00
|
|
|
.environmentObject(playlists)
|
2021-09-25 08:18:22 +00:00
|
|
|
.environmentObject(recents)
|
2021-10-05 20:20:09 +00:00
|
|
|
.environmentObject(search)
|
|
|
|
.environmentObject(subscriptions)
|
2021-10-24 22:26:25 +00:00
|
|
|
.environmentObject(thumbnailsModel)
|
|
|
|
|
2022-05-29 12:29:43 +00:00
|
|
|
#if os(iOS)
|
2022-05-28 21:41:23 +00:00
|
|
|
.overlay(videoPlayer)
|
2021-08-01 23:01:24 +00:00
|
|
|
#endif
|
2022-05-28 21:41:23 +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()
|
|
|
|
.environmentObject(accounts)
|
|
|
|
.environmentObject(navigation)
|
|
|
|
}
|
2021-12-19 22:27:20 +00:00
|
|
|
)
|
2022-05-28 21:41:23 +00:00
|
|
|
#if !os(tvOS)
|
|
|
|
.onOpenURL { OpenURLHandler(accounts: accounts, player: player).handle($0) }
|
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingAddToPlaylist) {
|
|
|
|
AddToPlaylistView(video: navigation.videoToAddToPlaylist)
|
|
|
|
.environmentObject(playlists)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingPlaylistForm) {
|
|
|
|
PlaylistFormView(playlist: $navigation.editedPlaylist)
|
|
|
|
.environmentObject(accounts)
|
|
|
|
.environmentObject(playlists)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingSettings, onDismiss: openWelcomeScreenIfAccountEmpty) {
|
|
|
|
SettingsView()
|
|
|
|
.environmentObject(accounts)
|
|
|
|
.environmentObject(instances)
|
|
|
|
.environmentObject(player)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
#endif
|
|
|
|
.alert(isPresented: $navigation.presentingUnsubscribeAlert) {
|
|
|
|
Alert(
|
|
|
|
title: Text(
|
|
|
|
"Are you sure you want to unsubscribe from \(navigation.channelToUnsubscribe.name)?"
|
|
|
|
),
|
|
|
|
primaryButton: .destructive(Text("Unsubscribe")) {
|
|
|
|
subscriptions.unsubscribe(navigation.channelToUnsubscribe.id)
|
|
|
|
},
|
|
|
|
secondaryButton: .cancel()
|
|
|
|
)
|
|
|
|
}
|
2022-06-18 12:39:49 +00:00
|
|
|
.alert(isPresented: $navigation.presentingAlert) {
|
|
|
|
Alert(title: Text(navigation.alertTitle), message: Text(navigation.alertMessage))
|
2022-02-16 21:10:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 23:06:00 +00:00
|
|
|
func openWelcomeScreenIfAccountEmpty() {
|
2021-10-19 21:27:04 +00:00
|
|
|
guard Defaults[.instances].isEmpty else {
|
2021-10-17 23:06:00 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
navigation.presentingWelcomeScreen = true
|
|
|
|
}
|
2022-05-28 21:41:23 +00:00
|
|
|
|
|
|
|
var videoPlayer: some View {
|
|
|
|
VideoPlayerView()
|
|
|
|
.environmentObject(accounts)
|
|
|
|
.environmentObject(comments)
|
|
|
|
.environmentObject(instances)
|
|
|
|
.environmentObject(navigation)
|
|
|
|
.environmentObject(player)
|
|
|
|
.environmentObject(playerControls)
|
|
|
|
.environmentObject(playlists)
|
|
|
|
.environmentObject(recents)
|
|
|
|
.environmentObject(subscriptions)
|
|
|
|
.environmentObject(thumbnailsModel)
|
|
|
|
.environment(\.navigationStyle, .sidebar)
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|