adds iconImageUrl to article utils
This commit is contained in:
parent
3254d57189
commit
fe194ec2e5
@ -103,6 +103,22 @@ extension Article {
|
|||||||
return FaviconGenerator.favicon(webFeed)
|
return FaviconGenerator.favicon(webFeed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func iconImageUrl(webFeed: WebFeed) -> URL? {
|
||||||
|
if let image = iconImage() {
|
||||||
|
let fm = FileManager.default
|
||||||
|
var path = fm.urls(for: .cachesDirectory, in: .userDomainMask)[0]
|
||||||
|
#if os(macOS)
|
||||||
|
path.appendPathComponent(webFeed.webFeedID + "_smallIcon.tiff")
|
||||||
|
#else
|
||||||
|
path.appendPathComponent(webFeed.webFeedID + "_smallIcon.png")
|
||||||
|
#endif
|
||||||
|
fm.createFile(atPath: path.path, contents: image.image.dataRepresentation()!, attributes: nil)
|
||||||
|
return path
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func byline() -> String {
|
func byline() -> String {
|
||||||
guard let authors = authors ?? webFeed?.authors, !authors.isEmpty else {
|
guard let authors = authors ?? webFeed?.authors, !authors.isEmpty else {
|
||||||
return ""
|
return ""
|
||||||
|
@ -73,17 +73,8 @@ private extension UserNotificationManager {
|
|||||||
/// - Returns: A `UNNotifcationAttachment` if an icon is available. Otherwise nil.
|
/// - Returns: A `UNNotifcationAttachment` if an icon is available. Otherwise nil.
|
||||||
/// - Warning: In certain scenarios, this will return the `faviconTemplateImage`.
|
/// - Warning: In certain scenarios, this will return the `faviconTemplateImage`.
|
||||||
func thumbnailAttachment(for article: Article, webFeed: WebFeed) -> UNNotificationAttachment? {
|
func thumbnailAttachment(for article: Article, webFeed: WebFeed) -> UNNotificationAttachment? {
|
||||||
if let image = article.iconImage() {
|
if let imageURL = article.iconImageUrl(webFeed: webFeed) {
|
||||||
let fm = FileManager.default
|
let thumbnail = try? UNNotificationAttachment(identifier: webFeed.webFeedID, url: imageURL, options: nil)
|
||||||
var path = fm.urls(for: .cachesDirectory, in: .userDomainMask)[0]
|
|
||||||
#if os(macOS)
|
|
||||||
path.appendPathComponent(webFeed.webFeedID + "_smallIcon.tiff")
|
|
||||||
#else
|
|
||||||
path.appendPathComponent(webFeed.webFeedID + "_smallIcon.png")
|
|
||||||
#endif
|
|
||||||
fm.createFile(atPath: path.path, contents: image.image.dataRepresentation()!, attributes: nil)
|
|
||||||
|
|
||||||
let thumbnail = try? UNNotificationAttachment(identifier: webFeed.webFeedID, url: path, options: nil)
|
|
||||||
return thumbnail
|
return thumbnail
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user