Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove widget favicon coupling and move favicon code from core to the app #3590

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Core/FaviconHasher.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// FaviconHasher.swift
// DuckDuckGo
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//


import Foundation
import Kingfisher

public struct FaviconHasher {

static let salt = "DDGSalt:"
public static func createHash(ofDomain domain: String) -> String {
return "\(Self.salt)\(domain)".sha256()
}

}
1 change: 1 addition & 0 deletions Core/FaviconRequestModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// limitations under the License.
//

import Core
import Kingfisher

class FaviconRequestModifier: ImageDownloadRequestModifier {
Expand Down
43 changes: 43 additions & 0 deletions Core/FaviconsCacheType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// FaviconsCacheType.swift
// DuckDuckGo
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

public enum FaviconsCacheType: String {

static let faviconsFolderName = "Favicons"

case tabs
case fireproof

public func cacheLocation() -> URL? {
return baseCacheURL()?.appendingPathComponent(Self.faviconsFolderName)
}

private func baseCacheURL() -> URL? {
switch self {
case .fireproof:
let groupName = BookmarksDatabase.Constants.bookmarksGroupID
return FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupName)

case .tabs:
return FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first
}
}
}
34 changes: 0 additions & 34 deletions Core/FaviconsHelper.swift

This file was deleted.

1 change: 1 addition & 0 deletions Core/NotFoundCachingDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// limitations under the License.
//

import Core
import Kingfisher

class NotFoundCachingDownloader: ImageDownloader {
Expand Down
8 changes: 6 additions & 2 deletions Core/SyncBookmarksAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
public let databaseCleaner: BookmarkDatabaseCleaner
public let syncDidCompletePublisher: AnyPublisher<Void, Never>
let syncErrorHandler: SyncErrorHandling
private let faviconStoring: FaviconStoring

@UserDefaultsWrapper(key: .syncDidMigrateToImprovedListsHandling, defaultValue: false)
private var didMigrateToImprovedListsHandling: Bool
Expand All @@ -88,10 +89,13 @@

public init(database: CoreDataDatabase,
favoritesDisplayModeStorage: FavoritesDisplayModeStoring,
syncErrorHandler: SyncErrorHandling) {
syncErrorHandler: SyncErrorHandling,
faviconStoring: FaviconStoring) {
self.database = database
self.favoritesDisplayModeStorage = favoritesDisplayModeStorage
self.syncErrorHandler = syncErrorHandler
self.faviconStoring = faviconStoring

syncDidCompletePublisher = syncDidCompleteSubject.eraseToAnyPublisher()
databaseCleaner = BookmarkDatabaseCleaner(
bookmarkDatabase: database,
Expand Down Expand Up @@ -172,7 +176,7 @@
database: database,
stateStore: stateStore,
fetcher: FaviconFetcher(),
faviconStore: Favicons.shared,
faviconStore: faviconStoring,
errorEvents: BookmarksFaviconsFetcherErrorHandler()
)
}
Expand All @@ -192,7 +196,7 @@
Logger.sync.debug("Favicons Fetching is in progress. Starting background task to allow it to gracefully complete.")

var taskID: UIBackgroundTaskIdentifier!
taskID = application.beginBackgroundTask(withName: "Cancelled Favicons Fetching Completion Task") {

Check warning on line 199 in Core/SyncBookmarksAdapter.swift

View workflow job for this annotation

GitHub Actions / Unit Tests

'taskID' mutated after capture by sendable closure

Check warning on line 199 in Core/SyncBookmarksAdapter.swift

View workflow job for this annotation

GitHub Actions / Make Release Build

'taskID' mutated after capture by sendable closure
Logger.sync.debug("Forcing background task completion")
application.endBackgroundTask(taskID)
}
Expand Down
6 changes: 4 additions & 2 deletions Core/SyncDataProviders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ public class SyncDataProviders: DataProvidersSource {
secureVaultErrorReporter: SecureVaultReporting,
settingHandlers: [SettingSyncHandler],
favoritesDisplayModeStorage: FavoritesDisplayModeStoring,
syncErrorHandler: SyncErrorHandling
syncErrorHandler: SyncErrorHandling,
faviconStoring: FaviconStoring
) {
self.bookmarksDatabase = bookmarksDatabase
self.secureVaultFactory = secureVaultFactory
self.secureVaultErrorReporter = secureVaultErrorReporter
bookmarksAdapter = SyncBookmarksAdapter(database: bookmarksDatabase,
favoritesDisplayModeStorage: favoritesDisplayModeStorage,
syncErrorHandler: syncErrorHandler)
syncErrorHandler: syncErrorHandler,
faviconStoring: faviconStoring)
credentialsAdapter = SyncCredentialsAdapter(secureVaultFactory: secureVaultFactory,
secureVaultErrorReporter: secureVaultErrorReporter,
syncErrorHandler: syncErrorHandler)
Expand Down
Loading
Loading