mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Replace environment objects with observed objects
This commit is contained in:
@@ -7,17 +7,10 @@ struct ChannelCell: View {
|
||||
|
||||
@Environment(\.navigationStyle) private var navigationStyle
|
||||
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
NavigationModel.openChannel(
|
||||
NavigationModel.shared.openChannel(
|
||||
channel,
|
||||
player: player,
|
||||
recents: recents,
|
||||
navigation: navigation,
|
||||
navigationStyle: navigationStyle
|
||||
)
|
||||
} label: {
|
||||
|
@@ -6,13 +6,12 @@ struct ChannelPlaylistCell: View {
|
||||
|
||||
@Environment(\.navigationStyle) private var navigationStyle
|
||||
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
var navigation = NavigationModel.shared
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
let recent = RecentItem(from: playlist)
|
||||
recents.add(recent)
|
||||
RecentsModel.shared.add(recent)
|
||||
navigation.presentingPlaylist = true
|
||||
|
||||
if navigationStyle == .sidebar {
|
||||
|
@@ -12,10 +12,9 @@ struct ChannelPlaylistView: View {
|
||||
@Environment(\.colorScheme) private var colorScheme
|
||||
@Environment(\.navigationStyle) private var navigationStyle
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
var player = PlayerModel.shared
|
||||
@ObservedObject private var recents = RecentsModel.shared
|
||||
|
||||
private var items: [ContentItem] {
|
||||
ContentItem.array(of: store.item?.videos ?? [])
|
||||
@@ -89,7 +88,7 @@ struct ChannelPlaylistView: View {
|
||||
if navigationStyle == .tab {
|
||||
Button("Done") {
|
||||
withAnimation(Constants.overlayAnimation) {
|
||||
navigation.presentingPlaylist = false
|
||||
NavigationModel.shared.presentingPlaylist = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,14 +15,12 @@ struct ChannelVideosView: View {
|
||||
|
||||
#if os(iOS)
|
||||
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
#endif
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
||||
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
@ObservedObject private var navigation = NavigationModel.shared
|
||||
@ObservedObject private var recents = RecentsModel.shared
|
||||
@ObservedObject private var subscriptions = SubscriptionsModel.shared
|
||||
@Namespace private var focusNamespace
|
||||
|
||||
var presentedChannel: Channel? {
|
||||
|
@@ -10,12 +10,11 @@ struct ControlsBar: View {
|
||||
|
||||
@Environment(\.navigationStyle) private var navigationStyle
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<PlayerModel> private var model
|
||||
@EnvironmentObject<PlaylistsModel> private var playlists
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
var navigation = NavigationModel.shared
|
||||
@ObservedObject private var model = PlayerModel.shared
|
||||
@ObservedObject private var playlists = PlaylistsModel.shared
|
||||
@ObservedObject private var subscriptions = SubscriptionsModel.shared
|
||||
|
||||
@ObservedObject private var controls = PlayerControlsModel.shared
|
||||
|
||||
@@ -139,11 +138,8 @@ struct ControlsBar: View {
|
||||
HStack(spacing: 8) {
|
||||
Button {
|
||||
if let video = model.currentVideo, !video.isLocal {
|
||||
NavigationModel.openChannel(
|
||||
navigation.openChannel(
|
||||
video.channel,
|
||||
player: model,
|
||||
recents: recents,
|
||||
navigation: navigation,
|
||||
navigationStyle: navigationStyle
|
||||
)
|
||||
}
|
||||
@@ -179,7 +175,7 @@ struct ControlsBar: View {
|
||||
|
||||
if let playlist = playlists.lastUsed, let video = model.currentVideo {
|
||||
Button {
|
||||
playlists.addVideo(playlistID: playlist.id, videoID: video.videoID, navigation: navigation)
|
||||
playlists.addVideo(playlistID: playlist.id, videoID: video.videoID)
|
||||
} label: {
|
||||
Label("Add to \(playlist.title)", systemImage: "text.badge.star")
|
||||
}
|
||||
@@ -194,11 +190,8 @@ struct ControlsBar: View {
|
||||
Section {
|
||||
if !video.isLocal {
|
||||
Button {
|
||||
NavigationModel.openChannel(
|
||||
navigation.openChannel(
|
||||
video.channel,
|
||||
player: model,
|
||||
recents: recents,
|
||||
navigation: navigation,
|
||||
navigationStyle: navigationStyle
|
||||
)
|
||||
} label: {
|
||||
|
@@ -2,10 +2,8 @@ import SwiftUI
|
||||
|
||||
#if !os(macOS)
|
||||
struct MPVPlayerView: UIViewControllerRepresentable {
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
|
||||
func makeUIViewController(context _: Context) -> some UIViewController {
|
||||
player.mpvController
|
||||
PlayerModel.shared.mpvController
|
||||
}
|
||||
|
||||
func updateUIViewController(_: UIViewControllerType, context _: Context) {}
|
||||
@@ -15,10 +13,8 @@ import SwiftUI
|
||||
@State private var client = MPVClient()
|
||||
@State private var layer = VideoLayer()
|
||||
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
|
||||
func makeNSView(context _: Context) -> some NSView {
|
||||
player.mpvBackend.client = client
|
||||
PlayerModel.shared.mpvBackend.client = client
|
||||
|
||||
let view = MPVOGLView()
|
||||
|
||||
|
@@ -4,7 +4,7 @@ struct OpenSettingsButton: View {
|
||||
@Environment(\.presentationMode) private var presentationMode
|
||||
|
||||
#if !os(macOS)
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
private var navigation: NavigationModel { .shared }
|
||||
#endif
|
||||
|
||||
var body: some View {
|
||||
|
@@ -6,11 +6,7 @@ struct OpenVideosView: View {
|
||||
@State private var playbackMode = OpenVideosModel.PlaybackMode.playNow
|
||||
@State private var removeQueueItems = false
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
@EnvironmentObject<SearchModel> private var search
|
||||
@ObservedObject private var navigation = NavigationModel.shared
|
||||
|
||||
@Environment(\.openURL) private var openURL
|
||||
@Environment(\.presentationMode) private var presentationMode
|
||||
@@ -132,8 +128,8 @@ struct OpenVideosView: View {
|
||||
|
||||
openURLs(urlsToOpen)
|
||||
} catch {
|
||||
NavigationModel.shared.alert = Alert(title: Text("Could not open Files"))
|
||||
NavigationModel.shared.presentingAlertInOpenVideos = true
|
||||
navigation.alert = Alert(title: Text("Could not open Files"))
|
||||
navigation.presentingAlertInOpenVideos = true
|
||||
}
|
||||
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
|
@@ -4,8 +4,9 @@ import SwiftUI
|
||||
struct PlaylistVideosView: View {
|
||||
let playlist: Playlist
|
||||
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
@EnvironmentObject<PlaylistsModel> private var model
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
var player = PlayerModel.shared
|
||||
@ObservedObject private var model = PlaylistsModel.shared
|
||||
|
||||
@StateObject private var channelPlaylist = Store<ChannelPlaylist>()
|
||||
@StateObject private var userPlaylist = Store<Playlist>()
|
||||
@@ -15,7 +16,7 @@ struct PlaylistVideosView: View {
|
||||
|
||||
if videos.isEmpty {
|
||||
videos = userPlaylist.item?.videos ?? channelPlaylist.item?.videos ?? []
|
||||
if !player.accounts.app.userPlaylistsEndpointIncludesVideos {
|
||||
if !accounts.app.userPlaylistsEndpointIncludesVideos {
|
||||
var i = 0
|
||||
|
||||
for index in videos.indices {
|
||||
@@ -31,9 +32,9 @@ struct PlaylistVideosView: View {
|
||||
}
|
||||
|
||||
private var resource: Resource? {
|
||||
let resource = player.accounts.api.playlist(playlist.id)
|
||||
let resource = accounts.api.playlist(playlist.id)
|
||||
|
||||
if player.accounts.app.userPlaylistsUseChannelPlaylistEndpoint {
|
||||
if accounts.app.userPlaylistsUseChannelPlaylistEndpoint {
|
||||
resource?.addObserver(channelPlaylist)
|
||||
} else {
|
||||
resource?.addObserver(userPlaylist)
|
||||
|
@@ -4,7 +4,7 @@ import SwiftUI
|
||||
struct PopularView: View {
|
||||
@StateObject private var store = Store<[Video]>()
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
|
||||
var resource: Resource? {
|
||||
accounts.api.popular
|
||||
|
@@ -3,9 +3,9 @@ import SwiftUI
|
||||
struct ShareButton<LabelView: View>: View {
|
||||
let contentItem: ContentItem
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
private var navigation: NavigationModel { .shared }
|
||||
@ObservedObject private var player = PlayerModel.shared
|
||||
|
||||
let label: LabelView?
|
||||
|
||||
|
@@ -5,7 +5,7 @@ struct SignInRequiredView<Content: View>: View {
|
||||
let title: String
|
||||
let content: Content
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
|
||||
@Default(.instances) private var instances
|
||||
|
||||
|
@@ -4,7 +4,7 @@ import SwiftUI
|
||||
struct SubscriptionsView: View {
|
||||
@StateObject private var store = Store<[Video]>()
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
|
||||
var feed: Resource? {
|
||||
accounts.api.feed
|
||||
|
@@ -11,12 +11,11 @@ struct VideoContextMenuView: View {
|
||||
@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
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
@ObservedObject private var navigation = NavigationModel.shared
|
||||
@ObservedObject private var player = PlayerModel.shared
|
||||
@ObservedObject private var playlists = PlaylistsModel.shared
|
||||
@ObservedObject private var subscriptions = SubscriptionsModel.shared
|
||||
|
||||
@FetchRequest private var watchRequest: FetchedResults<Watch>
|
||||
|
||||
@@ -261,11 +260,8 @@ struct VideoContextMenuView: View {
|
||||
|
||||
private var openChannelButton: some View {
|
||||
Button {
|
||||
NavigationModel.openChannel(
|
||||
NavigationModel.shared.openChannel(
|
||||
video.channel,
|
||||
player: player,
|
||||
recents: recents,
|
||||
navigation: navigation,
|
||||
navigationStyle: navigationStyle
|
||||
)
|
||||
} label: {
|
||||
@@ -308,7 +304,7 @@ struct VideoContextMenuView: View {
|
||||
@ViewBuilder private var addToLastPlaylistButton: some View {
|
||||
if let playlist = playlists.lastUsed {
|
||||
Button {
|
||||
playlists.addVideo(playlistID: playlist.id, videoID: video.videoID, navigation: navigation)
|
||||
playlists.addVideo(playlistID: playlist.id, videoID: video.videoID)
|
||||
} label: {
|
||||
Label("Add to \(playlist.title)", systemImage: "text.badge.star")
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@ import SwiftUI
|
||||
struct WelcomeScreen: View {
|
||||
@Environment(\.presentationMode) private var presentationMode
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@State private var store = [ManifestedInstance]()
|
||||
|
||||
var body: some View {
|
||||
@@ -25,7 +24,7 @@ struct WelcomeScreen: View {
|
||||
ForEach(countries, id: \.self) { country in
|
||||
Button {
|
||||
Defaults[.countryOfPublicInstances] = country
|
||||
InstancesManifest.shared.setPublicAccount(country, accounts: accounts)
|
||||
InstancesManifest.shared.setPublicAccount(country)
|
||||
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
} label: {
|
||||
|
Reference in New Issue
Block a user