2019-04-29 14:07:57 +02:00
|
|
|
//
|
|
|
|
// FaviconGenerator.swift
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 4/29/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import RSCore
|
|
|
|
import Account
|
|
|
|
|
2024-03-20 07:05:30 +01:00
|
|
|
@MainActor final class FaviconGenerator {
|
2019-04-29 14:07:57 +02:00
|
|
|
|
2019-11-06 01:05:57 +01:00
|
|
|
private static var faviconGeneratorCache = [String: IconImage]() // feedURL: RSImage
|
2019-04-29 14:07:57 +02:00
|
|
|
|
2024-02-26 08:12:21 +01:00
|
|
|
static func favicon(_ feed: Feed) -> IconImage {
|
2019-04-29 14:07:57 +02:00
|
|
|
|
2024-02-26 08:12:21 +01:00
|
|
|
if let favicon = FaviconGenerator.faviconGeneratorCache[feed.url] {
|
2019-04-29 14:07:57 +02:00
|
|
|
return favicon
|
|
|
|
}
|
|
|
|
|
2024-02-26 08:12:21 +01:00
|
|
|
let colorHash = ColorHash(feed.url)
|
2019-05-21 12:42:40 +02:00
|
|
|
if let favicon = AppAssets.faviconTemplateImage.maskWithColor(color: colorHash.color.cgColor) {
|
2020-12-06 21:25:22 +01:00
|
|
|
let iconImage = IconImage(favicon, isBackgroundSupressed: true)
|
2024-02-26 08:12:21 +01:00
|
|
|
FaviconGenerator.faviconGeneratorCache[feed.url] = iconImage
|
2019-11-06 01:05:57 +01:00
|
|
|
return iconImage
|
2019-04-29 14:07:57 +02:00
|
|
|
} else {
|
2020-12-06 21:25:22 +01:00
|
|
|
return IconImage(AppAssets.faviconTemplateImage, isBackgroundSupressed: true)
|
2019-04-29 14:07:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|