Merge branch 'ios-release' of https://github.com/Ranchero-Software/NetNewsWire into ios-release

This commit is contained in:
Maurice Parker 2020-03-20 06:59:14 -05:00
commit 39520e319c
1 changed files with 26 additions and 7 deletions

View File

@ -6,6 +6,7 @@
// Copyright © 2019 Ranchero Software. All rights reserved. // Copyright © 2019 Ranchero Software. All rights reserved.
// //
import RSCore
#if os(macOS) #if os(macOS)
import AppKit import AppKit
#else #else
@ -18,13 +19,8 @@ extension RSImage {
static let maxIconSize = 48 static let maxIconSize = 48
static func scaledForIcon(_ data: Data, imageResultBlock: @escaping (RSImage?) -> Void) { static func scaledForIcon(_ data: Data, imageResultBlock: @escaping ImageResultBlock) {
DispatchQueue.global(qos: .default).async { IconScalerQueue.shared.scaledForIcon(data, imageResultBlock)
let image = RSImage.scaledForIcon(data)
DispatchQueue.main.async {
imageResultBlock(image)
}
}
} }
static func scaledForIcon(_ data: Data) -> RSImage? { static func scaledForIcon(_ data: Data) -> RSImage? {
@ -41,3 +37,26 @@ extension RSImage {
#endif #endif
} }
} }
// MARK: - IconScalerQueue
private class IconScalerQueue {
static let shared = IconScalerQueue()
private let queue: DispatchQueue = {
let q = DispatchQueue(label: "IconScaler", attributes: .initiallyInactive)
q.setTarget(queue: DispatchQueue.global(qos: .default))
q.activate()
return q
}()
func scaledForIcon(_ data: Data, _ imageResultBlock: @escaping ImageResultBlock) {
queue.async {
let image = RSImage.scaledForIcon(data)
DispatchQueue.main.async {
imageResultBlock(image)
}
}
}
}