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
|
|
|
|
|
|
|
|
final class FaviconGenerator {
|
|
|
|
|
2019-11-06 01:05:57 +01:00
|
|
|
private static var faviconGeneratorCache = [String: IconImage]() // feedURL: RSImage
|
2019-04-29 14:07:57 +02:00
|
|
|
|
2019-11-15 03:11:41 +01:00
|
|
|
static func favicon(_ webFeed: WebFeed) -> IconImage {
|
2019-04-29 14:07:57 +02:00
|
|
|
|
2019-11-15 03:11:41 +01:00
|
|
|
if let favicon = FaviconGenerator.faviconGeneratorCache[webFeed.url] {
|
2019-04-29 14:07:57 +02:00
|
|
|
return favicon
|
|
|
|
}
|
|
|
|
|
2019-11-15 03:11:41 +01:00
|
|
|
let colorHash = ColorHash(webFeed.url)
|
2019-05-21 12:42:40 +02:00
|
|
|
if let favicon = AppAssets.faviconTemplateImage.maskWithColor(color: colorHash.color.cgColor) {
|
2019-11-06 01:05:57 +01:00
|
|
|
let iconImage = IconImage(favicon)
|
2019-11-15 03:11:41 +01:00
|
|
|
FaviconGenerator.faviconGeneratorCache[webFeed.url] = iconImage
|
2019-11-06 01:05:57 +01:00
|
|
|
return iconImage
|
2019-04-29 14:07:57 +02:00
|
|
|
} else {
|
2019-11-06 01:05:57 +01:00
|
|
|
return IconImage(AppAssets.faviconTemplateImage)
|
2019-04-29 14:07:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|