From c0f6f5c666b00bc1f53075b14769fde050c67cfb Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Mon, 29 Aug 2022 15:31:36 +0200 Subject: [PATCH] Fix player initializer --- Shared/Navigation/ContentView.swift | 15 +++++++++++++++ Shared/YatteeApp.swift | 7 +------ tvOS/TVNavigationView.swift | 15 --------------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift index 9388fa46..3d1e39e8 100644 --- a/Shared/Navigation/ContentView.swift +++ b/Shared/Navigation/ContentView.swift @@ -29,6 +29,8 @@ struct ContentView: View { @Environment(\.horizontalSizeClass) private var horizontalSizeClass #endif + @State private var playerInitialized = false + let persistenceController = PersistenceController.shared var body: some View { @@ -120,6 +122,7 @@ struct ContentView: View { } ) #endif + .background(playerViewInitialize) .alert(isPresented: $navigation.presentingAlert) { navigation.alert } } @@ -159,6 +162,18 @@ struct ContentView: View { .environmentObject(thumbnailsModel) .environment(\.navigationStyle, navigationStyle) } + + @ViewBuilder var playerViewInitialize: some View { + if !playerInitialized { + VideoPlayerView() + .scaleEffect(0.00001) + .onAppear { + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + playerInitialized = true + } + } + } + } } struct ContentView_Previews: PreviewProvider { diff --git a/Shared/YatteeApp.swift b/Shared/YatteeApp.swift index 782cad34..599d161f 100644 --- a/Shared/YatteeApp.swift +++ b/Shared/YatteeApp.swift @@ -231,12 +231,7 @@ struct YatteeApp: App { subscriptions.load() playlists.load() - #if os(macOS) - Windows.player.open() - DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - Windows.main.focus() - } - #else + #if !os(macOS) player.updateRemoteCommandCenter() #endif diff --git a/tvOS/TVNavigationView.swift b/tvOS/TVNavigationView.swift index 4e88c3e2..56ad0215 100644 --- a/tvOS/TVNavigationView.swift +++ b/tvOS/TVNavigationView.swift @@ -10,8 +10,6 @@ struct TVNavigationView: View { @Default(.visibleSections) private var visibleSections - @State private var playerInitialized = false - var body: some View { NavigationView { TabView(selection: navigation.tabSelectionBinding) { @@ -58,7 +56,6 @@ struct TVNavigationView: View { .tag(TabSelection.settings) } } - .background(videoPlayerInitialize) .fullScreenCover(isPresented: $navigation.presentingAddToPlaylist) { if let video = navigation.videoToAddToPlaylist { AddToPlaylistView(video: video) @@ -78,18 +75,6 @@ struct TVNavigationView: View { } } } - - @ViewBuilder var videoPlayerInitialize: some View { - if !playerInitialized { - VideoPlayerView() - .scaleEffect(0.00001) - .onAppear { - DispatchQueue.main.asyncAfter(deadline: .now() + 1) { - playerInitialized = true - } - } - } - } } struct TVNavigationView_Previews: PreviewProvider {