Skip to content

Commit

Permalink
Fix passing favicon resource to the google pinned tile.
Browse files Browse the repository at this point in the history
  • Loading branch information
ih-codes committed Jan 17, 2025
1 parent 04d95da commit 8641fed
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,17 @@ class TopSiteCell: UICollectionViewCell, ReusableCell {
case .pinnedSite, .suggestedSite:
imageResource = topSite.site.faviconResource
default:
if let siteURL = URL(string: siteURLString),
let domainNoTLD = siteURL.baseDomain?.split(separator: ".").first,
domainNoTLD == "google" {
// Exception for Google top sites, which all return blurry low quality favicons that on the home screen.
// Return our bundled G icon for all of the Google Suite.
// Parse example: "https://drive.google.com/drive/home" > "drive.google.com" > "google"
imageResource = GoogleTopSiteManager.Constants.faviconResource
}
break
}

if imageResource == nil,
let siteURL = URL(string: siteURLString),
let domainNoTLD = siteURL.baseDomain?.split(separator: ".").first,
domainNoTLD == "google" {
// Exception for Google top sites, which all return blurry low quality favicons that on the home screen.
// Return our bundled G icon for all of the Google Suite.
// Parse example: "https://drive.google.com/drive/home" > "drive.google.com" > "google"
imageResource = GoogleTopSiteManager.Constants.faviconResource
}

let viewModel = FaviconImageViewModel(siteURLString: siteURLString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,17 @@ class TopSiteItemCell: UICollectionViewCell, ReusableCell {
case .pinnedSite, .suggestedSite:
imageResource = topSite.site.faviconResource
default:
if let siteURL = URL(string: siteURLString),
let domainNoTLD = siteURL.baseDomain?.split(separator: ".").first,
domainNoTLD == "google" {
// Exception for Google top sites, which all return blurry low quality favicons that on the home screen.
// Return our bundled G icon for all of the Google Suite.
// Parse example: "https://drive.google.com/drive/home" > "drive.google.com" > "google"
imageResource = GoogleTopSiteManager.Constants.faviconResource
}
break
}

if imageResource == nil,
let siteURL = URL(string: siteURLString),
let domainNoTLD = siteURL.baseDomain?.split(separator: ".").first,
domainNoTLD == "google" {
// Exception for Google top sites, which all return blurry low quality favicons that on the home screen.
// Return our bundled G icon for all of the Google Suite.
// Parse example: "https://drive.google.com/drive/home" > "drive.google.com" > "google"
imageResource = GoogleTopSiteManager.Constants.faviconResource
}

let viewModel = FaviconImageViewModel(siteURLString: siteURLString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ class GoogleTopSiteManager: GoogleTopSiteManagerProvider {
var pinnedSiteData: Site? {
guard let url = self.url else { return nil }

let pinnedSite = Site.createPinnedSite(url: url, title: "Google", isGooglePinnedTile: true)
let pinnedSite = Site.createPinnedSite(
url: url,
title: "Google",
isGooglePinnedTile: true,
faviconResource: Constants.faviconResource
)

return pinnedSite
}
Expand Down
27 changes: 19 additions & 8 deletions firefox-ios/Storage/Sites/Site.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct Site: Identifiable, Hashable, Equatable, Codable {
public let type: SiteType

// MARK: - Other information
public var faviconResource: SiteImageView.SiteResource?
public var faviconResource: SiteResource?
public var metadata: PageMetadata?
public var latestVisit: Visit?
public var isBookmarked: Bool?
Expand Down Expand Up @@ -46,7 +46,7 @@ public struct Site: Identifiable, Hashable, Equatable, Codable {
url: String,
title: String,
isBookmarked: Bool? = nil,
faviconResource: SiteImageView.SiteResource? = nil
faviconResource: SiteResource? = nil
) -> Site {
var site = Site(id: id ?? UUID().hashValue, url: url, title: title, type: .basic)
site.isBookmarked = isBookmarked
Expand All @@ -62,7 +62,7 @@ public struct Site: Identifiable, Hashable, Equatable, Codable {
url: String,
title: String,
trackingId: Int,
faviconResource: SiteImageView.SiteResource? = nil
faviconResource: SiteResource? = nil
) -> Site {
let siteInfo = SuggestedSiteInfo(trackingId: trackingId)
return Site(
Expand All @@ -74,9 +74,20 @@ public struct Site: Identifiable, Hashable, Equatable, Codable {
)
}

public static func createPinnedSite(url: String, title: String, isGooglePinnedTile: Bool) -> Site {
public static func createPinnedSite(
url: String,
title: String,
isGooglePinnedTile: Bool,
faviconResource: SiteResource? = nil
) -> Site {
let siteInfo = PinnedSiteInfo(isGooglePinnedTile: isGooglePinnedTile)
return Site(id: UUID().hashValue, url: url, title: title, type: .pinnedSite(siteInfo))
return Site(
id: UUID().hashValue,
url: url,
title: title,
type: .pinnedSite(siteInfo),
faviconResource: faviconResource
)
}

public static func createPinnedSite(fromSite site: Site, isGooglePinnedTile: Bool = false) -> Site {
Expand Down Expand Up @@ -109,7 +120,7 @@ public struct Site: Identifiable, Hashable, Equatable, Codable {

// MARK: - Initializers

private init(id: Int, url: String, title: String, type: SiteType, faviconResource: SiteImageView.SiteResource? = nil) {
private init(id: Int, url: String, title: String, type: SiteType, faviconResource: SiteResource? = nil) {
self.id = id
self.url = url
self.title = title
Expand All @@ -122,7 +133,7 @@ public struct Site: Identifiable, Hashable, Equatable, Codable {
url: String,
title: String,
type: SiteType,
faviconResource: SiteImageView.SiteResource? = nil,
faviconResource: SiteResource? = nil,
metadata: PageMetadata? = nil,
latestVisit: Visit? = nil,
isBookmarked: Bool? = nil
Expand Down Expand Up @@ -190,7 +201,7 @@ public struct Site: Identifiable, Hashable, Equatable, Codable {
let type = (try? values.decode(SiteType.self, forKey: .type)) ?? .basic

// Optional properties
let faviconResource = try? values.decode(SiteImageView.SiteResource.self, forKey: .faviconResource)
let faviconResource = try? values.decode(SiteResource.self, forKey: .faviconResource)

self.init(id: id ?? UUID().hashValue, url: url, title: title, type: type, faviconResource: faviconResource)
}
Expand Down

0 comments on commit 8641fed

Please sign in to comment.