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

use instance var for TLD in text zoom coordinator #3823

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Changes from all 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
14 changes: 8 additions & 6 deletions DuckDuckGo/TextZoomCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protocol TextZoomCoordinating {
func onTextZoomChange(applyToWebView webView: WKWebView)

/// Shows a text zoom editor for the current webview. Does nothing if the feature is disabled.
func showTextZoomEditor(inController controller: UIViewController, forWebView webView: WKWebView)
func showTextZoomEditor(inController controller: UIViewController, forWebView webView: WKWebView) async
miasma13 marked this conversation as resolved.
Show resolved Hide resolved

/// Creates a browsing menu entry for the given link. Returns nil if the feature is disabled.
func makeBrowsingMenuEntry(forLink: Link, inController controller: UIViewController, forWebView webView: WKWebView) -> BrowsingMenuEntry?
Expand All @@ -63,27 +63,29 @@ final class TextZoomCoordinator: TextZoomCoordinating {
let appSettings: AppSettings
let storage: TextZoomStoring
let featureFlagger: FeatureFlagger
let tld: TLD

var isEnabled: Bool {
featureFlagger.isFeatureOn(.textZoom)
}

init(appSettings: AppSettings, storage: TextZoomStoring, featureFlagger: FeatureFlagger) {
init(appSettings: AppSettings, storage: TextZoomStoring, featureFlagger: FeatureFlagger, tld: TLD = TLD()) {
self.appSettings = appSettings
self.storage = storage
self.featureFlagger = featureFlagger
self.tld = tld
}

func textZoomLevel(forHost host: String?) -> TextZoomLevel {
let domain = TLD().eTLDplus1(host) ?? ""
let domain = tld.eTLDplus1(host) ?? ""
// If the webview returns no host then there won't be a setting for a blank string anyway.
return storage.textZoomLevelForDomain(domain)
// And if there's no setting for whatever domain is passed in, use the app default
?? appSettings.defaultTextZoomLevel
}

func set(textZoomLevel level: TextZoomLevel, forHost host: String?) {
guard let domain = TLD().eTLDplus1(host) else { return }
guard let domain = tld.eTLDplus1(host) else { return }
if level == appSettings.defaultTextZoomLevel {
storage.removeTextZoomLevel(forDomain: domain)
} else {
Expand Down Expand Up @@ -118,7 +120,7 @@ final class TextZoomCoordinator: TextZoomCoordinating {
func showTextZoomEditor(inController controller: UIViewController, forWebView webView: WKWebView) {
guard isEnabled else { return }

guard let domain = TLD().eTLDplus1(webView.url?.host) else { return }
guard let domain = tld.eTLDplus1(webView.url?.host) else { return }
let zoomController = TextZoomController(
domain: domain,
coordinator: self,
Expand Down Expand Up @@ -147,7 +149,7 @@ final class TextZoomCoordinator: TextZoomCoordinating {
guard isEnabled else { return nil }

let label: String
if let domain = TLD().eTLDplus1(link.url.host),
if let domain = tld.eTLDplus1(link.url.host),
let level = storage.textZoomLevelForDomain(domain) {
label = UserText.textZoomWithPercentForMenuItem(level.rawValue)
} else {
Expand Down
Loading