From 2f334e20d8b41728baa2c754dbfbc81581155de5 Mon Sep 17 00:00:00 2001 From: Alex Grebenyuk Date: Wed, 18 Dec 2024 08:50:15 -0500 Subject: [PATCH] Move FaviconService (#23905) --- .../Sources/WordPressMedia}/FaviconService.swift | 14 +++++++------- .../Reader/Cards/ReaderPostCellViewModel.swift | 1 + .../Reader/Views/ReaderSiteIconView.swift | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) rename {WordPress/Classes/Utility/Media => Modules/Sources/WordPressMedia}/FaviconService.swift (90%) diff --git a/WordPress/Classes/Utility/Media/FaviconService.swift b/Modules/Sources/WordPressMedia/FaviconService.swift similarity index 90% rename from WordPress/Classes/Utility/Media/FaviconService.swift rename to Modules/Sources/WordPressMedia/FaviconService.swift index 08dc2b89fdb9..e8c838b3fe23 100644 --- a/WordPress/Classes/Utility/Media/FaviconService.swift +++ b/Modules/Sources/WordPressMedia/FaviconService.swift @@ -1,8 +1,8 @@ import UIKit -// Fetches URLs for favicons for sites. -actor FaviconService { - static let shared = FaviconService() +/// Fetches URLs for favicons for sites. +public actor FaviconService { + public static let shared = FaviconService() private nonisolated let cache = FaviconCache() @@ -14,12 +14,12 @@ actor FaviconService { private var tasks: [URL: FaviconTask] = [:] - nonisolated func cachedFavicon(forURL siteURL: URL) -> URL? { + nonisolated public func cachedFavicon(forURL siteURL: URL) -> URL? { cache.cachedFavicon(forURL: siteURL) } /// Returns a favicon URL for the given site. - func favicon(forURL siteURL: URL) async throws -> URL { + public func favicon(forURL siteURL: URL) async throws -> URL { if let faviconURL = cache.cachedFavicon(forURL: siteURL) { return faviconURL } @@ -57,7 +57,7 @@ actor FaviconService { } } -enum FaviconError: Error { +public enum FaviconError: Error, Sendable { case unacceptableStatusCode(_ code: Int) } @@ -105,7 +105,7 @@ private final class FaviconTask { var isCancelled = false var task: Task - init(_ closure: @escaping () async throws -> URL) { + init(_ closure: @escaping @Sendable () async throws -> URL) { self.task = Task { try await closure() } } } diff --git a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCellViewModel.swift b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCellViewModel.swift index 0c725e10b6ef..0600cf4b61e4 100644 --- a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCellViewModel.swift +++ b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCellViewModel.swift @@ -1,4 +1,5 @@ import Foundation +import WordPressMedia final class ReaderPostCellViewModel { // Header diff --git a/WordPress/Classes/ViewRelated/Reader/Views/ReaderSiteIconView.swift b/WordPress/Classes/ViewRelated/Reader/Views/ReaderSiteIconView.swift index 0e138608864b..27363ecacf74 100644 --- a/WordPress/Classes/ViewRelated/Reader/Views/ReaderSiteIconView.swift +++ b/WordPress/Classes/ViewRelated/Reader/Views/ReaderSiteIconView.swift @@ -1,4 +1,5 @@ import SwiftUI +import WordPressMedia struct ReaderSiteIconView: View, Hashable { let site: ReaderSiteTopic