Various minor fixes

This commit is contained in:
Arkadiusz Fal 2022-11-13 00:07:23 +01:00
parent 4657af2f3d
commit 61d235780d
12 changed files with 71 additions and 62 deletions

View File

@ -38,6 +38,10 @@ struct PlayerQueueItem: Hashable, Identifiable, Defaults.Serializable {
return false return false
} }
if duration <= 0 {
return false
}
return duration - seconds <= 20 return duration - seconds <= 20
} }

View File

@ -39,21 +39,23 @@ struct DocumentsView: View {
} }
.toolbar { .toolbar {
ToolbarItem(placement: .navigationBarLeading) { ToolbarItem(placement: .navigationBarLeading) {
Button { if model.canGoBack {
withAnimation { Button {
model.goBack() withAnimation {
} model.goBack()
} label: { }
HStack(spacing: 6) { } label: {
Label("Go back", systemImage: "chevron.left") 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) .navigationTitle(model.directoryLabel)
.padding() .padding(.horizontal)
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode) .navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
.backport .backport
.refreshable { .refreshable {

View File

@ -141,7 +141,6 @@ struct Favorites_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
TabView { TabView {
HomeView() HomeView()
// .overlay(VideoPlayerView().injectFixtureEnvironmentObjects())
.injectFixtureEnvironmentObjects() .injectFixtureEnvironmentObjects()
.tabItem { .tabItem {
Label("Home", systemImage: "house") Label("Home", systemImage: "house")

View File

@ -5,8 +5,6 @@ import SwiftUI
#endif #endif
struct AppSidebarNavigation: View { struct AppSidebarNavigation: View {
@Default(.showOpenActionsToolbarItem) private var showOpenActionsToolbarItem
@EnvironmentObject<AccountsModel> private var accounts @EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<NavigationModel> private var navigation @EnvironmentObject<NavigationModel> private var navigation
@ -23,6 +21,8 @@ struct AppSidebarNavigation: View {
@EnvironmentObject<ThumbnailsModel> private var thumbnailsModel @EnvironmentObject<ThumbnailsModel> private var thumbnailsModel
#endif #endif
@Default(.showOpenActionsToolbarItem) private var showOpenActionsToolbarItem
var body: some View { var body: some View {
#if os(iOS) #if os(iOS)
content.introspectViewController { viewController in content.introspectViewController { viewController in

View File

@ -121,16 +121,7 @@ struct ContentView: View {
NavigationModel.shared.presentingOpenVideos = false NavigationModel.shared.presentingOpenVideos = false
} }
.onOpenURL { .onOpenURL(perform: OpenURLHandler.shared.handle)
OpenURLHandler(
accounts: accounts,
navigation: navigation,
recents: recents,
player: player,
search: search,
navigationStyle: navigationStyle
).handle($0)
}
.background( .background(
EmptyView().sheet(isPresented: $navigation.presentingAddToPlaylist) { EmptyView().sheet(isPresented: $navigation.presentingAddToPlaylist) {
AddToPlaylistView(video: navigation.videoToAddToPlaylist) AddToPlaylistView(video: navigation.videoToAddToPlaylist)

View File

@ -47,7 +47,7 @@ struct Sidebar: View {
Label("Home", systemImage: "house") Label("Home", systemImage: "house")
.accessibility(label: Text("Home")) .accessibility(label: Text("Home"))
} }
.id("favorites") .id("home")
} }
#if os(iOS) #if os(iOS)
@ -59,7 +59,6 @@ struct Sidebar: View {
.id("documents") .id("documents")
} }
#endif #endif
}
if !accounts.isEmpty { if !accounts.isEmpty {
if visibleSections.contains(.subscriptions), if visibleSections.contains(.subscriptions),

View File

@ -3,16 +3,25 @@ import Foundation
import Siesta import Siesta
struct OpenURLHandler { struct OpenURLHandler {
static var firstHandle = true
static var shared = OpenURLHandler()
static let yatteeProtocol = "yattee://" static let yatteeProtocol = "yattee://"
var accounts: AccountsModel var accounts: AccountsModel!
var navigation: NavigationModel var navigation: NavigationModel!
var recents: RecentsModel var recents: RecentsModel!
var player: PlayerModel var player: PlayerModel!
var search: SearchModel var search: SearchModel!
var navigationStyle = NavigationStyle.sidebar var navigationStyle = NavigationStyle.sidebar
func handle(_ url: URL) { func handle(_ url: URL) {
if Self.firstHandle {
Self.firstHandle = false
Delay.by(1) { Self.shared.handle(url) }
return
}
if accounts.current.isNil { if accounts.current.isNil {
accounts.setCurrent(accounts.any) accounts.setCurrent(accounts.any)
} }
@ -27,9 +36,7 @@ struct OpenURLHandler {
} }
#endif #endif
guard var url = urlByReplacingYatteeProtocol(url) else { guard let url = urlByReplacingYatteeProtocol(url) else { return }
return
}
let parser = URLParser(url: url) let parser = URLParser(url: url)

View File

@ -39,7 +39,6 @@ struct PlayerQueueRow: View {
return return
} }
#endif #endif
}
if item.video.localStreamIsFile, let url = item.video.localStream?.localURL { if item.video.localStreamIsFile, let url = item.video.localStream?.localURL {
URLBookmarkModel.shared.saveBookmark(url) URLBookmarkModel.shared.saveBookmark(url)

View File

@ -57,14 +57,14 @@ struct VideoPlayerView: View {
@State internal var orientationObserver: Any? @State internal var orientationObserver: Any?
#endif #endif
@EnvironmentObject<AccountsModel> internal var accounts
@EnvironmentObject<NavigationModel> internal var navigation
@EnvironmentObject<PlayerModel> internal var player @EnvironmentObject<PlayerModel> internal var player
@EnvironmentObject<RecentsModel> internal var recents
#if os(macOS) #if os(macOS)
@EnvironmentObject<NavigationModel> internal var navigation
@EnvironmentObject<SearchModel> internal var search @EnvironmentObject<SearchModel> internal var search
#endif #endif
@EnvironmentObject<ThumbnailsModel> internal var thumbnails #if os(tvOS)
@EnvironmentObject<ThumbnailsModel> private var thumbnails
#endif
@Default(.horizontalPlayerGestureEnabled) var horizontalPlayerGestureEnabled @Default(.horizontalPlayerGestureEnabled) var horizontalPlayerGestureEnabled
@Default(.seekGestureSpeed) var seekGestureSpeed @Default(.seekGestureSpeed) var seekGestureSpeed
@ -107,15 +107,7 @@ struct VideoPlayerView: View {
} }
} }
.alert(isPresented: $navigation.presentingAlertInVideoPlayer) { navigation.alert } .alert(isPresented: $navigation.presentingAlertInVideoPlayer) { navigation.alert }
.onOpenURL { .onOpenURL(perform: OpenURLHandler.shared.handle)
OpenURLHandler(
accounts: accounts,
navigation: navigation,
recents: recents,
player: player,
search: search
).handle($0)
}
.frame(minWidth: 950, minHeight: 700) .frame(minWidth: 950, minHeight: 700)
#else #else
return GeometryReader { geometry in return GeometryReader { geometry in

View File

@ -21,18 +21,20 @@ struct OpenVideosView: View {
.frame(minWidth: 600, maxWidth: 800, minHeight: 350, maxHeight: 500) .frame(minWidth: 600, maxWidth: 800, minHeight: 350, maxHeight: 500)
#else #else
NavigationView { NavigationView {
openVideos ScrollView(.vertical, showsIndicators: false) {
.toolbar { openVideos
ToolbarItem(placement: .navigationBarLeading) { }
Button(action: { presentationMode.wrappedValue.dismiss() }) { .toolbar {
Label("Close", systemImage: "xmark") ToolbarItem(placement: .navigationBarLeading) {
} Button(action: { presentationMode.wrappedValue.dismiss() }) {
#if !os(tvOS) Label("Close", systemImage: "xmark")
.keyboardShortcut(.cancelAction)
#endif
} }
#if !os(tvOS)
.keyboardShortcut(.cancelAction)
#endif
} }
.navigationTitle("Open Videos") }
.navigationTitle("Open Videos")
#if os(iOS) #if os(iOS)
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
#endif #endif

View File

@ -226,12 +226,13 @@ struct VideoContextMenuView: View {
} }
#if os(iOS) #if os(iOS)
private var removeDocumentButton: some View { @ViewBuilder private var removeDocumentButton: some View {
Button { let action = {
if let url = video.localStream?.localURL { if let url = video.localStream?.localURL {
NavigationModel.shared.presentAlert( NavigationModel.shared.presentAlert(
Alert( Alert(
title: Text("Are you sure you want to remove this document?"), 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")) { primaryButton: .destructive(Text("Remove")) {
do { do {
try DocumentsModel.shared.removeDocument(url) try DocumentsModel.shared.removeDocument(url)
@ -243,9 +244,14 @@ struct VideoContextMenuView: View {
) )
) )
} }
} label: { }
Label("Remove...", systemImage: "trash.fill") let label = Label("Remove...", systemImage: "trash.fill")
.foregroundColor(Color("AppRedColor")) .foregroundColor(Color("AppRedColor"))
if #available(iOS 15, macOS 12, *) {
Button(role: .destructive, action: action) { label }
} else {
Button(action: action) { label }
} }
} }
#endif #endif

View File

@ -195,6 +195,14 @@ struct YatteeApp: App {
PlayerModel.shared = player PlayerModel.shared = player
PlayerTimeModel.shared.player = 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 { if !accounts.current.isNil {
player.restoreQueue() player.restoreQueue()
} }