From 61d235780d85727418e0ac05d5df363192d9e583 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 13 Nov 2022 00:07:23 +0100 Subject: [PATCH] Various minor fixes --- Model/Player/PlayerQueueItem.swift | 4 ++++ Shared/Documents/DocumentsView.swift | 22 ++++++++++--------- Shared/Home/HomeView.swift | 1 - Shared/Navigation/AppSidebarNavigation.swift | 4 ++-- Shared/Navigation/ContentView.swift | 11 +--------- Shared/Navigation/Sidebar.swift | 3 +-- Shared/OpenURLHandler.swift | 23 +++++++++++++------- Shared/Player/PlayerQueueRow.swift | 1 - Shared/Player/VideoPlayerView.swift | 18 +++++---------- Shared/Views/OpenVideosView.swift | 22 ++++++++++--------- Shared/Views/VideoContextMenuView.swift | 16 +++++++++----- Shared/YatteeApp.swift | 8 +++++++ 12 files changed, 71 insertions(+), 62 deletions(-) diff --git a/Model/Player/PlayerQueueItem.swift b/Model/Player/PlayerQueueItem.swift index c81be6ff..fa2c13ad 100644 --- a/Model/Player/PlayerQueueItem.swift +++ b/Model/Player/PlayerQueueItem.swift @@ -38,6 +38,10 @@ struct PlayerQueueItem: Hashable, Identifiable, Defaults.Serializable { return false } + if duration <= 0 { + return false + } + return duration - seconds <= 20 } diff --git a/Shared/Documents/DocumentsView.swift b/Shared/Documents/DocumentsView.swift index a7b0d0ca..062a880d 100644 --- a/Shared/Documents/DocumentsView.swift +++ b/Shared/Documents/DocumentsView.swift @@ -39,21 +39,23 @@ struct DocumentsView: View { } .toolbar { ToolbarItem(placement: .navigationBarLeading) { - Button { - withAnimation { - model.goBack() - } - } label: { - HStack(spacing: 6) { - Label("Go back", systemImage: "chevron.left") + if model.canGoBack { + Button { + withAnimation { + model.goBack() + } + } label: { + HStack(spacing: 6) { + Label("Go back", systemImage: "chevron.left") + } } + .transaction { t in t.animation = .none } + .disabled(!model.canGoBack) } - .transaction { t in t.animation = .none } - .disabled(!model.canGoBack) } } .navigationTitle(model.directoryLabel) - .padding() + .padding(.horizontal) .navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode) .backport .refreshable { diff --git a/Shared/Home/HomeView.swift b/Shared/Home/HomeView.swift index 62bc5c15..66957fce 100644 --- a/Shared/Home/HomeView.swift +++ b/Shared/Home/HomeView.swift @@ -141,7 +141,6 @@ struct Favorites_Previews: PreviewProvider { static var previews: some View { TabView { HomeView() -// .overlay(VideoPlayerView().injectFixtureEnvironmentObjects()) .injectFixtureEnvironmentObjects() .tabItem { Label("Home", systemImage: "house") diff --git a/Shared/Navigation/AppSidebarNavigation.swift b/Shared/Navigation/AppSidebarNavigation.swift index b0d6237f..04b30d4b 100644 --- a/Shared/Navigation/AppSidebarNavigation.swift +++ b/Shared/Navigation/AppSidebarNavigation.swift @@ -5,8 +5,6 @@ import SwiftUI #endif struct AppSidebarNavigation: View { - @Default(.showOpenActionsToolbarItem) private var showOpenActionsToolbarItem - @EnvironmentObject private var accounts @EnvironmentObject private var navigation @@ -23,6 +21,8 @@ struct AppSidebarNavigation: View { @EnvironmentObject private var thumbnailsModel #endif + @Default(.showOpenActionsToolbarItem) private var showOpenActionsToolbarItem + var body: some View { #if os(iOS) content.introspectViewController { viewController in diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift index feaeee57..3475dd19 100644 --- a/Shared/Navigation/ContentView.swift +++ b/Shared/Navigation/ContentView.swift @@ -121,16 +121,7 @@ struct ContentView: View { NavigationModel.shared.presentingOpenVideos = false } - .onOpenURL { - OpenURLHandler( - accounts: accounts, - navigation: navigation, - recents: recents, - player: player, - search: search, - navigationStyle: navigationStyle - ).handle($0) - } + .onOpenURL(perform: OpenURLHandler.shared.handle) .background( EmptyView().sheet(isPresented: $navigation.presentingAddToPlaylist) { AddToPlaylistView(video: navigation.videoToAddToPlaylist) diff --git a/Shared/Navigation/Sidebar.swift b/Shared/Navigation/Sidebar.swift index d0895031..22e602eb 100644 --- a/Shared/Navigation/Sidebar.swift +++ b/Shared/Navigation/Sidebar.swift @@ -47,7 +47,7 @@ struct Sidebar: View { Label("Home", systemImage: "house") .accessibility(label: Text("Home")) } - .id("favorites") + .id("home") } #if os(iOS) @@ -59,7 +59,6 @@ struct Sidebar: View { .id("documents") } #endif - } if !accounts.isEmpty { if visibleSections.contains(.subscriptions), diff --git a/Shared/OpenURLHandler.swift b/Shared/OpenURLHandler.swift index d27b207d..2db2960d 100644 --- a/Shared/OpenURLHandler.swift +++ b/Shared/OpenURLHandler.swift @@ -3,16 +3,25 @@ import Foundation import Siesta struct OpenURLHandler { + static var firstHandle = true + static var shared = OpenURLHandler() static let yatteeProtocol = "yattee://" - var accounts: AccountsModel - var navigation: NavigationModel - var recents: RecentsModel - var player: PlayerModel - var search: SearchModel + var accounts: AccountsModel! + var navigation: NavigationModel! + var recents: RecentsModel! + var player: PlayerModel! + var search: SearchModel! var navigationStyle = NavigationStyle.sidebar func handle(_ url: URL) { + if Self.firstHandle { + Self.firstHandle = false + + Delay.by(1) { Self.shared.handle(url) } + return + } + if accounts.current.isNil { accounts.setCurrent(accounts.any) } @@ -27,9 +36,7 @@ struct OpenURLHandler { } #endif - guard var url = urlByReplacingYatteeProtocol(url) else { - return - } + guard let url = urlByReplacingYatteeProtocol(url) else { return } let parser = URLParser(url: url) diff --git a/Shared/Player/PlayerQueueRow.swift b/Shared/Player/PlayerQueueRow.swift index d7c51b39..e17e563e 100644 --- a/Shared/Player/PlayerQueueRow.swift +++ b/Shared/Player/PlayerQueueRow.swift @@ -39,7 +39,6 @@ struct PlayerQueueRow: View { return } #endif - } if item.video.localStreamIsFile, let url = item.video.localStream?.localURL { URLBookmarkModel.shared.saveBookmark(url) diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index 19a60aab..8d4b70e3 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -57,14 +57,14 @@ struct VideoPlayerView: View { @State internal var orientationObserver: Any? #endif - @EnvironmentObject internal var accounts - @EnvironmentObject internal var navigation @EnvironmentObject internal var player - @EnvironmentObject internal var recents #if os(macOS) + @EnvironmentObject internal var navigation @EnvironmentObject internal var search #endif - @EnvironmentObject internal var thumbnails + #if os(tvOS) + @EnvironmentObject private var thumbnails + #endif @Default(.horizontalPlayerGestureEnabled) var horizontalPlayerGestureEnabled @Default(.seekGestureSpeed) var seekGestureSpeed @@ -107,15 +107,7 @@ struct VideoPlayerView: View { } } .alert(isPresented: $navigation.presentingAlertInVideoPlayer) { navigation.alert } - .onOpenURL { - OpenURLHandler( - accounts: accounts, - navigation: navigation, - recents: recents, - player: player, - search: search - ).handle($0) - } + .onOpenURL(perform: OpenURLHandler.shared.handle) .frame(minWidth: 950, minHeight: 700) #else return GeometryReader { geometry in diff --git a/Shared/Views/OpenVideosView.swift b/Shared/Views/OpenVideosView.swift index 4c639d03..60e76115 100644 --- a/Shared/Views/OpenVideosView.swift +++ b/Shared/Views/OpenVideosView.swift @@ -21,18 +21,20 @@ struct OpenVideosView: View { .frame(minWidth: 600, maxWidth: 800, minHeight: 350, maxHeight: 500) #else NavigationView { - openVideos - .toolbar { - ToolbarItem(placement: .navigationBarLeading) { - Button(action: { presentationMode.wrappedValue.dismiss() }) { - Label("Close", systemImage: "xmark") - } - #if !os(tvOS) - .keyboardShortcut(.cancelAction) - #endif + ScrollView(.vertical, showsIndicators: false) { + openVideos + } + .toolbar { + ToolbarItem(placement: .navigationBarLeading) { + Button(action: { presentationMode.wrappedValue.dismiss() }) { + Label("Close", systemImage: "xmark") } + #if !os(tvOS) + .keyboardShortcut(.cancelAction) + #endif } - .navigationTitle("Open Videos") + } + .navigationTitle("Open Videos") #if os(iOS) .navigationBarTitleDisplayMode(.inline) #endif diff --git a/Shared/Views/VideoContextMenuView.swift b/Shared/Views/VideoContextMenuView.swift index da039fb4..1f4adda3 100644 --- a/Shared/Views/VideoContextMenuView.swift +++ b/Shared/Views/VideoContextMenuView.swift @@ -226,12 +226,13 @@ struct VideoContextMenuView: View { } #if os(iOS) - private var removeDocumentButton: some View { - Button { + @ViewBuilder private var removeDocumentButton: some View { + let action = { if let url = video.localStream?.localURL { NavigationModel.shared.presentAlert( Alert( title: Text("Are you sure you want to remove this document?"), + message: Text(String(format: "\"%@\" will be irreversibly removed from this device.", video.displayTitle)), primaryButton: .destructive(Text("Remove")) { do { try DocumentsModel.shared.removeDocument(url) @@ -243,9 +244,14 @@ struct VideoContextMenuView: View { ) ) } - } label: { - Label("Remove...", systemImage: "trash.fill") - .foregroundColor(Color("AppRedColor")) + } + let label = Label("Remove...", systemImage: "trash.fill") + .foregroundColor(Color("AppRedColor")) + + if #available(iOS 15, macOS 12, *) { + Button(role: .destructive, action: action) { label } + } else { + Button(action: action) { label } } } #endif diff --git a/Shared/YatteeApp.swift b/Shared/YatteeApp.swift index e3183697..43d7558a 100644 --- a/Shared/YatteeApp.swift +++ b/Shared/YatteeApp.swift @@ -195,6 +195,14 @@ struct YatteeApp: App { PlayerModel.shared = player PlayerTimeModel.shared.player = player + #if !os(tvOS) + OpenURLHandler.shared.accounts = accounts + OpenURLHandler.shared.navigation = navigation + OpenURLHandler.shared.recents = recents + OpenURLHandler.shared.player = player + OpenURLHandler.shared.search = search + #endif + if !accounts.current.isNil { player.restoreQueue() }