From fe31e4ffd1f157f5646f5ffaaeeb5ad4aa20ca04 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Mon, 24 Jul 2023 19:38:32 +0200 Subject: [PATCH] Fix URL handling on macOS --- Shared/Navigation/ContentView.swift | 15 --------------- Shared/YatteeApp.swift | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift index f850f246..350efee3 100644 --- a/Shared/Navigation/ContentView.swift +++ b/Shared/Navigation/ContentView.swift @@ -131,10 +131,6 @@ struct ContentView: View { NavigationModel.shared.presentingOpenVideos = false } - .onOpenURL { url in - URLBookmarkModel.shared.saveBookmark(url) - OpenURLHandler(navigationStyle: navigationStyle).handle(url) - } .background( EmptyView().sheet(isPresented: $navigation.presentingAddToPlaylist) { AddToPlaylistView(video: navigation.videoToAddToPlaylist) @@ -173,16 +169,6 @@ struct ContentView: View { #endif } - var navigationStyle: NavigationStyle { - #if os(iOS) - return horizontalSizeClass == .compact ? .tab : .sidebar - #elseif os(tvOS) - return .tab - #else - return .sidebar - #endif - } - @ViewBuilder var videoPlayer: some View { if player.presentingPlayer { playerView @@ -199,7 +185,6 @@ struct ContentView: View { var playerView: some View { VideoPlayerView() - .environment(\.navigationStyle, navigationStyle) } } diff --git a/Shared/YatteeApp.swift b/Shared/YatteeApp.swift index 26264048..3f69a67e 100644 --- a/Shared/YatteeApp.swift +++ b/Shared/YatteeApp.swift @@ -28,6 +28,7 @@ struct YatteeApp: App { @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate #elseif os(iOS) @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate + @Environment(\.horizontalSizeClass) private var horizontalSizeClass #endif @State private var configured = false @@ -55,6 +56,7 @@ struct YatteeApp: App { ContentView() .onAppear(perform: configure) .environment(\.managedObjectContext, persistenceController.container.viewContext) + .environment(\.navigationStyle, navigationStyle) #if os(macOS) .background( HostingWindowFinder { window in @@ -76,6 +78,12 @@ struct YatteeApp: App { #if os(iOS) .handlesExternalEvents(preferring: Set(["*"]), allowing: Set(["*"])) #endif + #if !os(tvOS) + .onOpenURL { url in + URLBookmarkModel.shared.saveBookmark(url) + OpenURLHandler(navigationStyle: navigationStyle).handle(url) + } + #endif } #if os(iOS) .handlesExternalEvents(matching: Set(["*"])) @@ -114,6 +122,10 @@ struct YatteeApp: App { .environment(\.managedObjectContext, persistenceController.container.viewContext) .environment(\.navigationStyle, .sidebar) .handlesExternalEvents(preferring: Set(["player", "*"]), allowing: Set(["player", "*"])) + .onOpenURL { url in + URLBookmarkModel.shared.saveBookmark(url) + OpenURLHandler(navigationStyle: navigationStyle).handle(url) + } } .handlesExternalEvents(matching: Set(["player", "*"])) @@ -200,4 +212,14 @@ struct YatteeApp: App { Defaults[.homeHistoryItems] = -1 } + + var navigationStyle: NavigationStyle { + #if os(iOS) + return horizontalSizeClass == .compact ? .tab : .sidebar + #elseif os(tvOS) + return .tab + #else + return .sidebar + #endif + } }