2017-11-23 23:15:28 +01:00
|
|
|
//
|
|
|
|
// Favicon.swift
|
|
|
|
// Evergreen
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 11/23/17.
|
|
|
|
// Copyright © 2017 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import AppKit
|
2017-11-24 19:45:22 +01:00
|
|
|
import RSCore
|
2017-11-23 23:15:28 +01:00
|
|
|
|
2017-11-24 19:45:22 +01:00
|
|
|
final class FaviconController {
|
2017-11-23 23:15:28 +01:00
|
|
|
|
|
|
|
enum DiskStatus {
|
|
|
|
case unknown, notOnDisk, onDisk
|
|
|
|
}
|
|
|
|
|
|
|
|
let faviconURL: String
|
|
|
|
var lastDownloadAttemptDate: Date?
|
|
|
|
var diskStatus = DiskStatus.unknown
|
2017-11-24 19:45:22 +01:00
|
|
|
let diskCache: RSBinaryCache
|
2017-11-23 23:15:28 +01:00
|
|
|
var image: NSImage?
|
|
|
|
|
2017-11-24 19:45:22 +01:00
|
|
|
init?(faviconURL: String, _ diskCache: RSBinaryCache) {
|
2017-11-23 23:15:28 +01:00
|
|
|
|
|
|
|
self.faviconURL = faviconURL
|
2017-11-24 19:45:22 +01:00
|
|
|
self.diskCache = diskCache
|
|
|
|
findFavicon()
|
2017-11-23 23:15:28 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-24 19:45:22 +01:00
|
|
|
|
|
|
|
private extension FaviconController {
|
|
|
|
|
|
|
|
func findFavicon() {
|
|
|
|
|
|
|
|
readFromDisk { (image) in
|
|
|
|
self.image = image
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func readFromDisk(_ callback: (NSImage?) -> Void) {
|
|
|
|
|
|
|
|
if diskStatus == .notOnDisk {
|
|
|
|
callback(nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|