Fix bookmarks

This commit is contained in:
Arkadiusz Fal
2022-12-04 13:21:50 +01:00
parent 220aef65ce
commit f1664d026c
12 changed files with 107 additions and 51 deletions

View File

@@ -2,5 +2,6 @@ import Foundation
import SwiftUI
struct Constants {
static let yatteeProtocol = "yattee://"
static let overlayAnimation = Animation.linear(duration: 0.2)
}

View File

@@ -10,7 +10,7 @@ struct DocumentsView: View {
NoDocumentsView()
} else {
ForEach(model.sortedDirectoryContents, id: \.absoluteString) { url in
let video = Video.local(model.replacePrivateVar(url) ?? url)
let video = Video.local(model.standardizedURL(url) ?? url)
PlayerQueueRow(
item: PlayerQueueItem(video)
)

View File

@@ -11,7 +11,7 @@ struct RecentDocumentsView: View {
NoDocumentsView()
} else {
ForEach(recentDocuments, id: \.absoluteString) { url in
let video = Video.local(model.replacePrivateVar(url) ?? url)
let video = Video.local(model.standardizedURL(url) ?? url)
PlayerQueueRow(
item: PlayerQueueItem(video)
)

View File

@@ -95,7 +95,10 @@ struct ContentView: View {
NavigationModel.shared.presentingOpenVideos = false
}
.onOpenURL(perform: OpenURLHandler.shared.handle)
.onOpenURL { url in
URLBookmarkModel.shared.saveBookmark(url)
OpenURLHandler.shared.handle(url)
}
.background(
EmptyView().sheet(isPresented: $navigation.presentingAddToPlaylist) {
AddToPlaylistView(video: navigation.videoToAddToPlaylist)

View File

@@ -36,7 +36,7 @@ struct OpenURLHandler {
}
#endif
guard let url = urlByReplacingYatteeProtocol(url) else { return }
guard let url = url.byReplacingYatteeProtocol() else { return }
let parser = URLParser(url: url)
@@ -93,21 +93,6 @@ struct OpenURLHandler {
navigation.presentingOpenVideos = false
}
private func urlByReplacingYatteeProtocol(_ url: URL, with urlProtocol: String = "https") -> URL! {
var urlAbsoluteString = url.absoluteString
guard urlAbsoluteString.hasPrefix(Self.yatteeProtocol) else {
return url
}
urlAbsoluteString = String(urlAbsoluteString.dropFirst(Self.yatteeProtocol.count))
if url.absoluteString.contains("://") {
return URL(string: urlAbsoluteString)
}
return URL(string: "\(urlProtocol)://\(urlAbsoluteString)")
}
private func handleFileURLOpen(_ parser: URLParser) {
guard let url = parser.fileURL else { return }

View File

@@ -109,7 +109,10 @@ struct VideoPlayerView: View {
}
}
.alert(isPresented: $navigation.presentingAlertInVideoPlayer) { navigation.alert }
.onOpenURL(perform: OpenURLHandler.shared.handle)
.onOpenURL { url in
URLBookmarkModel.shared.saveBookmark(url)
OpenURLHandler.shared.handle(url)
}
.frame(minWidth: 950, minHeight: 700)
#else
return GeometryReader { geometry in