From 14b146291f1252c86d79cd42d46e43e6a351c0bd Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Sat, 21 May 2022 10:17:54 -0700 Subject: [PATCH 1/9] create a PDFItem struct that can be used by PDFViewer --- .../App/PDFSupport/PDFViewerViewModel.swift | 20 +++++++-------- .../Components/FeedCardNavigationLink.swift | 2 +- .../App/Views/LinkItemDetailView.swift | 8 +++--- .../App/Views/RootView/RootViewModel.swift | 4 +-- .../Sources/Models/DataModels/PDFItem.swift | 25 +++++++++++++++++++ apple/Sources/PDFViewer.swift | 8 +++--- 6 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 apple/OmnivoreKit/Sources/Models/DataModels/PDFItem.swift diff --git a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift index 094ec4e4d..f8510a545 100644 --- a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift @@ -8,15 +8,15 @@ public final class PDFViewerViewModel: ObservableObject { @Published public var errorMessage: String? @Published public var readerView: Bool = false - public var linkedItem: LinkedItem + public let pdfItem: PDFItem private var storedURL: URL? var subscriptions = Set() let services: Services - public init(services: Services, linkedItem: LinkedItem) { + public init(services: Services, pdfItem: PDFItem) { self.services = services - self.linkedItem = linkedItem + self.pdfItem = pdfItem } public func dataURL(remoteURL: URL) -> URL { @@ -24,9 +24,9 @@ public final class PDFViewerViewModel: ObservableObject { return storedURL } - guard let data = linkedItem.pdfData else { return remoteURL } + guard let data = pdfItem.documentData else { return remoteURL } - let subPath = linkedItem.unwrappedTitle.isEmpty ? UUID().uuidString : linkedItem.unwrappedTitle + let subPath = pdfItem.title.isEmpty ? UUID().uuidString : pdfItem.title let path = FileManager.default .urls(for: .cachesDirectory, in: .userDomainMask)[0] @@ -42,7 +42,7 @@ public final class PDFViewerViewModel: ObservableObject { } public func loadHighlightPatches(completion onComplete: @escaping ([String]) -> Void) { - onComplete(linkedItem.highlights.asArray(of: Highlight.self).map { $0.patch ?? "" }) + onComplete(pdfItem.highlights.map { $0.patch ?? "" }) } public func createHighlight(shortId: String, highlightID: String, quote: String, patch: String) { @@ -51,7 +51,7 @@ public final class PDFViewerViewModel: ObservableObject { highlightID: highlightID, quote: quote, patch: patch, - articleId: linkedItem.unwrappedID + articleId: pdfItem.itemID ) } @@ -67,7 +67,7 @@ public final class PDFViewerViewModel: ObservableObject { highlightID: highlightID, quote: quote, patch: patch, - articleId: linkedItem.unwrappedID, + articleId: pdfItem.itemID, overlapHighlightIdList: overlapHighlightIdList ) } @@ -80,7 +80,7 @@ public final class PDFViewerViewModel: ObservableObject { public func updateItemReadProgress(percent: Double, anchorIndex: Int) { services.dataService.updateLinkReadingProgress( - itemID: linkedItem.unwrappedID, + itemID: pdfItem.itemID, readingProgress: percent, anchorIndex: anchorIndex ) @@ -91,7 +91,7 @@ public final class PDFViewerViewModel: ObservableObject { var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false) if let username = services.dataService.currentViewer?.username { - components?.path = "/\(username)/\(linkedItem.unwrappedSlug)/highlights/\(shortId)" + components?.path = "/\(username)/\(pdfItem.slug)/highlights/\(shortId)" } else { return nil } diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift index 895216be8..a1326b292 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift @@ -6,7 +6,7 @@ import Views struct FeedCardNavigationLink: View { @EnvironmentObject var dataService: DataService - @ObservedObject var item: LinkedItem + let item: LinkedItem @ObservedObject var viewModel: HomeFeedViewModel diff --git a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift index e25217235..4646b1822 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift @@ -6,10 +6,11 @@ import Utils import Views enum PDFProvider { - static var pdfViewerProvider: ((URL, LinkedItem) -> AnyView)? + static var pdfViewerProvider: ((URL, PDFItem) -> AnyView)? } @MainActor final class LinkItemDetailViewModel: ObservableObject { + let pdfItem: PDFItem? @Published var item: LinkedItem @Published var webAppWrapperViewModel: WebAppWrapperViewModel? @@ -17,6 +18,7 @@ enum PDFProvider { init(item: LinkedItem) { self.item = item + self.pdfItem = PDFItem.make(item: item) } func handleArchiveAction(dataService: DataService) { @@ -277,9 +279,9 @@ struct LinkItemDetailView: View { #endif @ViewBuilder private var fixedNavBarReader: some View { - if let pdfURL = viewModel.item.pdfURL { + if let pdfURL = viewModel.item.pdfURL, let pdfItem = viewModel.pdfItem { #if os(iOS) - PDFProvider.pdfViewerProvider?(pdfURL, viewModel.item) + PDFProvider.pdfViewerProvider?(pdfURL, pdfItem) .navigationBarTitleDisplayMode(.inline) #elseif os(macOS) PDFWrapperView(pdfURL: pdfURL) diff --git a/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift index cb037610f..400ac7564 100644 --- a/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift @@ -35,9 +35,9 @@ public final class RootViewModel: ObservableObject { func configurePDFProvider(pdfViewerProvider: @escaping (URL, PDFViewerViewModel) -> AnyView) { guard PDFProvider.pdfViewerProvider == nil else { return } - PDFProvider.pdfViewerProvider = { [weak self] url, linkedItem in + PDFProvider.pdfViewerProvider = { [weak self] url, pdfItem in guard let self = self else { return AnyView(Text("")) } - return pdfViewerProvider(url, PDFViewerViewModel(services: self.services, linkedItem: linkedItem)) + return pdfViewerProvider(url, PDFViewerViewModel(services: self.services, pdfItem: pdfItem)) } } diff --git a/apple/OmnivoreKit/Sources/Models/DataModels/PDFItem.swift b/apple/OmnivoreKit/Sources/Models/DataModels/PDFItem.swift new file mode 100644 index 000000000..f9d99c6c5 --- /dev/null +++ b/apple/OmnivoreKit/Sources/Models/DataModels/PDFItem.swift @@ -0,0 +1,25 @@ +import Foundation + +public struct PDFItem { + public let itemID: String + public let documentData: Data? + public let title: String + public let slug: String + public let readingProgress: Double + public let readingProgressAnchor: Int + public let highlights: [Highlight] + + public static func make(item: LinkedItem) -> PDFItem? { + guard item.isPDF else { return nil } + + return PDFItem( + itemID: item.unwrappedID, + documentData: item.pdfData, + title: item.unwrappedID, + slug: item.unwrappedSlug, + readingProgress: item.readingProgress, + readingProgressAnchor: Int(item.readingProgressAnchor), + highlights: item.highlights.asArray(of: Highlight.self) + ) + } +} diff --git a/apple/Sources/PDFViewer.swift b/apple/Sources/PDFViewer.swift index 9bfff9d70..520cc538e 100644 --- a/apple/Sources/PDFViewer.swift +++ b/apple/Sources/PDFViewer.swift @@ -70,8 +70,8 @@ import Utils coordinator.viewer = self - if viewModel.linkedItem.readingProgressAnchor > 0 { - let pageIndex = UInt(viewModel.linkedItem.readingProgressAnchor) + if viewModel.pdfItem.readingProgressAnchor > 0 { + let pageIndex = UInt(viewModel.pdfItem.readingProgressAnchor) controller.setPageIndex(pageIndex, animated: false) } @@ -145,7 +145,7 @@ import Utils let pageIndex = Int(event.pageIndex) if let totalPageCount = controller.document?.pageCount { let percent = min(100, max(0, ((Double(pageIndex) + 1.0) / Double(totalPageCount)) * 100.0)) - if percent > self.viewModel.linkedItem.readingProgress { + if percent > self.viewModel.pdfItem.readingProgress { self.viewModel.updateItemReadProgress(percent: percent, anchorIndex: pageIndex) } } @@ -199,7 +199,7 @@ import Utils "id": highlightID, "shortId": shortId, "quote": quote, - "articleId": viewModel.linkedItem.unwrappedID + "articleId": viewModel.pdfItem.itemID ] ] document.add(annotations: [highlight]) From 8139664083770c9a4f89806888d736d51efb0bb6 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Sat, 21 May 2022 15:56:27 -0700 Subject: [PATCH 2/9] pass pdfitem to LinkItemDetailView when item is a pdf --- .../Components/FeedCardNavigationLink.swift | 10 ++-- .../App/Views/Home/HomeFeedViewIOS.swift | 2 +- .../App/Views/Home/HomeFeedViewModel.swift | 2 +- .../App/Views/LinkItemDetailView.swift | 55 ++++++++++++------- .../Sources/Models/DataModels/PDFItem.swift | 11 ++++ 5 files changed, 54 insertions(+), 26 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift index a1326b292..a92404771 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift @@ -11,7 +11,7 @@ struct FeedCardNavigationLink: View { @ObservedObject var viewModel: HomeFeedViewModel var body: some View { - let destination = LinkItemDetailView(viewModel: LinkItemDetailViewModel(item: item)) + let destination = LinkItemDetailView(viewModel: LinkItemDetailViewModel(item: item, pdfItem: PDFItem.make(item: item))) #if os(iOS) let modifiedDestination = destination .navigationTitle("") @@ -22,7 +22,7 @@ struct FeedCardNavigationLink: View { return ZStack { NavigationLink( destination: modifiedDestination, - tag: item, + tag: item.objectID, selection: $viewModel.selectedLinkItem ) { EmptyView() @@ -50,7 +50,7 @@ struct GridCardNavigationLink: View { @ObservedObject var viewModel: HomeFeedViewModel var body: some View { - let destination = LinkItemDetailView(viewModel: LinkItemDetailViewModel(item: item)) + let destination = LinkItemDetailView(viewModel: LinkItemDetailViewModel(item: item, pdfItem: PDFItem.make(item: item))) #if os(iOS) let modifiedDestination = destination .navigationTitle("") @@ -61,7 +61,7 @@ struct GridCardNavigationLink: View { return ZStack { NavigationLink( destination: modifiedDestination, - tag: item, + tag: item.objectID, selection: $viewModel.selectedLinkItem ) { EmptyView() @@ -71,7 +71,7 @@ struct GridCardNavigationLink: View { scale = 0.95 DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(150)) { scale = 1.0 - viewModel.selectedLinkItem = item + viewModel.selectedLinkItem = item.objectID } } }) diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift index ee531e593..b0dbe5304 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift @@ -101,7 +101,7 @@ private let enableGrid = UIDevice.isIPad || FeatureFlag.enableGridCardsOnPhone guard let objectID = dataService.persist(jsonArticle: jsonArticle) else { return } guard let linkedItem = dataService.viewContext.object(with: objectID) as? LinkedItem else { return } viewModel.pushFeedItem(item: linkedItem) - viewModel.selectedLinkItem = linkedItem + viewModel.selectedLinkItem = linkedItem.objectID } .onOpenURL { url in withoutAnimation { diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift index c11d66d2c..8b2db340f 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift @@ -19,7 +19,7 @@ import Views @Published var negatedLabels = [LinkedItemLabel]() @Published var snoozePresented = false @Published var itemToSnoozeID: String? - @Published var selectedLinkItem: LinkedItem? + @Published var selectedLinkItem: NSManagedObjectID? @Published var linkRequest: LinkRequest? @Published var showLoadingBar = false diff --git a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift index 4646b1822..bd4560a5b 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift @@ -11,30 +11,34 @@ enum PDFProvider { @MainActor final class LinkItemDetailViewModel: ObservableObject { let pdfItem: PDFItem? - @Published var item: LinkedItem + let item: LinkedItem? @Published var webAppWrapperViewModel: WebAppWrapperViewModel? var subscriptions = Set() - init(item: LinkedItem) { + init(item: LinkedItem?, pdfItem: PDFItem?) { self.item = item - self.pdfItem = PDFItem.make(item: item) + self.pdfItem = pdfItem } func handleArchiveAction(dataService: DataService) { - dataService.archiveLink(objectID: item.objectID, archived: !item.isArchived) - Snackbar.show(message: !item.isArchived ? "Link archived" : "Link moved to Inbox") + guard let objectID = item?.objectID ?? pdfItem?.objectID else { return } + dataService.archiveLink(objectID: objectID, archived: !isItemArchived) + Snackbar.show(message: !isItemArchived ? "Link archived" : "Link moved to Inbox") } func handleDeleteAction(dataService: DataService) { + guard let objectID = item?.objectID ?? pdfItem?.objectID else { return } Snackbar.show(message: "Link removed") - dataService.removeLink(objectID: item.objectID) + dataService.removeLink(objectID: objectID) } func updateItemReadStatus(dataService: DataService) { + guard let itemID = item?.unwrappedID ?? pdfItem?.itemID else { return } + dataService.updateLinkReadingProgress( - itemID: item.unwrappedID, - readingProgress: item.isRead ? 0 : 100, + itemID: itemID, + readingProgress: isItemRead ? 0 : 100, anchorIndex: 0 ) } @@ -66,21 +70,34 @@ enum PDFProvider { } func trackReadEvent() { + guard let itemID = item?.unwrappedID ?? pdfItem?.itemID else { return } + guard let slug = item?.unwrappedSlug ?? pdfItem?.slug else { return } + guard let originalArticleURL = item?.unwrappedPageURLString ?? pdfItem?.originalArticleURL else { return } + EventTracker.track( .linkRead( - linkID: item.unwrappedID, - slug: item.unwrappedSlug, - originalArticleURL: item.unwrappedPageURLString + linkID: itemID, + slug: slug, + originalArticleURL: originalArticleURL ) ) } + var isItemRead: Bool { + item?.isRead ?? pdfItem?.isRead ?? false + } + + var isItemArchived: Bool { + item?.isArchived ?? pdfItem?.isArchived ?? false + } + private func createWebAppWrapperViewModel(username: String, dataService: DataService, rawAuthCookie: String?) { + guard let slug = item?.unwrappedSlug ?? pdfItem?.slug else { return } let baseURL = dataService.appEnvironment.webAppBaseURL let urlRequest = URLRequest.webRequest( baseURL: dataService.appEnvironment.webAppBaseURL, - urlPath: "/app/\(username)/\(item.unwrappedSlug)", + urlPath: "/app/\(username)/\(slug)", queryParams: ["isAppEmbedView": "true", "highlightBarDisabled": isMacApp ? "false" : "true"] ) @@ -113,7 +130,7 @@ struct LinkItemDetailView: View { viewModel.updateItemReadStatus(dataService: dataService) }, label: { - Image(systemName: viewModel.item.isRead ? "line.horizontal.3.decrease.circle" : "checkmark.circle") + Image(systemName: viewModel.isItemRead ? "line.horizontal.3.decrease.circle" : "checkmark.circle") } ) } @@ -141,15 +158,15 @@ struct LinkItemDetailView: View { var body: some View { #if os(iOS) - if viewModel.item.isPDF { + if viewModel.pdfItem != nil { fixedNavBarReader .navigationBarHidden(hideNavBar) .task { hideNavBar = true viewModel.trackReadEvent() } - } else { - WebReaderContainerView(item: viewModel.item) + } else if let item = viewModel.item { + WebReaderContainerView(item: item) .navigationBarHidden(hideNavBar) .task { hideNavBar = true @@ -191,8 +208,8 @@ struct LinkItemDetailView: View { action: { viewModel.handleArchiveAction(dataService: dataService) }, label: { Label( - viewModel.item.isArchived ? "Unarchive" : "Archive", - systemImage: viewModel.item.isArchived ? "tray.and.arrow.down.fill" : "archivebox" + viewModel.isItemArchived ? "Unarchive" : "Archive", + systemImage: viewModel.isItemArchived ? "tray.and.arrow.down.fill" : "archivebox" ) } ) @@ -279,7 +296,7 @@ struct LinkItemDetailView: View { #endif @ViewBuilder private var fixedNavBarReader: some View { - if let pdfURL = viewModel.item.pdfURL, let pdfItem = viewModel.pdfItem { + if let pdfItem = viewModel.pdfItem, let pdfURL = pdfItem.pdfURL { #if os(iOS) PDFProvider.pdfViewerProvider?(pdfURL, pdfItem) .navigationBarTitleDisplayMode(.inline) diff --git a/apple/OmnivoreKit/Sources/Models/DataModels/PDFItem.swift b/apple/OmnivoreKit/Sources/Models/DataModels/PDFItem.swift index f9d99c6c5..2953a2f73 100644 --- a/apple/OmnivoreKit/Sources/Models/DataModels/PDFItem.swift +++ b/apple/OmnivoreKit/Sources/Models/DataModels/PDFItem.swift @@ -1,24 +1,35 @@ +import CoreData import Foundation public struct PDFItem { + public let objectID: NSManagedObjectID public let itemID: String + public let pdfURL: URL? public let documentData: Data? public let title: String public let slug: String public let readingProgress: Double public let readingProgressAnchor: Int + public let isArchived: Bool + public let isRead: Bool + public let originalArticleURL: String public let highlights: [Highlight] public static func make(item: LinkedItem) -> PDFItem? { guard item.isPDF else { return nil } return PDFItem( + objectID: item.objectID, itemID: item.unwrappedID, + pdfURL: URL(string: item.unwrappedPageURLString), documentData: item.pdfData, title: item.unwrappedID, slug: item.unwrappedSlug, readingProgress: item.readingProgress, readingProgressAnchor: Int(item.readingProgressAnchor), + isArchived: item.isArchived, + isRead: item.isRead, + originalArticleURL: item.unwrappedPageURLString, highlights: item.highlights.asArray(of: Highlight.self) ) } From 86eaef4d5888798346b14af34be89c489331fb47 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Sun, 22 May 2022 08:04:43 -0700 Subject: [PATCH 3/9] add local pspdfkit package --- apple/LocalPSPDFKit/Package.swift | 29 ++ apple/Omnivore.xcodeproj/project.pbxproj | 19 +- .../xcshareddata/swiftpm/Package.resolved | 429 +++++++++--------- apple/OmnivoreKit/Package.swift | 5 +- 4 files changed, 245 insertions(+), 237 deletions(-) create mode 100644 apple/LocalPSPDFKit/Package.swift diff --git a/apple/LocalPSPDFKit/Package.swift b/apple/LocalPSPDFKit/Package.swift new file mode 100644 index 000000000..019269d28 --- /dev/null +++ b/apple/LocalPSPDFKit/Package.swift @@ -0,0 +1,29 @@ +// swift-tools-version:5.5 + +import PackageDescription + +let package = Package( + name: "PSPDFKit", + platforms: [ + .iOS(.v15), + .macOS("99.0") + ], + products: [ + .library( + name: "PSPDFKit", + targets: ["PSPDFKit", "PSPDFKitUI"] + ) + ], + targets: [ + .binaryTarget( + name: "PSPDFKit", + url: "https://customers.pspdfkit.com/pspdfkit/xcframework/11.2.0.zip", + checksum: "e70261d3938fb99955bd8a89bd20a691c9024d573e0fcf9fa53fd4a797cc10fb" + ), + .binaryTarget( + name: "PSPDFKitUI", + url: "https://customers.pspdfkit.com/pspdfkitui/xcframework/11.2.0.zip", + checksum: "f4e757c4067921b469d910fc8babb6e9445b189c53aca378ef943960806f22dd" + ) + ] +) diff --git a/apple/Omnivore.xcodeproj/project.pbxproj b/apple/Omnivore.xcodeproj/project.pbxproj index 223e4eabc..76d2f839c 100644 --- a/apple/Omnivore.xcodeproj/project.pbxproj +++ b/apple/Omnivore.xcodeproj/project.pbxproj @@ -10,7 +10,6 @@ 0411792A26A22860004AE24F /* MacAppSmokeTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0411792926A22860004AE24F /* MacAppSmokeTest.swift */; }; 0418837E2742E99F003E0001 /* Intercom in Frameworks */ = {isa = PBXBuildFile; productRef = 0418837D2742E99F003E0001 /* Intercom */; }; 041883802742FCF2003E0001 /* Utils in Frameworks */ = {isa = PBXBuildFile; productRef = 0418837F2742FCF2003E0001 /* Utils */; }; - 042184ED273AD426002357B0 /* PSPDFKit in Frameworks */ = {isa = PBXBuildFile; productRef = 042184EC273AD426002357B0 /* PSPDFKit */; }; 042184EF273AD5F3002357B0 /* PDFViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 042184EE273AD5F3002357B0 /* PDFViewer.swift */; }; 042184F0273AD5F3002357B0 /* PDFViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 042184EE273AD5F3002357B0 /* PDFViewer.swift */; }; 042F48DC26DFD10E00BF98FC /* iOSLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 042F48DB26DFD10E00BF98FC /* iOSLaunchTests.swift */; }; @@ -188,6 +187,7 @@ 042F48D926DFD10E00BF98FC /* UITests-iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UITests-iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 042F48DB26DFD10E00BF98FC /* iOSLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSLaunchTests.swift; sourceTree = ""; }; 042F48DD26DFD10E00BF98FC /* iOSUITests.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = iOSUITests.plist; sourceTree = ""; }; + 04501446283A861300BD138D /* LocalPSPDFKit */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = LocalPSPDFKit; sourceTree = ""; }; 046C5CD226A3F89A00AC5349 /* ShareExtension-Mac.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "ShareExtension-Mac.appex"; sourceTree = BUILT_PRODUCTS_DIR; }; 046C5CD426A3F89A00AC5349 /* icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = icon.icns; sourceTree = ""; }; 046C5CDB26A3F89A00AC5349 /* ShareExtensionMac.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = ShareExtensionMac.plist; sourceTree = ""; }; @@ -315,7 +315,6 @@ 0418837E2742E99F003E0001 /* Intercom in Frameworks */, 045B1681279147E7005047F7 /* FirebaseMessaging in Frameworks */, 041883802742FCF2003E0001 /* Utils in Frameworks */, - 042184ED273AD426002357B0 /* PSPDFKit in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -420,6 +419,7 @@ 2EE5B57B588CF4ADBA39A106 = { isa = PBXGroup; children = ( + 04501446283A861300BD138D /* LocalPSPDFKit */, 047AD6F62724E513004FD5CF /* SafariExtension (iOS)Release.entitlements */, 047AD6F52724CF8A004FD5CF /* SafariExtension (iOS).entitlements */, 0480E70B26D8A07A006CAE2F /* Omnivore-Mac.xctestplan */, @@ -719,7 +719,6 @@ name = "Omnivore-iOS"; packageProductDependencies = ( 8F13016D33DF1598D7157563 /* App */, - 042184EC273AD426002357B0 /* PSPDFKit */, 0418837D2742E99F003E0001 /* Intercom */, 0418837F2742FCF2003E0001 /* Utils */, 045B1680279147E7005047F7 /* FirebaseMessaging */, @@ -796,7 +795,6 @@ ); mainGroup = 2EE5B57B588CF4ADBA39A106; packageReferences = ( - 042184EB273AD426002357B0 /* XCRemoteSwiftPackageReference "PSPDFKit-SP" */, 0418837C2742E99F003E0001 /* XCRemoteSwiftPackageReference "intercom-ios" */, 048F592A2790EAF800E0B494 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */, ); @@ -1964,14 +1962,6 @@ version = 11.1.2; }; }; - 042184EB273AD426002357B0 /* XCRemoteSwiftPackageReference "PSPDFKit-SP" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/PSPDFKit/PSPDFKit-SP"; - requirement = { - branch = master; - kind = branch; - }; - }; 048F592A2790EAF800E0B494 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/firebase/firebase-ios-sdk"; @@ -1992,11 +1982,6 @@ isa = XCSwiftPackageProductDependency; productName = Utils; }; - 042184EC273AD426002357B0 /* PSPDFKit */ = { - isa = XCSwiftPackageProductDependency; - package = 042184EB273AD426002357B0 /* XCRemoteSwiftPackageReference "PSPDFKit-SP" */; - productName = PSPDFKit; - }; 045B1680279147E7005047F7 /* FirebaseMessaging */ = { isa = XCSwiftPackageProductDependency; package = 048F592A2790EAF800E0B494 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; diff --git a/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved b/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved index 4f826f753..0e27d329f 100644 --- a/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,221 +1,214 @@ { - "pins" : [ - { - "identity" : "abseil-cpp-swiftpm", - "kind" : "remoteSourceControl", - "location" : "https://github.com/firebase/abseil-cpp-SwiftPM.git", - "state" : { - "revision" : "fffc3c2729be5747390ad02d5100291a0d9ad26a", - "version" : "0.20200225.4" + "object": { + "pins": [ + { + "package": "abseil", + "repositoryURL": "https://github.com/firebase/abseil-cpp-SwiftPM.git", + "state": { + "branch": null, + "revision": "fffc3c2729be5747390ad02d5100291a0d9ad26a", + "version": "0.20200225.4" + } + }, + { + "package": "Segment", + "repositoryURL": "git@github.com:segmentio/analytics-swift.git", + "state": { + "branch": null, + "revision": "92cc824211160ab98c28c7d40c1e6d27645c2bf1", + "version": "1.2.3" + } + }, + { + "package": "AppAuth", + "repositoryURL": "https://github.com/openid/AppAuth-iOS.git", + "state": { + "branch": null, + "revision": "01131d68346c8ae552961c768d583c715fbe1410", + "version": "1.4.0" + } + }, + { + "package": "BoringSSL-GRPC", + "repositoryURL": "https://github.com/firebase/boringssl-SwiftPM.git", + "state": { + "branch": null, + "revision": "734a8247442fde37df4364c21f6a0085b6a36728", + "version": "0.7.2" + } + }, + { + "package": "Files", + "repositoryURL": "https://github.com/JohnSundell/Files", + "state": { + "branch": null, + "revision": "d273b5b7025d386feef79ef6bad7de762e106eaf", + "version": "4.2.0" + } + }, + { + "package": "Firebase", + "repositoryURL": "https://github.com/firebase/firebase-ios-sdk", + "state": { + "branch": null, + "revision": "08686f04881483d2bc098b2696e674c0ba135e47", + "version": "8.10.0" + } + }, + { + "package": "GoogleAppMeasurement", + "repositoryURL": "https://github.com/google/GoogleAppMeasurement.git", + "state": { + "branch": null, + "revision": "9b2f6aca5b4685c45f9f5481f19bee8e7982c538", + "version": "8.9.1" + } + }, + { + "package": "GoogleDataTransport", + "repositoryURL": "https://github.com/google/GoogleDataTransport.git", + "state": { + "branch": null, + "revision": "15ccdfd25ac55b9239b82809531ff26605e7556e", + "version": "9.1.2" + } + }, + { + "package": "GoogleUtilities", + "repositoryURL": "https://github.com/google/GoogleUtilities.git", + "state": { + "branch": null, + "revision": "b3bb0c5551fb3f80ca939829639ab5b093edd14f", + "version": "7.7.0" + } + }, + { + "package": "gRPC", + "repositoryURL": "https://github.com/firebase/grpc-SwiftPM.git", + "state": { + "branch": null, + "revision": "fb405dd2c7901485f7e158b24e3a0a47e4efd8b5", + "version": "1.28.4" + } + }, + { + "package": "GTMSessionFetcher", + "repositoryURL": "https://github.com/google/gtm-session-fetcher.git", + "state": { + "branch": null, + "revision": "bc6a19702ac76ac4e488b68148710eb815f9bc56", + "version": "1.7.0" + } + }, + { + "package": "Intercom", + "repositoryURL": "https://github.com/intercom/intercom-ios", + "state": { + "branch": null, + "revision": "3345d9e7599141d7c844981423a7e5409f2bfb81", + "version": "11.1.2" + } + }, + { + "package": "leveldb", + "repositoryURL": "https://github.com/firebase/leveldb.git", + "state": { + "branch": null, + "revision": "0706abcc6b0bd9cedfbb015ba840e4a780b5159b", + "version": "1.22.2" + } + }, + { + "package": "nanopb", + "repositoryURL": "https://github.com/firebase/nanopb.git", + "state": { + "branch": null, + "revision": "7ee9ef9f627d85cbe1b8c4f49a3ed26eed216c77", + "version": "2.30908.0" + } + }, + { + "package": "Promises", + "repositoryURL": "https://github.com/google/promises.git", + "state": { + "branch": null, + "revision": "611337c330350c9c1823ad6d671e7f936af5ee13", + "version": "2.0.0" + } + }, + { + "package": "Sovran", + "repositoryURL": "https://github.com/segmentio/Sovran-Swift.git", + "state": { + "branch": null, + "revision": "944c17d7c46bd95fc37f09136cabd172be5b413b", + "version": "1.0.3" + } + }, + { + "package": "swift-argument-parser", + "repositoryURL": "https://github.com/apple/swift-argument-parser", + "state": { + "branch": null, + "revision": "e1465042f195f374b94f915ba8ca49de24300a0d", + "version": "1.0.2" + } + }, + { + "package": "swift-graphql", + "repositoryURL": "https://github.com/maticzav/swift-graphql", + "state": { + "branch": null, + "revision": "b1fad45d10194e865685150fedad9ef0845fb254", + "version": "2.3.1" + } + }, + { + "package": "SwiftProtobuf", + "repositoryURL": "https://github.com/apple/swift-protobuf.git", + "state": { + "branch": null, + "revision": "7e2c5f3cbbeea68e004915e3a8961e20bd11d824", + "version": "1.18.0" + } + }, + { + "package": "SwiftFormat", + "repositoryURL": "https://github.com/nicklockwood/SwiftFormat", + "state": { + "branch": null, + "revision": "872e7034f54aeee3f20acf790ecc13e1383f7360", + "version": "0.48.4" + } + }, + { + "package": "Introspect", + "repositoryURL": "https://github.com/siteline/SwiftUI-Introspect.git", + "state": { + "branch": null, + "revision": "f2616860a41f9d9932da412a8978fec79c06fe24", + "version": "0.1.4" + } + }, + { + "package": "Valet", + "repositoryURL": "https://github.com/Square/Valet", + "state": { + "branch": null, + "revision": "2bf3329055f5d71d42a12801dd69d1d770fafa5e", + "version": "4.1.2" + } + }, + { + "package": "Yams", + "repositoryURL": "https://github.com/jpsim/Yams.git", + "state": { + "branch": null, + "revision": "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa", + "version": "4.0.6" + } } - }, - { - "identity" : "analytics-swift", - "kind" : "remoteSourceControl", - "location" : "git@github.com:segmentio/analytics-swift.git", - "state" : { - "revision" : "92cc824211160ab98c28c7d40c1e6d27645c2bf1", - "version" : "1.2.3" - } - }, - { - "identity" : "appauth-ios", - "kind" : "remoteSourceControl", - "location" : "https://github.com/openid/AppAuth-iOS.git", - "state" : { - "revision" : "01131d68346c8ae552961c768d583c715fbe1410", - "version" : "1.4.0" - } - }, - { - "identity" : "boringssl-swiftpm", - "kind" : "remoteSourceControl", - "location" : "https://github.com/firebase/boringssl-SwiftPM.git", - "state" : { - "revision" : "734a8247442fde37df4364c21f6a0085b6a36728", - "version" : "0.7.2" - } - }, - { - "identity" : "files", - "kind" : "remoteSourceControl", - "location" : "https://github.com/JohnSundell/Files", - "state" : { - "revision" : "d273b5b7025d386feef79ef6bad7de762e106eaf", - "version" : "4.2.0" - } - }, - { - "identity" : "firebase-ios-sdk", - "kind" : "remoteSourceControl", - "location" : "https://github.com/firebase/firebase-ios-sdk", - "state" : { - "revision" : "08686f04881483d2bc098b2696e674c0ba135e47", - "version" : "8.10.0" - } - }, - { - "identity" : "googleappmeasurement", - "kind" : "remoteSourceControl", - "location" : "https://github.com/google/GoogleAppMeasurement.git", - "state" : { - "revision" : "9b2f6aca5b4685c45f9f5481f19bee8e7982c538", - "version" : "8.9.1" - } - }, - { - "identity" : "googledatatransport", - "kind" : "remoteSourceControl", - "location" : "https://github.com/google/GoogleDataTransport.git", - "state" : { - "revision" : "15ccdfd25ac55b9239b82809531ff26605e7556e", - "version" : "9.1.2" - } - }, - { - "identity" : "googleutilities", - "kind" : "remoteSourceControl", - "location" : "https://github.com/google/GoogleUtilities.git", - "state" : { - "revision" : "b3bb0c5551fb3f80ca939829639ab5b093edd14f", - "version" : "7.7.0" - } - }, - { - "identity" : "grpc-swiftpm", - "kind" : "remoteSourceControl", - "location" : "https://github.com/firebase/grpc-SwiftPM.git", - "state" : { - "revision" : "fb405dd2c7901485f7e158b24e3a0a47e4efd8b5", - "version" : "1.28.4" - } - }, - { - "identity" : "gtm-session-fetcher", - "kind" : "remoteSourceControl", - "location" : "https://github.com/google/gtm-session-fetcher.git", - "state" : { - "revision" : "bc6a19702ac76ac4e488b68148710eb815f9bc56", - "version" : "1.7.0" - } - }, - { - "identity" : "intercom-ios", - "kind" : "remoteSourceControl", - "location" : "https://github.com/intercom/intercom-ios", - "state" : { - "revision" : "3345d9e7599141d7c844981423a7e5409f2bfb81", - "version" : "11.1.2" - } - }, - { - "identity" : "leveldb", - "kind" : "remoteSourceControl", - "location" : "https://github.com/firebase/leveldb.git", - "state" : { - "revision" : "0706abcc6b0bd9cedfbb015ba840e4a780b5159b", - "version" : "1.22.2" - } - }, - { - "identity" : "nanopb", - "kind" : "remoteSourceControl", - "location" : "https://github.com/firebase/nanopb.git", - "state" : { - "revision" : "7ee9ef9f627d85cbe1b8c4f49a3ed26eed216c77", - "version" : "2.30908.0" - } - }, - { - "identity" : "promises", - "kind" : "remoteSourceControl", - "location" : "https://github.com/google/promises.git", - "state" : { - "revision" : "611337c330350c9c1823ad6d671e7f936af5ee13", - "version" : "2.0.0" - } - }, - { - "identity" : "pspdfkit-sp", - "kind" : "remoteSourceControl", - "location" : "https://github.com/PSPDFKit/PSPDFKit-SP", - "state" : { - "branch" : "master", - "revision" : "344c895fea62eb42c6b56e6a060d5dff73cc5bc2" - } - }, - { - "identity" : "sovran-swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/segmentio/Sovran-Swift.git", - "state" : { - "revision" : "944c17d7c46bd95fc37f09136cabd172be5b413b", - "version" : "1.0.3" - } - }, - { - "identity" : "swift-argument-parser", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-argument-parser", - "state" : { - "revision" : "e1465042f195f374b94f915ba8ca49de24300a0d", - "version" : "1.0.2" - } - }, - { - "identity" : "swift-graphql", - "kind" : "remoteSourceControl", - "location" : "https://github.com/maticzav/swift-graphql", - "state" : { - "revision" : "b1fad45d10194e865685150fedad9ef0845fb254", - "version" : "2.3.1" - } - }, - { - "identity" : "swift-protobuf", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-protobuf.git", - "state" : { - "revision" : "7e2c5f3cbbeea68e004915e3a8961e20bd11d824", - "version" : "1.18.0" - } - }, - { - "identity" : "swiftformat", - "kind" : "remoteSourceControl", - "location" : "https://github.com/nicklockwood/SwiftFormat", - "state" : { - "revision" : "872e7034f54aeee3f20acf790ecc13e1383f7360", - "version" : "0.48.4" - } - }, - { - "identity" : "swiftui-introspect", - "kind" : "remoteSourceControl", - "location" : "https://github.com/siteline/SwiftUI-Introspect.git", - "state" : { - "revision" : "f2616860a41f9d9932da412a8978fec79c06fe24", - "version" : "0.1.4" - } - }, - { - "identity" : "valet", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Square/Valet", - "state" : { - "revision" : "2bf3329055f5d71d42a12801dd69d1d770fafa5e", - "version" : "4.1.2" - } - }, - { - "identity" : "yams", - "kind" : "remoteSourceControl", - "location" : "https://github.com/jpsim/Yams.git", - "state" : { - "revision" : "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa", - "version" : "4.0.6" - } - } - ], - "version" : 2 + ] + }, + "version": 1 } diff --git a/apple/OmnivoreKit/Package.swift b/apple/OmnivoreKit/Package.swift index 1897ffaa7..fb073c60d 100644 --- a/apple/OmnivoreKit/Package.swift +++ b/apple/OmnivoreKit/Package.swift @@ -21,10 +21,11 @@ let package = Package( .package(url: "https://github.com/Square/Valet", from: "4.1.2"), .package(url: "https://github.com/maticzav/swift-graphql", from: "2.3.1"), .package(url: "https://github.com/siteline/SwiftUI-Introspect.git", from: "0.1.4"), - .package(url: "git@github.com:segmentio/analytics-swift.git", .upToNextMajor(from: "1.0.0")) + .package(url: "git@github.com:segmentio/analytics-swift.git", .upToNextMajor(from: "1.0.0")), + .package(path: "../LocalPSPDFKit") ], targets: [ - .target(name: "App", dependencies: ["Views", "Services", "Models", "Utils"]), + .target(name: "App", dependencies: ["Views", "Services", "Models", "Utils", .product(name: "PSPDFKit", package: "LocalPSPDFKit")]), .testTarget(name: "AppTests", dependencies: ["App"]), .target( name: "Views", From 89e9519322c8fc03d7ca4abc1e888e900e0496a9 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Sun, 22 May 2022 09:35:17 -0700 Subject: [PATCH 4/9] import pspsdfkit for ios only --- apple/LocalPSPDFKit/Package.swift | 29 -- apple/Omnivore.xcodeproj/project.pbxproj | 2 - .../xcshareddata/swiftpm/Package.resolved | 420 +++++++++--------- apple/OmnivoreKit/Package.swift | 33 +- apple/OmnivoreKit/Sources/App/Services.swift | 95 ++-- .../App/Views/Home/HomeFeedViewIOS.swift | 4 +- .../Sources/App/Views/RootView/RootView.swift | 4 +- .../OmnivoreKit/Sources/Views/SearchBar.swift | 2 +- apple/Sources/PDFReaderView.swift | 1 + 9 files changed, 288 insertions(+), 302 deletions(-) delete mode 100644 apple/LocalPSPDFKit/Package.swift diff --git a/apple/LocalPSPDFKit/Package.swift b/apple/LocalPSPDFKit/Package.swift deleted file mode 100644 index 019269d28..000000000 --- a/apple/LocalPSPDFKit/Package.swift +++ /dev/null @@ -1,29 +0,0 @@ -// swift-tools-version:5.5 - -import PackageDescription - -let package = Package( - name: "PSPDFKit", - platforms: [ - .iOS(.v15), - .macOS("99.0") - ], - products: [ - .library( - name: "PSPDFKit", - targets: ["PSPDFKit", "PSPDFKitUI"] - ) - ], - targets: [ - .binaryTarget( - name: "PSPDFKit", - url: "https://customers.pspdfkit.com/pspdfkit/xcframework/11.2.0.zip", - checksum: "e70261d3938fb99955bd8a89bd20a691c9024d573e0fcf9fa53fd4a797cc10fb" - ), - .binaryTarget( - name: "PSPDFKitUI", - url: "https://customers.pspdfkit.com/pspdfkitui/xcframework/11.2.0.zip", - checksum: "f4e757c4067921b469d910fc8babb6e9445b189c53aca378ef943960806f22dd" - ) - ] -) diff --git a/apple/Omnivore.xcodeproj/project.pbxproj b/apple/Omnivore.xcodeproj/project.pbxproj index 76d2f839c..8da7796bd 100644 --- a/apple/Omnivore.xcodeproj/project.pbxproj +++ b/apple/Omnivore.xcodeproj/project.pbxproj @@ -187,7 +187,6 @@ 042F48D926DFD10E00BF98FC /* UITests-iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UITests-iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 042F48DB26DFD10E00BF98FC /* iOSLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSLaunchTests.swift; sourceTree = ""; }; 042F48DD26DFD10E00BF98FC /* iOSUITests.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = iOSUITests.plist; sourceTree = ""; }; - 04501446283A861300BD138D /* LocalPSPDFKit */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = LocalPSPDFKit; sourceTree = ""; }; 046C5CD226A3F89A00AC5349 /* ShareExtension-Mac.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "ShareExtension-Mac.appex"; sourceTree = BUILT_PRODUCTS_DIR; }; 046C5CD426A3F89A00AC5349 /* icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = icon.icns; sourceTree = ""; }; 046C5CDB26A3F89A00AC5349 /* ShareExtensionMac.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = ShareExtensionMac.plist; sourceTree = ""; }; @@ -419,7 +418,6 @@ 2EE5B57B588CF4ADBA39A106 = { isa = PBXGroup; children = ( - 04501446283A861300BD138D /* LocalPSPDFKit */, 047AD6F62724E513004FD5CF /* SafariExtension (iOS)Release.entitlements */, 047AD6F52724CF8A004FD5CF /* SafariExtension (iOS).entitlements */, 0480E70B26D8A07A006CAE2F /* Omnivore-Mac.xctestplan */, diff --git a/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved b/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved index 0e27d329f..e79bf771f 100644 --- a/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,214 +1,212 @@ { - "object": { - "pins": [ - { - "package": "abseil", - "repositoryURL": "https://github.com/firebase/abseil-cpp-SwiftPM.git", - "state": { - "branch": null, - "revision": "fffc3c2729be5747390ad02d5100291a0d9ad26a", - "version": "0.20200225.4" - } - }, - { - "package": "Segment", - "repositoryURL": "git@github.com:segmentio/analytics-swift.git", - "state": { - "branch": null, - "revision": "92cc824211160ab98c28c7d40c1e6d27645c2bf1", - "version": "1.2.3" - } - }, - { - "package": "AppAuth", - "repositoryURL": "https://github.com/openid/AppAuth-iOS.git", - "state": { - "branch": null, - "revision": "01131d68346c8ae552961c768d583c715fbe1410", - "version": "1.4.0" - } - }, - { - "package": "BoringSSL-GRPC", - "repositoryURL": "https://github.com/firebase/boringssl-SwiftPM.git", - "state": { - "branch": null, - "revision": "734a8247442fde37df4364c21f6a0085b6a36728", - "version": "0.7.2" - } - }, - { - "package": "Files", - "repositoryURL": "https://github.com/JohnSundell/Files", - "state": { - "branch": null, - "revision": "d273b5b7025d386feef79ef6bad7de762e106eaf", - "version": "4.2.0" - } - }, - { - "package": "Firebase", - "repositoryURL": "https://github.com/firebase/firebase-ios-sdk", - "state": { - "branch": null, - "revision": "08686f04881483d2bc098b2696e674c0ba135e47", - "version": "8.10.0" - } - }, - { - "package": "GoogleAppMeasurement", - "repositoryURL": "https://github.com/google/GoogleAppMeasurement.git", - "state": { - "branch": null, - "revision": "9b2f6aca5b4685c45f9f5481f19bee8e7982c538", - "version": "8.9.1" - } - }, - { - "package": "GoogleDataTransport", - "repositoryURL": "https://github.com/google/GoogleDataTransport.git", - "state": { - "branch": null, - "revision": "15ccdfd25ac55b9239b82809531ff26605e7556e", - "version": "9.1.2" - } - }, - { - "package": "GoogleUtilities", - "repositoryURL": "https://github.com/google/GoogleUtilities.git", - "state": { - "branch": null, - "revision": "b3bb0c5551fb3f80ca939829639ab5b093edd14f", - "version": "7.7.0" - } - }, - { - "package": "gRPC", - "repositoryURL": "https://github.com/firebase/grpc-SwiftPM.git", - "state": { - "branch": null, - "revision": "fb405dd2c7901485f7e158b24e3a0a47e4efd8b5", - "version": "1.28.4" - } - }, - { - "package": "GTMSessionFetcher", - "repositoryURL": "https://github.com/google/gtm-session-fetcher.git", - "state": { - "branch": null, - "revision": "bc6a19702ac76ac4e488b68148710eb815f9bc56", - "version": "1.7.0" - } - }, - { - "package": "Intercom", - "repositoryURL": "https://github.com/intercom/intercom-ios", - "state": { - "branch": null, - "revision": "3345d9e7599141d7c844981423a7e5409f2bfb81", - "version": "11.1.2" - } - }, - { - "package": "leveldb", - "repositoryURL": "https://github.com/firebase/leveldb.git", - "state": { - "branch": null, - "revision": "0706abcc6b0bd9cedfbb015ba840e4a780b5159b", - "version": "1.22.2" - } - }, - { - "package": "nanopb", - "repositoryURL": "https://github.com/firebase/nanopb.git", - "state": { - "branch": null, - "revision": "7ee9ef9f627d85cbe1b8c4f49a3ed26eed216c77", - "version": "2.30908.0" - } - }, - { - "package": "Promises", - "repositoryURL": "https://github.com/google/promises.git", - "state": { - "branch": null, - "revision": "611337c330350c9c1823ad6d671e7f936af5ee13", - "version": "2.0.0" - } - }, - { - "package": "Sovran", - "repositoryURL": "https://github.com/segmentio/Sovran-Swift.git", - "state": { - "branch": null, - "revision": "944c17d7c46bd95fc37f09136cabd172be5b413b", - "version": "1.0.3" - } - }, - { - "package": "swift-argument-parser", - "repositoryURL": "https://github.com/apple/swift-argument-parser", - "state": { - "branch": null, - "revision": "e1465042f195f374b94f915ba8ca49de24300a0d", - "version": "1.0.2" - } - }, - { - "package": "swift-graphql", - "repositoryURL": "https://github.com/maticzav/swift-graphql", - "state": { - "branch": null, - "revision": "b1fad45d10194e865685150fedad9ef0845fb254", - "version": "2.3.1" - } - }, - { - "package": "SwiftProtobuf", - "repositoryURL": "https://github.com/apple/swift-protobuf.git", - "state": { - "branch": null, - "revision": "7e2c5f3cbbeea68e004915e3a8961e20bd11d824", - "version": "1.18.0" - } - }, - { - "package": "SwiftFormat", - "repositoryURL": "https://github.com/nicklockwood/SwiftFormat", - "state": { - "branch": null, - "revision": "872e7034f54aeee3f20acf790ecc13e1383f7360", - "version": "0.48.4" - } - }, - { - "package": "Introspect", - "repositoryURL": "https://github.com/siteline/SwiftUI-Introspect.git", - "state": { - "branch": null, - "revision": "f2616860a41f9d9932da412a8978fec79c06fe24", - "version": "0.1.4" - } - }, - { - "package": "Valet", - "repositoryURL": "https://github.com/Square/Valet", - "state": { - "branch": null, - "revision": "2bf3329055f5d71d42a12801dd69d1d770fafa5e", - "version": "4.1.2" - } - }, - { - "package": "Yams", - "repositoryURL": "https://github.com/jpsim/Yams.git", - "state": { - "branch": null, - "revision": "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa", - "version": "4.0.6" - } + "pins" : [ + { + "identity" : "abseil-cpp-swiftpm", + "kind" : "remoteSourceControl", + "location" : "https://github.com/firebase/abseil-cpp-SwiftPM.git", + "state" : { + "revision" : "fffc3c2729be5747390ad02d5100291a0d9ad26a", + "version" : "0.20200225.4" } - ] - }, - "version": 1 + }, + { + "identity" : "analytics-swift", + "kind" : "remoteSourceControl", + "location" : "git@github.com:segmentio/analytics-swift.git", + "state" : { + "revision" : "92cc824211160ab98c28c7d40c1e6d27645c2bf1", + "version" : "1.2.3" + } + }, + { + "identity" : "appauth-ios", + "kind" : "remoteSourceControl", + "location" : "https://github.com/openid/AppAuth-iOS.git", + "state" : { + "revision" : "01131d68346c8ae552961c768d583c715fbe1410", + "version" : "1.4.0" + } + }, + { + "identity" : "boringssl-swiftpm", + "kind" : "remoteSourceControl", + "location" : "https://github.com/firebase/boringssl-SwiftPM.git", + "state" : { + "revision" : "734a8247442fde37df4364c21f6a0085b6a36728", + "version" : "0.7.2" + } + }, + { + "identity" : "files", + "kind" : "remoteSourceControl", + "location" : "https://github.com/JohnSundell/Files", + "state" : { + "revision" : "d273b5b7025d386feef79ef6bad7de762e106eaf", + "version" : "4.2.0" + } + }, + { + "identity" : "firebase-ios-sdk", + "kind" : "remoteSourceControl", + "location" : "https://github.com/firebase/firebase-ios-sdk", + "state" : { + "revision" : "08686f04881483d2bc098b2696e674c0ba135e47", + "version" : "8.10.0" + } + }, + { + "identity" : "googleappmeasurement", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/GoogleAppMeasurement.git", + "state" : { + "revision" : "9b2f6aca5b4685c45f9f5481f19bee8e7982c538", + "version" : "8.9.1" + } + }, + { + "identity" : "googledatatransport", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/GoogleDataTransport.git", + "state" : { + "revision" : "15ccdfd25ac55b9239b82809531ff26605e7556e", + "version" : "9.1.2" + } + }, + { + "identity" : "googleutilities", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/GoogleUtilities.git", + "state" : { + "revision" : "b3bb0c5551fb3f80ca939829639ab5b093edd14f", + "version" : "7.7.0" + } + }, + { + "identity" : "grpc-swiftpm", + "kind" : "remoteSourceControl", + "location" : "https://github.com/firebase/grpc-SwiftPM.git", + "state" : { + "revision" : "fb405dd2c7901485f7e158b24e3a0a47e4efd8b5", + "version" : "1.28.4" + } + }, + { + "identity" : "gtm-session-fetcher", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/gtm-session-fetcher.git", + "state" : { + "revision" : "bc6a19702ac76ac4e488b68148710eb815f9bc56", + "version" : "1.7.0" + } + }, + { + "identity" : "intercom-ios", + "kind" : "remoteSourceControl", + "location" : "https://github.com/intercom/intercom-ios", + "state" : { + "revision" : "3345d9e7599141d7c844981423a7e5409f2bfb81", + "version" : "11.1.2" + } + }, + { + "identity" : "leveldb", + "kind" : "remoteSourceControl", + "location" : "https://github.com/firebase/leveldb.git", + "state" : { + "revision" : "0706abcc6b0bd9cedfbb015ba840e4a780b5159b", + "version" : "1.22.2" + } + }, + { + "identity" : "nanopb", + "kind" : "remoteSourceControl", + "location" : "https://github.com/firebase/nanopb.git", + "state" : { + "revision" : "7ee9ef9f627d85cbe1b8c4f49a3ed26eed216c77", + "version" : "2.30908.0" + } + }, + { + "identity" : "promises", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/promises.git", + "state" : { + "revision" : "611337c330350c9c1823ad6d671e7f936af5ee13", + "version" : "2.0.0" + } + }, + { + "identity" : "sovran-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/segmentio/Sovran-Swift.git", + "state" : { + "revision" : "944c17d7c46bd95fc37f09136cabd172be5b413b", + "version" : "1.0.3" + } + }, + { + "identity" : "swift-argument-parser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-argument-parser", + "state" : { + "revision" : "e1465042f195f374b94f915ba8ca49de24300a0d", + "version" : "1.0.2" + } + }, + { + "identity" : "swift-graphql", + "kind" : "remoteSourceControl", + "location" : "https://github.com/maticzav/swift-graphql", + "state" : { + "revision" : "b1fad45d10194e865685150fedad9ef0845fb254", + "version" : "2.3.1" + } + }, + { + "identity" : "swift-protobuf", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-protobuf.git", + "state" : { + "revision" : "7e2c5f3cbbeea68e004915e3a8961e20bd11d824", + "version" : "1.18.0" + } + }, + { + "identity" : "swiftformat", + "kind" : "remoteSourceControl", + "location" : "https://github.com/nicklockwood/SwiftFormat", + "state" : { + "revision" : "872e7034f54aeee3f20acf790ecc13e1383f7360", + "version" : "0.48.4" + } + }, + { + "identity" : "swiftui-introspect", + "kind" : "remoteSourceControl", + "location" : "https://github.com/siteline/SwiftUI-Introspect.git", + "state" : { + "revision" : "f2616860a41f9d9932da412a8978fec79c06fe24", + "version" : "0.1.4" + } + }, + { + "identity" : "valet", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Square/Valet", + "state" : { + "revision" : "2bf3329055f5d71d42a12801dd69d1d770fafa5e", + "version" : "4.1.2" + } + }, + { + "identity" : "yams", + "kind" : "remoteSourceControl", + "location" : "https://github.com/jpsim/Yams.git", + "state" : { + "revision" : "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa", + "version" : "4.0.6" + } + } + ], + "version" : 2 } diff --git a/apple/OmnivoreKit/Package.swift b/apple/OmnivoreKit/Package.swift index fb073c60d..1eafb078f 100644 --- a/apple/OmnivoreKit/Package.swift +++ b/apple/OmnivoreKit/Package.swift @@ -16,16 +16,9 @@ let package = Package( .library(name: "Models", targets: ["Models"]), .library(name: "Utils", targets: ["Utils"]) ], - dependencies: [ - .package(url: "https://github.com/openid/AppAuth-iOS.git", .upToNextMajor(from: "1.4.0")), - .package(url: "https://github.com/Square/Valet", from: "4.1.2"), - .package(url: "https://github.com/maticzav/swift-graphql", from: "2.3.1"), - .package(url: "https://github.com/siteline/SwiftUI-Introspect.git", from: "0.1.4"), - .package(url: "git@github.com:segmentio/analytics-swift.git", .upToNextMajor(from: "1.0.0")), - .package(path: "../LocalPSPDFKit") - ], + dependencies: dependencies, targets: [ - .target(name: "App", dependencies: ["Views", "Services", "Models", "Utils", .product(name: "PSPDFKit", package: "LocalPSPDFKit")]), + .target(name: "App", dependencies: appPackageDependencies), .testTarget(name: "AppTests", dependencies: ["App"]), .target( name: "Views", @@ -59,3 +52,25 @@ let package = Package( .testTarget(name: "UtilsTests", dependencies: ["Utils"]) ] ) + +var appPackageDependencies: [Target.Dependency] { + var deps: [Target.Dependency] = ["Views", "Services", "Models", "Utils"] + #if canImport(UIKit) + deps.append(.product(name: "PSPDFKit", package: "PSPDFKit-SP")) + #endif + return deps +} + +var dependencies: [Package.Dependency] { + var deps: [Package.Dependency] = [ + .package(url: "https://github.com/openid/AppAuth-iOS.git", .upToNextMajor(from: "1.4.0")), + .package(url: "https://github.com/Square/Valet", from: "4.1.2"), + .package(url: "https://github.com/maticzav/swift-graphql", from: "2.3.1"), + .package(url: "https://github.com/siteline/SwiftUI-Introspect.git", from: "0.1.4"), + .package(url: "git@github.com:segmentio/analytics-swift.git", .upToNextMajor(from: "1.0.0")) + ] + #if canImport(UIKit) + deps.append(.package(url: "https://github.com/PSPDFKit/PSPDFKit-SP", branch: "master")) + #endif + return deps +} diff --git a/apple/OmnivoreKit/Sources/App/Services.swift b/apple/OmnivoreKit/Sources/App/Services.swift index c12951763..1a8d6ad59 100644 --- a/apple/OmnivoreKit/Sources/App/Services.swift +++ b/apple/OmnivoreKit/Sources/App/Services.swift @@ -20,61 +20,62 @@ public final class Services { } } -// Background fetching functions -extension Services { - public static func registerBackgroundFetch() { - BGTaskScheduler.shared.register(forTaskWithIdentifier: fetchTaskID, using: nil) { task in - if let task = task as? BGAppRefreshTask { - EventTracker.trackForDebugging("executing app.omnivore.fetchLinkedItems bg task") - logger.debug("in background task register closure") - performBackgroundFetch(task: task) +#if os(iOS) + // Background fetching functions + extension Services { + public static func registerBackgroundFetch() { + BGTaskScheduler.shared.register(forTaskWithIdentifier: fetchTaskID, using: nil) { task in + if let task = task as? BGAppRefreshTask { + EventTracker.trackForDebugging("executing app.omnivore.fetchLinkedItems bg task") + logger.debug("in background task register closure") + performBackgroundFetch(task: task) + } } } - } - static func scheduleBackgroundFetch() { - BGTaskScheduler.shared.cancelAllTaskRequests() - let taskRequest = BGAppRefreshTaskRequest(identifier: fetchTaskID) - taskRequest.earliestBeginDate = Date(timeIntervalSinceNow: secondsToWaitBeforeNextBackgroundRefresh) + static func scheduleBackgroundFetch() { + BGTaskScheduler.shared.cancelAllTaskRequests() + let taskRequest = BGAppRefreshTaskRequest(identifier: fetchTaskID) + taskRequest.earliestBeginDate = Date(timeIntervalSinceNow: secondsToWaitBeforeNextBackgroundRefresh) - do { - try BGTaskScheduler.shared.submit(taskRequest) - logger.debug("\(fetchTaskID) task scheduled") - } catch { - logger.debug("task scheduling failed: \(fetchTaskID)") - } - } - - static func performBackgroundFetch(task: BGAppRefreshTask) { - Services.logger.debug("starting background fetch") - scheduleBackgroundFetch() - let services = Services() - - task.expirationHandler = { - EventTracker.trackForDebugging("background fetch expiration handler called") - logger.debug("handling background fetch expiration") - } - - guard services.authenticator.hasValidAuthToken else { - EventTracker.trackForDebugging("background fetch failed: user does not have a valid auth token") - Services.logger.debug("background fetch failed: user does not habe a valid auth token") - task.setTaskCompleted(success: false) - return - } - - Task { do { - try await services.dataService.fetchLinkedItemsBackgroundTask() - logger.debug("fetch complete") - EventTracker.trackForDebugging("background fetch task completed successfully") - task.setTaskCompleted(success: true) + try BGTaskScheduler.shared.submit(taskRequest) + logger.debug("\(fetchTaskID) task scheduled") } catch { - logger.debug("fetch failed") - EventTracker.trackForDebugging("background fetch task failed") + logger.debug("task scheduling failed: \(fetchTaskID)") + } + } + + static func performBackgroundFetch(task: BGAppRefreshTask) { + Services.logger.debug("starting background fetch") + scheduleBackgroundFetch() + let services = Services() + + task.expirationHandler = { + EventTracker.trackForDebugging("background fetch expiration handler called") + logger.debug("handling background fetch expiration") + } + + guard services.authenticator.hasValidAuthToken else { + EventTracker.trackForDebugging("background fetch failed: user does not have a valid auth token") + Services.logger.debug("background fetch failed: user does not habe a valid auth token") task.setTaskCompleted(success: false) + return + } + + Task { + do { + try await services.dataService.fetchLinkedItemsBackgroundTask() + logger.debug("fetch complete") + EventTracker.trackForDebugging("background fetch task completed successfully") + task.setTaskCompleted(success: true) + } catch { + logger.debug("fetch failed") + EventTracker.trackForDebugging("background fetch task failed") + task.setTaskCompleted(success: false) + } } } } -} - +#endif // e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"app.omnivore.fetchLinkedItems"] diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift index b0dbe5304..745e1447e 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift @@ -5,9 +5,9 @@ import UserNotifications import Utils import Views -private let enableGrid = UIDevice.isIPad || FeatureFlag.enableGridCardsOnPhone - #if os(iOS) + private let enableGrid = UIDevice.isIPad || FeatureFlag.enableGridCardsOnPhone + struct HomeFeedContainerView: View { @EnvironmentObject var dataService: DataService @AppStorage(UserDefaultKey.homeFeedlayoutPreference.rawValue) var prefersListLayout = false diff --git a/apple/OmnivoreKit/Sources/App/Views/RootView/RootView.swift b/apple/OmnivoreKit/Sources/App/Views/RootView/RootView.swift index 4261c20a1..ad53ded07 100644 --- a/apple/OmnivoreKit/Sources/App/Views/RootView/RootView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/RootView/RootView.swift @@ -34,7 +34,9 @@ public struct RootView: View { } .onChange(of: scenePhase) { phase in if phase == .background { - Services.scheduleBackgroundFetch() + #if os(iOS) + Services.scheduleBackgroundFetch() + #endif } } } diff --git a/apple/OmnivoreKit/Sources/Views/SearchBar.swift b/apple/OmnivoreKit/Sources/Views/SearchBar.swift index 7c7e02a4f..40dd39e73 100644 --- a/apple/OmnivoreKit/Sources/Views/SearchBar.swift +++ b/apple/OmnivoreKit/Sources/Views/SearchBar.swift @@ -15,7 +15,7 @@ public struct SearchBar: View { TextField("Search", text: $searchTerm) .padding(7) .padding(.horizontal, 25) - .background(Color(.systemGray6)) + .background(Color.systemGray6) .cornerRadius(8) .focused($isFocused) .overlay( diff --git a/apple/Sources/PDFReaderView.swift b/apple/Sources/PDFReaderView.swift index 59131fb55..2dad14846 100644 --- a/apple/Sources/PDFReaderView.swift +++ b/apple/Sources/PDFReaderView.swift @@ -4,6 +4,7 @@ import Utils import WebKit #if os(iOS) + import App import PSPDFKit import PSPDFKitUI From 3f68a179c818f984997497cfe3d9e5f213dcf030 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Sun, 22 May 2022 10:15:14 -0700 Subject: [PATCH 5/9] remove pdfproviders --- apple/Omnivore.xcodeproj/project.pbxproj | 18 -------- .../Sources/App/PDFSupport}/NanoID.swift | 0 .../App/PDFSupport}/PDFReaderView.swift | 16 ++++--- .../Sources/App/PDFSupport}/PDFViewer.swift | 43 +++++++++++++------ .../App/PDFSupport/PDFViewerViewModel.swift | 31 +++++++------ .../App/Views/LinkItemDetailView.swift | 6 +-- .../Sources/App/Views/RootView/RootView.swift | 17 +++----- .../App/Views/RootView/RootViewModel.swift | 9 ---- apple/Sources/MainApp.swift | 15 +------ 9 files changed, 66 insertions(+), 89 deletions(-) rename apple/{Sources => OmnivoreKit/Sources/App/PDFSupport}/NanoID.swift (100%) rename apple/{Sources => OmnivoreKit/Sources/App/PDFSupport}/PDFReaderView.swift (87%) rename apple/{Sources => OmnivoreKit/Sources/App/PDFSupport}/PDFViewer.swift (90%) diff --git a/apple/Omnivore.xcodeproj/project.pbxproj b/apple/Omnivore.xcodeproj/project.pbxproj index 8da7796bd..083e78b94 100644 --- a/apple/Omnivore.xcodeproj/project.pbxproj +++ b/apple/Omnivore.xcodeproj/project.pbxproj @@ -10,8 +10,6 @@ 0411792A26A22860004AE24F /* MacAppSmokeTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0411792926A22860004AE24F /* MacAppSmokeTest.swift */; }; 0418837E2742E99F003E0001 /* Intercom in Frameworks */ = {isa = PBXBuildFile; productRef = 0418837D2742E99F003E0001 /* Intercom */; }; 041883802742FCF2003E0001 /* Utils in Frameworks */ = {isa = PBXBuildFile; productRef = 0418837F2742FCF2003E0001 /* Utils */; }; - 042184EF273AD5F3002357B0 /* PDFViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 042184EE273AD5F3002357B0 /* PDFViewer.swift */; }; - 042184F0273AD5F3002357B0 /* PDFViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 042184EE273AD5F3002357B0 /* PDFViewer.swift */; }; 042F48DC26DFD10E00BF98FC /* iOSLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 042F48DB26DFD10E00BF98FC /* iOSLaunchTests.swift */; }; 045B1681279147E7005047F7 /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = 045B1680279147E7005047F7 /* FirebaseMessaging */; }; 0465B9BE26CDD35F005558CD /* MainApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D81BE98F0CB588F5FC577A13 /* MainApp.swift */; }; @@ -43,10 +41,6 @@ 42321E882714E6B00056429F /* styles in Resources */ = {isa = PBXBuildFile; fileRef = 42321E832714E6B00056429F /* styles */; }; 42321E892714E6B00056429F /* views in Resources */ = {isa = PBXBuildFile; fileRef = 42321E842714E6B00056429F /* views */; }; 42321E8A2714E6B00056429F /* views in Resources */ = {isa = PBXBuildFile; fileRef = 42321E842714E6B00056429F /* views */; }; - 4255C6D82755A5350006422A /* NanoID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4255C6D72755A5350006422A /* NanoID.swift */; }; - 4255C6D92755A5350006422A /* NanoID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4255C6D72755A5350006422A /* NanoID.swift */; }; - 426408732744676C00A2AE46 /* PDFReaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 426408722744676B00A2AE46 /* PDFReaderView.swift */; }; - 426408742744676C00A2AE46 /* PDFReaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 426408722744676B00A2AE46 /* PDFReaderView.swift */; }; 42FF1B33271154A700B38C38 /* SafariWebExtensionHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42FF1AEB271154A600B38C38 /* SafariWebExtensionHandler.swift */; }; 42FF1B34271154A700B38C38 /* SafariWebExtensionHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42FF1AEB271154A600B38C38 /* SafariWebExtensionHandler.swift */; }; 42FF1B35271154A700B38C38 /* _locales in Resources */ = {isa = PBXBuildFile; fileRef = 42FF1AED271154A600B38C38 /* _locales */; }; @@ -183,7 +177,6 @@ 0411792726A22860004AE24F /* UnitTests-MacApp.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UnitTests-MacApp.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 0411792926A22860004AE24F /* MacAppSmokeTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacAppSmokeTest.swift; sourceTree = ""; }; 0411792B26A22860004AE24F /* MacUnitTests.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = MacUnitTests.plist; sourceTree = ""; }; - 042184EE273AD5F3002357B0 /* PDFViewer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFViewer.swift; sourceTree = ""; }; 042F48D926DFD10E00BF98FC /* UITests-iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UITests-iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 042F48DB26DFD10E00BF98FC /* iOSLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSLaunchTests.swift; sourceTree = ""; }; 042F48DD26DFD10E00BF98FC /* iOSUITests.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = iOSUITests.plist; sourceTree = ""; }; @@ -214,8 +207,6 @@ 42321E822714E6B00056429F /* scripts */ = {isa = PBXFileReference; lastKnownFileType = folder; path = scripts; sourceTree = ""; }; 42321E832714E6B00056429F /* styles */ = {isa = PBXFileReference; lastKnownFileType = folder; path = styles; sourceTree = ""; }; 42321E842714E6B00056429F /* views */ = {isa = PBXFileReference; lastKnownFileType = folder; path = views; sourceTree = ""; }; - 4255C6D72755A5350006422A /* NanoID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NanoID.swift; sourceTree = ""; }; - 426408722744676B00A2AE46 /* PDFReaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFReaderView.swift; sourceTree = ""; }; 42FF1AEB271154A600B38C38 /* SafariWebExtensionHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariWebExtensionHandler.swift; sourceTree = ""; }; 42FF1AED271154A600B38C38 /* _locales */ = {isa = PBXFileReference; lastKnownFileType = folder; path = _locales; sourceTree = ""; }; 42FF1AEE271154A600B38C38 /* images */ = {isa = PBXFileReference; lastKnownFileType = folder; path = images; sourceTree = ""; }; @@ -476,9 +467,6 @@ children = ( 0480E71B26D95096006CAE2F /* AppDelegate.swift */, D81BE98F0CB588F5FC577A13 /* MainApp.swift */, - 042184EE273AD5F3002357B0 /* PDFViewer.swift */, - 426408722744676B00A2AE46 /* PDFReaderView.swift */, - 4255C6D72755A5350006422A /* NanoID.swift */, 42FF1AEA271154A600B38C38 /* SafariExtension */, B330B55BAF36E624637EE3BE /* ShareExtension */, 04920CC5279671EF003EC1B6 /* PushNotificationConfig.swift */, @@ -1035,10 +1023,7 @@ buildActionMask = 2147483647; files = ( 0480E71D26D95096006CAE2F /* AppDelegate.swift in Sources */, - 4255C6D92755A5350006422A /* NanoID.swift in Sources */, 0465B9BE26CDD35F005558CD /* MainApp.swift in Sources */, - 426408742744676C00A2AE46 /* PDFReaderView.swift in Sources */, - 042184F0273AD5F3002357B0 /* PDFViewer.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1071,11 +1056,8 @@ buildActionMask = 2147483647; files = ( 0480E71C26D95096006CAE2F /* AppDelegate.swift in Sources */, - 4255C6D82755A5350006422A /* NanoID.swift in Sources */, 04920CC6279671EF003EC1B6 /* PushNotificationConfig.swift in Sources */, CA7EE773095F267516D7AC98 /* MainApp.swift in Sources */, - 426408732744676C00A2AE46 /* PDFReaderView.swift in Sources */, - 042184EF273AD5F3002357B0 /* PDFViewer.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/apple/Sources/NanoID.swift b/apple/OmnivoreKit/Sources/App/PDFSupport/NanoID.swift similarity index 100% rename from apple/Sources/NanoID.swift rename to apple/OmnivoreKit/Sources/App/PDFSupport/NanoID.swift diff --git a/apple/Sources/PDFReaderView.swift b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFReaderView.swift similarity index 87% rename from apple/Sources/PDFReaderView.swift rename to apple/OmnivoreKit/Sources/App/PDFSupport/PDFReaderView.swift index 2dad14846..66309f623 100644 --- a/apple/Sources/PDFReaderView.swift +++ b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFReaderView.swift @@ -1,14 +1,18 @@ -import Models -import SwiftUI -import Utils -import WebKit - #if os(iOS) - import App + import Models import PSPDFKit import PSPDFKitUI + import SwiftUI + import Utils + import WebKit struct PDFReaderViewController: UIViewControllerRepresentable { + static func registerKey() { + if let pspdfKitKey = AppKeys.sharedInstance?.pspdfKitKey { + SDK.setLicenseKey(pspdfKitKey) + } + } + let document: Document @Environment(\.presentationMode) var presentationMode diff --git a/apple/Sources/PDFViewer.swift b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift similarity index 90% rename from apple/Sources/PDFViewer.swift rename to apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift index 520cc538e..c010b6d80 100644 --- a/apple/Sources/PDFViewer.swift +++ b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift @@ -1,14 +1,15 @@ -import App import Combine import SwiftUI import Utils #if os(iOS) - import PDFKit import PSPDFKit import PSPDFKitUI + import Services struct PDFViewer: View { + @EnvironmentObject var dataService: DataService + struct ShareLink: Identifiable { let id: UUID let url: URL @@ -36,7 +37,7 @@ import Utils } .updateControllerConfiguration { controller in print("document is valid", document.isValid) - coordinator.setController(controller: controller) + coordinator.setController(controller: controller, dataService: dataService) // Disable the Document Editor controller.navigationItem.setRightBarButtonItems( @@ -80,7 +81,11 @@ import Utils .onShouldShowMenuItemsForSelectedText(perform: { pageView, menuItems, selectedText in let copy = menuItems.first(where: { $0.identifier == "Copy" }) let highlight = MenuItem(title: "Highlight", block: { - _ = self.coordinator.highlightSelection(pageView: pageView, selectedText: selectedText) + _ = self.coordinator.highlightSelection( + pageView: pageView, + selectedText: selectedText, + dataService: dataService + ) }) // let share = MenuItem(title: "Share", block: { // let shortId = self.coordinator.highlightSelection(pageView: pageView, selectedText: selectedText) @@ -97,7 +102,7 @@ import Utils } let remove = MenuItem(title: "Remove", block: { - self.coordinator.remove(annotations: annotations) + self.coordinator.remove(dataService: dataService, annotations: annotations) }) result.append(remove) @@ -106,7 +111,7 @@ import Utils if let shortId = shortId, FeatureFlag.enableShareButton { let share = MenuItem(title: "Share", block: { - if let shareURL = viewModel.highlightShareURL(shortId: shortId) { + if let shareURL = viewModel.highlightShareURL(dataService: dataService, shortId: shortId) { shareLink = ShareLink(id: UUID(), url: shareURL) } }) @@ -137,7 +142,7 @@ import Utils self.viewModel = viewModel } - func setController(controller: PDFViewController) { + func setController(controller: PDFViewController, dataService: DataService) { self.controller = controller controller.pageIndexPublisher.sink { event in @@ -146,7 +151,11 @@ import Utils if let totalPageCount = controller.document?.pageCount { let percent = min(100, max(0, ((Double(pageIndex) + 1.0) / Double(totalPageCount)) * 100.0)) if percent > self.viewModel.pdfItem.readingProgress { - self.viewModel.updateItemReadProgress(percent: percent, anchorIndex: pageIndex) + self.viewModel.updateItemReadProgress( + dataService: dataService, + percent: percent, + anchorIndex: pageIndex + ) } } } @@ -187,7 +196,7 @@ import Utils return result } - func highlightSelection(pageView: PDFPageView, selectedText: String) -> String { + func highlightSelection(pageView: PDFPageView, selectedText: String, dataService: DataService) -> String { let highlightID = UUID().uuidString.lowercased() let quote = quoteFromSelectedText(selectedText) let shortId = NanoID.generate(alphabet: NanoID.Alphabet.urlSafe.rawValue, size: 8) @@ -208,7 +217,13 @@ import Utils if let patchData = try? highlight.generateInstantJSON(), let patch = String(data: patchData, encoding: .utf8) { if overlapping.isEmpty { - viewModel.createHighlight(shortId: shortId, highlightID: highlightID, quote: quote, patch: patch) + viewModel.createHighlight( + dataService: dataService, + shortId: shortId, + highlightID: highlightID, + quote: quote, + patch: patch + ) } else { let overlappingRects = overlapping.map(\.rects).compactMap { $0 }.flatMap { $0 } let rects = overlappingRects + (highlight.rects ?? []) @@ -223,6 +238,7 @@ import Utils document.remove(annotations: overlapping + [highlight]) viewModel.mergeHighlight( + dataService: dataService, shortId: shortId, highlightID: highlightID, quote: quote, @@ -238,10 +254,13 @@ import Utils return shortId } - public func remove(annotations: [Annotation]?) { + public func remove(dataService: DataService, annotations: [Annotation]?) { if let annotations = annotations { document.remove(annotations: annotations) - viewModel.removeHighlights(highlightIds: highlightIds(annotations.compactMap { $0 as? HighlightAnnotation })) + viewModel.removeHighlights( + dataService: dataService, + highlightIds: highlightIds(annotations.compactMap { $0 as? HighlightAnnotation }) + ) } } diff --git a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift index f8510a545..2d0b70cbf 100644 --- a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift @@ -12,10 +12,8 @@ public final class PDFViewerViewModel: ObservableObject { private var storedURL: URL? var subscriptions = Set() - let services: Services - public init(services: Services, pdfItem: PDFItem) { - self.services = services + public init(pdfItem: PDFItem) { self.pdfItem = pdfItem } @@ -45,8 +43,14 @@ public final class PDFViewerViewModel: ObservableObject { onComplete(pdfItem.highlights.map { $0.patch ?? "" }) } - public func createHighlight(shortId: String, highlightID: String, quote: String, patch: String) { - _ = services.dataService.createHighlight( + public func createHighlight( + dataService: DataService, + shortId: String, + highlightID: String, + quote: String, + patch: String + ) { + _ = dataService.createHighlight( shortId: shortId, highlightID: highlightID, quote: quote, @@ -56,13 +60,14 @@ public final class PDFViewerViewModel: ObservableObject { } public func mergeHighlight( + dataService: DataService, shortId: String, highlightID: String, quote: String, patch: String, overlapHighlightIdList: [String] ) { - _ = services.dataService.mergeHighlights( + _ = dataService.mergeHighlights( shortId: shortId, highlightID: highlightID, quote: quote, @@ -72,25 +77,25 @@ public final class PDFViewerViewModel: ObservableObject { ) } - public func removeHighlights(highlightIds: [String]) { + public func removeHighlights(dataService: DataService, highlightIds: [String]) { highlightIds.forEach { highlightID in - services.dataService.deleteHighlight(highlightID: highlightID) + dataService.deleteHighlight(highlightID: highlightID) } } - public func updateItemReadProgress(percent: Double, anchorIndex: Int) { - services.dataService.updateLinkReadingProgress( + public func updateItemReadProgress(dataService: DataService, percent: Double, anchorIndex: Int) { + dataService.updateLinkReadingProgress( itemID: pdfItem.itemID, readingProgress: percent, anchorIndex: anchorIndex ) } - public func highlightShareURL(shortId: String) -> URL? { - let baseURL = services.dataService.appEnvironment.serverBaseURL + public func highlightShareURL(dataService: DataService, shortId: String) -> URL? { + let baseURL = dataService.appEnvironment.serverBaseURL var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false) - if let username = services.dataService.currentViewer?.username { + if let username = dataService.currentViewer?.username { components?.path = "/\(username)/\(pdfItem.slug)/highlights/\(shortId)" } else { return nil diff --git a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift index bd4560a5b..fb39218e2 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift @@ -5,10 +5,6 @@ import SwiftUI import Utils import Views -enum PDFProvider { - static var pdfViewerProvider: ((URL, PDFItem) -> AnyView)? -} - @MainActor final class LinkItemDetailViewModel: ObservableObject { let pdfItem: PDFItem? let item: LinkedItem? @@ -298,7 +294,7 @@ struct LinkItemDetailView: View { @ViewBuilder private var fixedNavBarReader: some View { if let pdfItem = viewModel.pdfItem, let pdfURL = pdfItem.pdfURL { #if os(iOS) - PDFProvider.pdfViewerProvider?(pdfURL, pdfItem) + PDFViewer(remoteURL: pdfURL, viewModel: PDFViewerViewModel(pdfItem: pdfItem)) .navigationBarTitleDisplayMode(.inline) #elseif os(macOS) PDFWrapperView(pdfURL: pdfURL) diff --git a/apple/OmnivoreKit/Sources/App/Views/RootView/RootView.swift b/apple/OmnivoreKit/Sources/App/Views/RootView/RootView.swift index ad53ded07..7ba28267a 100644 --- a/apple/OmnivoreKit/Sources/App/Views/RootView/RootView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/RootView/RootView.swift @@ -6,20 +6,18 @@ import Views public struct RootView: View { @Environment(\.scenePhase) var scenePhase - let pdfViewerProvider: ((URL, PDFViewerViewModel) -> AnyView)? @StateObject private var viewModel = RootViewModel() - public init( - pdfViewerProvider: ((URL, PDFViewerViewModel) -> AnyView)?, - intercomProvider: IntercomProvider? - ) { - self.pdfViewerProvider = pdfViewerProvider - + public init(intercomProvider: IntercomProvider?) { if let intercomProvider = intercomProvider { DataService.showIntercomMessenger = intercomProvider.showIntercomMessenger DataService.registerIntercomUser = intercomProvider.registerIntercomUser Authenticator.unregisterIntercomUser = intercomProvider.unregisterIntercomUser } + + #if os(iOS) + PDFReaderViewController.registerKey() + #endif } public var body: some View { @@ -27,11 +25,6 @@ public struct RootView: View { .environmentObject(viewModel.services.authenticator) .environmentObject(viewModel.services.dataService) .environment(\.managedObjectContext, viewModel.services.dataService.viewContext) - .onAppear { - if let pdfViewerProvider = pdfViewerProvider { - viewModel.configurePDFProvider(pdfViewerProvider: pdfViewerProvider) - } - } .onChange(of: scenePhase) { phase in if phase == .background { #if os(iOS) diff --git a/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift index 400ac7564..b598fa014 100644 --- a/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift @@ -32,15 +32,6 @@ public final class RootViewModel: ObservableObject { #endif } - func configurePDFProvider(pdfViewerProvider: @escaping (URL, PDFViewerViewModel) -> AnyView) { - guard PDFProvider.pdfViewerProvider == nil else { return } - - PDFProvider.pdfViewerProvider = { [weak self] url, pdfItem in - guard let self = self else { return AnyView(Text("")) } - return pdfViewerProvider(url, PDFViewerViewModel(services: self.services, pdfItem: pdfItem)) - } - } - func webAppWrapperViewModel(webLinkPath: String) -> WebAppWrapperViewModel { let baseURL = services.dataService.appEnvironment.webAppBaseURL diff --git a/apple/Sources/MainApp.swift b/apple/Sources/MainApp.swift index 712c76265..909a6be02 100644 --- a/apple/Sources/MainApp.swift +++ b/apple/Sources/MainApp.swift @@ -6,7 +6,6 @@ import SwiftUI import AppKit #elseif os(iOS) import Intercom - import PSPDFKit import UIKit import Utils #endif @@ -17,20 +16,12 @@ struct MainApp: App { @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate #elseif os(iOS) @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate - - init() { - // Activate PSPDFKit for app.omnivore.app - if let pspdfKitKey = AppKeys.sharedInstance?.pspdfKitKey { - SDK.setLicenseKey(pspdfKitKey) - } - } #endif var body: some Scene { #if os(iOS) WindowGroup { RootView( - pdfViewerProvider: pdfViewerProvider, intercomProvider: AppKeys.sharedInstance?.intercom != nil ? IntercomProvider( registerIntercomUser: { Intercom.registerUser(withUserId: $0) }, unregisterIntercomUser: Intercom.logout, @@ -40,12 +31,8 @@ struct MainApp: App { } #elseif os(macOS) WindowGroup { - RootView(pdfViewerProvider: nil, intercomProvider: nil) + RootView(intercomProvider: nil) } #endif } - - private func pdfViewerProvider(url: URL, viewModel: PDFViewerViewModel) -> AnyView { - AnyView(PDFViewer(remoteURL: url, viewModel: viewModel)) - } } From 11b5dc3172a62a3e7c0ba2d7aad6704c26b4fa49 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Sun, 22 May 2022 23:24:37 -0700 Subject: [PATCH 6/9] use stateobject to keep track of pdf document --- .../Sources/App/PDFSupport/PDFViewer.swift | 188 ++++++++++-------- .../Components/FeedCardNavigationLink.swift | 14 +- .../App/Views/LinkItemDetailView.swift | 12 +- 3 files changed, 121 insertions(+), 93 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift index c010b6d80..9a6789b1c 100644 --- a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift +++ b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift @@ -8,6 +8,11 @@ import Utils import Services struct PDFViewer: View { + final class PDFStateObject: ObservableObject { + @Published var document: Document? + @Published var coordinator: PDFViewCoordinator? + } + @EnvironmentObject var dataService: DataService struct ShareLink: Identifiable { @@ -16,117 +21,124 @@ import Utils } let pdfURL: URL - let document: Document let viewModel: PDFViewerViewModel - let coordinator: PDFViewCoordinator + + @StateObject var pdfStateObject = PDFStateObject() @State var readerView: Bool = false @State private var shareLink: ShareLink? init(remoteURL: URL, viewModel: PDFViewerViewModel) { self.pdfURL = viewModel.dataURL(remoteURL: remoteURL) self.viewModel = viewModel - self.document = HighlightedDocument(url: pdfURL, viewModel: viewModel) - self.coordinator = PDFViewCoordinator(document: document, viewModel: viewModel) } var body: some View { - PDFView(document: document) - .useParentNavigationBar(true) - .updateConfiguration { builder in - builder.textSelectionShouldSnapToWord = true - } - .updateControllerConfiguration { controller in - print("document is valid", document.isValid) - coordinator.setController(controller: controller, dataService: dataService) - - // Disable the Document Editor - controller.navigationItem.setRightBarButtonItems( - [controller.thumbnailsButtonItem], - for: .thumbnails, - animated: false - ) - - let barButtonItems = [ - UIBarButtonItem( - image: UIImage(systemName: "textformat"), - style: .plain, - target: controller.settingsButtonItem.target, - action: controller.settingsButtonItem.action - ), - UIBarButtonItem( - image: UIImage(systemName: "book"), - style: .plain, - target: coordinator, - action: #selector(PDFViewCoordinator.toggleReaderView) - ), - UIBarButtonItem( - image: UIImage(systemName: "magnifyingglass"), - style: .plain, - target: controller.searchButtonItem.target, - action: controller.searchButtonItem.action - ) - ] - - document.areAnnotationsEnabled = true - - coordinator.viewer = self - - if viewModel.pdfItem.readingProgressAnchor > 0 { - let pageIndex = UInt(viewModel.pdfItem.readingProgressAnchor) - controller.setPageIndex(pageIndex, animated: false) + if let document = pdfStateObject.document, let coordinator = pdfStateObject.coordinator { + PDFView(document: document) + .useParentNavigationBar(true) + .updateConfiguration { builder in + builder.textSelectionShouldSnapToWord = true } + .updateControllerConfiguration { controller in + print("document is valid", document.isValid) + coordinator.setController(controller: controller, dataService: dataService) - controller.navigationItem.setRightBarButtonItems(barButtonItems, for: .document, animated: false) - } - .onShouldShowMenuItemsForSelectedText(perform: { pageView, menuItems, selectedText in - let copy = menuItems.first(where: { $0.identifier == "Copy" }) - let highlight = MenuItem(title: "Highlight", block: { - _ = self.coordinator.highlightSelection( - pageView: pageView, - selectedText: selectedText, - dataService: dataService + // Disable the Document Editor + controller.navigationItem.setRightBarButtonItems( + [controller.thumbnailsButtonItem], + for: .thumbnails, + animated: false ) - }) + + let barButtonItems = [ + UIBarButtonItem( + image: UIImage(systemName: "textformat"), + style: .plain, + target: controller.settingsButtonItem.target, + action: controller.settingsButtonItem.action + ), + UIBarButtonItem( + image: UIImage(systemName: "book"), + style: .plain, + target: coordinator, + action: #selector(PDFViewCoordinator.toggleReaderView) + ), + UIBarButtonItem( + image: UIImage(systemName: "magnifyingglass"), + style: .plain, + target: controller.searchButtonItem.target, + action: controller.searchButtonItem.action + ) + ] + + document.areAnnotationsEnabled = true + + coordinator.viewer = self + + if viewModel.pdfItem.readingProgressAnchor > 0 { + let pageIndex = UInt(viewModel.pdfItem.readingProgressAnchor) + controller.setPageIndex(pageIndex, animated: false) + } + + controller.navigationItem.setRightBarButtonItems(barButtonItems, for: .document, animated: false) + } + .onShouldShowMenuItemsForSelectedText(perform: { pageView, menuItems, selectedText in + let copy = menuItems.first(where: { $0.identifier == "Copy" }) + let highlight = MenuItem(title: "Highlight", block: { + _ = coordinator.highlightSelection( + pageView: pageView, + selectedText: selectedText, + dataService: dataService + ) + }) // let share = MenuItem(title: "Share", block: { // let shortId = self.coordinator.highlightSelection(pageView: pageView, selectedText: selectedText) // if let shareURL = viewModel.highlightShareURL(shortId: shortId) { // shareLink = ShareLink(id: UUID(), url: shareURL) // } // }) - return [copy, highlight /* , share */ ].compactMap { $0 } - }) - .onShouldShowMenuItemsForSelectedAnnotations(perform: { _, menuItems, annotations in - var result = [MenuItem]() - if let copy = menuItems.first(where: { $0.identifier == "Copy" }) { - result.append(copy) - } - - let remove = MenuItem(title: "Remove", block: { - self.coordinator.remove(dataService: dataService, annotations: annotations) + return [copy, highlight /* , share */ ].compactMap { $0 } }) - result.append(remove) + .onShouldShowMenuItemsForSelectedAnnotations(perform: { _, menuItems, annotations in + var result = [MenuItem]() + if let copy = menuItems.first(where: { $0.identifier == "Copy" }) { + result.append(copy) + } - let highlights = annotations?.compactMap { $0 as? HighlightAnnotation } - let shortId = highlights.flatMap { coordinator.shortHighlightIds($0).first } - - if let shortId = shortId, FeatureFlag.enableShareButton { - let share = MenuItem(title: "Share", block: { - if let shareURL = viewModel.highlightShareURL(dataService: dataService, shortId: shortId) { - shareLink = ShareLink(id: UUID(), url: shareURL) - } + let remove = MenuItem(title: "Remove", block: { + coordinator.remove(dataService: dataService, annotations: annotations) }) - result.append(share) - } + result.append(remove) - return result - }) - .fullScreenCover(isPresented: $readerView, content: { - PDFReaderViewController(document: document) - }) - .accentColor(Color(red: 255 / 255.0, green: 234 / 255.0, blue: 159 / 255.0)) - .sheet(item: $shareLink) { - ShareSheet(activityItems: [$0.url]) - } + let highlights = annotations?.compactMap { $0 as? HighlightAnnotation } + let shortId = highlights.flatMap { coordinator.shortHighlightIds($0).first } + + if let shortId = shortId, FeatureFlag.enableShareButton { + let share = MenuItem(title: "Share", block: { + if let shareURL = viewModel.highlightShareURL(dataService: dataService, shortId: shortId) { + shareLink = ShareLink(id: UUID(), url: shareURL) + } + }) + result.append(share) + } + + return result + }) + .fullScreenCover(isPresented: $readerView, content: { + PDFReaderViewController(document: document) + }) + .accentColor(Color(red: 255 / 255.0, green: 234 / 255.0, blue: 159 / 255.0)) + .sheet(item: $shareLink) { + ShareSheet(activityItems: [$0.url]) + } + } else { + Text("Loading...") + .task { + let document = HighlightedDocument(url: pdfURL, viewModel: viewModel) + pdfStateObject.document = document + pdfStateObject.coordinator = PDFViewCoordinator(document: document, viewModel: viewModel) + } + } } class PDFViewCoordinator: NSObject, PDFDocumentViewControllerDelegate, PDFViewControllerDelegate { diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift index a92404771..99ee55106 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift @@ -11,7 +11,12 @@ struct FeedCardNavigationLink: View { @ObservedObject var viewModel: HomeFeedViewModel var body: some View { - let destination = LinkItemDetailView(viewModel: LinkItemDetailViewModel(item: item, pdfItem: PDFItem.make(item: item))) + let destination = LinkItemDetailView( + viewModel: LinkItemDetailViewModel( + linkedItemObjectID: item.objectID, + dataService: dataService + ) + ) #if os(iOS) let modifiedDestination = destination .navigationTitle("") @@ -50,7 +55,12 @@ struct GridCardNavigationLink: View { @ObservedObject var viewModel: HomeFeedViewModel var body: some View { - let destination = LinkItemDetailView(viewModel: LinkItemDetailViewModel(item: item, pdfItem: PDFItem.make(item: item))) + let destination = LinkItemDetailView( + viewModel: LinkItemDetailViewModel( + linkedItemObjectID: item.objectID, + dataService: dataService + ) + ) #if os(iOS) let modifiedDestination = destination .navigationTitle("") diff --git a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift index fb39218e2..dea6b1963 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift @@ -1,4 +1,5 @@ import Combine +import CoreData import Models import Services import SwiftUI @@ -12,9 +13,14 @@ import Views var subscriptions = Set() - init(item: LinkedItem?, pdfItem: PDFItem?) { - self.item = item - self.pdfItem = pdfItem + init(linkedItemObjectID: NSManagedObjectID, dataService: DataService) { + if let linkedItem = dataService.viewContext.object(with: linkedItemObjectID) as? LinkedItem { + self.pdfItem = PDFItem.make(item: linkedItem) + self.item = linkedItem + } else { + self.pdfItem = nil + self.item = nil + } } func handleArchiveAction(dataService: DataService) { From c748ceb26ba08ab6cb29bc14ec9bb8c204bd6fc1 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Sun, 22 May 2022 23:26:04 -0700 Subject: [PATCH 7/9] bump ios version to 1.7.1 --- apple/Omnivore.xcodeproj/project.pbxproj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apple/Omnivore.xcodeproj/project.pbxproj b/apple/Omnivore.xcodeproj/project.pbxproj index 083e78b94..bd10aa72a 100644 --- a/apple/Omnivore.xcodeproj/project.pbxproj +++ b/apple/Omnivore.xcodeproj/project.pbxproj @@ -1441,7 +1441,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.7.0; + MARKETING_VERSION = 1.7.1; PRODUCT_BUNDLE_IDENTIFIER = app.omnivore.app; PRODUCT_NAME = Omnivore; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1473,7 +1473,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.7.0; + MARKETING_VERSION = 1.7.1; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; OTHER_LDFLAGS = ( @@ -1512,7 +1512,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.7.0; + MARKETING_VERSION = 1.7.1; MTL_FAST_MATH = YES; OTHER_LDFLAGS = ( "-framework", @@ -1674,7 +1674,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.7.0; + MARKETING_VERSION = 1.7.1; PRODUCT_BUNDLE_IDENTIFIER = "app.omnivore.app.share-extension"; PRODUCT_NAME = ShareExtension; SDKROOT = iphoneos; @@ -1728,7 +1728,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.7.0; + MARKETING_VERSION = 1.7.1; PRODUCT_BUNDLE_IDENTIFIER = app.omnivore.app; PRODUCT_NAME = Omnivore; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1756,7 +1756,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.7.0; + MARKETING_VERSION = 1.7.1; PRODUCT_BUNDLE_IDENTIFIER = "app.omnivore.app.share-extension"; PRODUCT_NAME = ShareExtension; SDKROOT = iphoneos; From b46576e9374526f5ca3f4134ad004ed2b7dd8bf2 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Mon, 23 May 2022 08:55:32 -0700 Subject: [PATCH 8/9] run controller config once --- .../xcshareddata/swiftpm/Package.resolved | 9 +++++++++ apple/OmnivoreKit/Package.swift | 12 ++++++------ .../Sources/App/PDFSupport/PDFViewer.swift | 4 ++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved b/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved index e79bf771f..fa6f4cbb3 100644 --- a/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -135,6 +135,15 @@ "version" : "2.0.0" } }, + { + "identity" : "pspdfkit-sp", + "kind" : "remoteSourceControl", + "location" : "https://github.com/PSPDFKit/PSPDFKit-SP", + "state" : { + "branch" : "master", + "revision" : "0e18629c443e3f39ecfee0f600d9ef5551ecf488" + } + }, { "identity" : "sovran-swift", "kind" : "remoteSourceControl", diff --git a/apple/OmnivoreKit/Package.swift b/apple/OmnivoreKit/Package.swift index 1eafb078f..6fafc0cb0 100644 --- a/apple/OmnivoreKit/Package.swift +++ b/apple/OmnivoreKit/Package.swift @@ -55,9 +55,9 @@ let package = Package( var appPackageDependencies: [Target.Dependency] { var deps: [Target.Dependency] = ["Views", "Services", "Models", "Utils"] - #if canImport(UIKit) - deps.append(.product(name: "PSPDFKit", package: "PSPDFKit-SP")) - #endif +// #if canImport(UIKit) + deps.append(.product(name: "PSPDFKit", package: "PSPDFKit-SP")) +// #endif return deps } @@ -69,8 +69,8 @@ var dependencies: [Package.Dependency] { .package(url: "https://github.com/siteline/SwiftUI-Introspect.git", from: "0.1.4"), .package(url: "git@github.com:segmentio/analytics-swift.git", .upToNextMajor(from: "1.0.0")) ] - #if canImport(UIKit) - deps.append(.package(url: "https://github.com/PSPDFKit/PSPDFKit-SP", branch: "master")) - #endif +// #if canImport(UIKit) + deps.append(.package(url: "https://github.com/PSPDFKit/PSPDFKit-SP", branch: "master")) +// #endif return deps } diff --git a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift index 9a6789b1c..1c6672f7b 100644 --- a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift +++ b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift @@ -11,6 +11,7 @@ import Utils final class PDFStateObject: ObservableObject { @Published var document: Document? @Published var coordinator: PDFViewCoordinator? + @Published var controllerNeedsConfig = true } @EnvironmentObject var dataService: DataService @@ -40,6 +41,8 @@ import Utils builder.textSelectionShouldSnapToWord = true } .updateControllerConfiguration { controller in + // Store config state so we only run this update closure once + guard pdfStateObject.controllerNeedsConfig else { return } print("document is valid", document.isValid) coordinator.setController(controller: controller, dataService: dataService) @@ -81,6 +84,7 @@ import Utils } controller.navigationItem.setRightBarButtonItems(barButtonItems, for: .document, animated: false) + pdfStateObject.controllerNeedsConfig = false } .onShouldShowMenuItemsForSelectedText(perform: { pageView, menuItems, selectedText in let copy = menuItems.first(where: { $0.identifier == "Copy" }) From 1a12e545f5c8db2c14d9bf38bf46f3fbfecd3576 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Mon, 23 May 2022 09:20:52 -0700 Subject: [PATCH 9/9] use progressview for pdf loading view --- apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift index 1c6672f7b..ea7b59c0f 100644 --- a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift +++ b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift @@ -136,7 +136,7 @@ import Utils ShareSheet(activityItems: [$0.url]) } } else { - Text("Loading...") + ProgressView() .task { let document = HighlightedDocument(url: pdfURL, viewModel: viewModel) pdfStateObject.document = document