From 8c6798a4670175ceb970e7516d80f1926588c1eb Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 17 Nov 2022 15:37:02 +0800 Subject: [PATCH] Remove the preview image from the share extension --- .../Share/ShareExtensionViewModel.swift | 16 +---- .../Share/Views/ShareExtensionView.swift | 65 ------------------- .../Sources/Models/PageScrapePayload.swift | 9 ++- .../Services/DataService/DataService.swift | 3 +- 4 files changed, 7 insertions(+), 86 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/ShareExtensionViewModel.swift b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/ShareExtensionViewModel.swift index 517e2a746..54d0ce76e 100644 --- a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/ShareExtensionViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/ShareExtensionViewModel.swift @@ -9,7 +9,6 @@ public class ShareExtensionViewModel: ObservableObject { @Published public var status: ShareExtensionStatus = .processing @Published public var title: String = "" @Published public var url: String? - @Published public var iconURL: String? @Published public var linkedItem: LinkedItem? @Published public var requestId = UUID().uuidString.lowercased() @Published var debugText: String? @@ -88,26 +87,15 @@ public class ShareExtensionViewModel: ObservableObject { let hostname = URL(string: payload.url)?.host ?? "" switch payload.contentType { - case let .html(html: _, title: title, iconURL: iconURL): + case let .html(html: _, title: title): self.title = title ?? "" - self.iconURL = iconURL self.url = hostname case .none: self.url = hostname self.title = payload.url - if var url = url { - url.path = "/favicon.ico" - self.iconURL = url.url?.absoluteString - } case let .pdf(localUrl: localUrl): self.url = hostname self.title = PDFUtils.titleFromPdfFile(localUrl.absoluteString) - Task { - let localThumbnail = try await PDFUtils.createThumbnailFor(inputUrl: localUrl) - DispatchQueue.main.async { - self.iconURL = localThumbnail?.absoluteString - } - } } } @@ -155,7 +143,7 @@ public class ShareExtensionViewModel: ObservableObject { localPdfURL: localUrl, url: pageScrapePayload.url ) - case let .html(html, title, _): + case let .html(html, title): newRequestID = try await services.dataService.createPage( id: requestId, originalHtml: html, diff --git a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift index c4a0ea82d..240ecf704 100644 --- a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift +++ b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift @@ -81,71 +81,6 @@ public struct ShareExtensionView: View { return nil } - public var previewCard: some View { - HStack { - if let iconURLStr = viewModel.iconURL, let iconURL = URL(string: iconURLStr) { - if !iconURL.isFileURL { - AsyncImage( - url: iconURL, - content: { image in - image - .resizable() - .aspectRatio(contentMode: .fill) - .frame(width: 61, height: 61) - .clipped() - }, - placeholder: { - Color.appButtonBackground - .aspectRatio(contentMode: .fill) - .frame(width: 61, height: 61) - } - ) - } else { - if let localImage = localImage(from: iconURL) { - localImage - .resizable() - .aspectRatio(contentMode: .fill) - .frame(width: 61, height: 61) - .clipped() - } else { - Color.appButtonBackground - .aspectRatio(contentMode: .fill) - .frame(width: 61, height: 61) - } - } - } else { - Color.appButtonBackground - .aspectRatio(contentMode: .fill) - .frame(width: 61, height: 61) - } - - VStack(alignment: .leading) { - Text(viewModel.title ?? "") - .lineLimit(1) - .foregroundColor(.appGrayTextContrast) - .font(Font.system(size: 15, weight: .semibold)) - Text(viewModel.url ?? "") - .lineLimit(1) - .foregroundColor(.appGrayText) - .font(Font.system(size: 12, weight: .regular)) - } - Spacer() - VStack { - Spacer() - Image(systemName: cloudIconName) - .resizable() - .aspectRatio(contentMode: .fill) - .frame(width: 12, height: 12, alignment: .trailing) - .foregroundColor(cloudIconColor) - // .padding(.trailing, 6) - .padding(EdgeInsets(top: 0, leading: 0, bottom: 8, trailing: 8)) - } - } - .background(Color.appButtonBackground) - .frame(maxWidth: .infinity, maxHeight: 61) - .cornerRadius(8) - } - var isSynced: Bool { switch viewModel.status { case .synced: diff --git a/apple/OmnivoreKit/Sources/Models/PageScrapePayload.swift b/apple/OmnivoreKit/Sources/Models/PageScrapePayload.swift index c0cc1ff94..b21265db9 100644 --- a/apple/OmnivoreKit/Sources/Models/PageScrapePayload.swift +++ b/apple/OmnivoreKit/Sources/Models/PageScrapePayload.swift @@ -11,7 +11,7 @@ let URLREGEX = #"[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6} public struct PageScrapePayload { public enum ContentType { case none - case html(html: String, title: String?, iconURL: String?) + case html(html: String, title: String?) case pdf(localUrl: URL) } @@ -33,9 +33,9 @@ public struct PageScrapePayload { self.contentType = .pdf(localUrl: localUrl) } - init(url: String, title: String?, html: String, iconURL: String? = nil) { + init(url: String, title: String?, html: String) { self.url = url - self.contentType = .html(html: html, title: title, iconURL: iconURL) + self.contentType = .html(html: html, title: title) } } @@ -302,7 +302,6 @@ private extension PageScrapePayload { guard let url = results?["url"] as? String else { return nil } let html = results?["originalHTML"] as? String let title = results?["title"] as? String - let iconURL = results?["iconURL"] as? String let contentType = results?["contentType"] as? String // If we were not able to capture any HTML, treat this as a URL and @@ -318,7 +317,7 @@ private extension PageScrapePayload { } if let html = html { - return PageScrapePayload(url: url, title: title, html: html, iconURL: iconURL) + return PageScrapePayload(url: url, title: title, html: html) } return PageScrapePayload(url: url) diff --git a/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift b/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift index 4757256b3..072d777b1 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift @@ -177,10 +177,9 @@ public final class DataService: ObservableObject { linkedItem.contentReader = "PDF" linkedItem.tempPDFURL = localUrl linkedItem.title = PDFUtils.titleFromPdfFile(pageScrape.url) - case let .html(html: html, title: title, iconURL: iconURL): + case let .html(html: html, title: title): linkedItem.contentReader = "WEB" linkedItem.originalHtml = html - linkedItem.imageURLString = iconURL linkedItem.title = title ?? PDFUtils.titleFromPdfFile(pageScrape.url) case .none: linkedItem.contentReader = "WEB"