Remove the preview image from the share extension

This commit is contained in:
Jackson Harper 2022-11-17 15:37:02 +08:00 committed by Hongbo Wu
parent 35a9de657a
commit 8c6798a467
4 changed files with 7 additions and 86 deletions

View file

@ -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,

View file

@ -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:

View file

@ -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)

View file

@ -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"