From 30c44319731baf8356d592458ab49633922f7ed9 Mon Sep 17 00:00:00 2001 From: Marceau Tonelli Date: Thu, 19 Dec 2024 13:21:20 +0100 Subject: [PATCH 1/3] Resolve implicitly_unwrapped_optional violations in ReadabilityService --- firefox-ios/Client/Frontend/Reader/ReadabilityService.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firefox-ios/Client/Frontend/Reader/ReadabilityService.swift b/firefox-ios/Client/Frontend/Reader/ReadabilityService.swift index 6f24280b8121..cc0e39b779ab 100644 --- a/firefox-ios/Client/Frontend/Reader/ReadabilityService.swift +++ b/firefox-ios/Client/Frontend/Reader/ReadabilityService.swift @@ -98,7 +98,7 @@ class ReadabilityOperation: Operation, @unchecked Sendable { extension ReadabilityOperation: WKNavigationDelegate { func webView( _ webView: WKWebView, - didFail navigation: WKNavigation!, + didFail navigation: WKNavigation?, withError error: Error ) { result = ReadabilityOperationResult.error(error as NSError) @@ -107,14 +107,14 @@ extension ReadabilityOperation: WKNavigationDelegate { func webView( _ webView: WKWebView, - didFailProvisionalNavigation navigation: WKNavigation!, + didFailProvisionalNavigation navigation: WKNavigation?, withError error: Error ) { result = ReadabilityOperationResult.error(error as NSError) semaphore.signal() } - func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { + func webView(_ webView: WKWebView, didFinish navigation: WKNavigation?) { webView.evaluateJavascriptInDefaultContentWorld("\(ReaderModeNamespace).checkReadability()") } } From 77672a2e7b06e1cf2f0a0450a4565ea6f651ab5e Mon Sep 17 00:00:00 2001 From: Marceau Tonelli Date: Thu, 19 Dec 2024 13:27:59 +0100 Subject: [PATCH 2/3] Resolve implicitly_unwrapped_optional violations in ReaderModeStyleViewController --- .../View/ReaderModeStyleViewController.swift | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/firefox-ios/Client/Frontend/Reader/View/ReaderModeStyleViewController.swift b/firefox-ios/Client/Frontend/Reader/View/ReaderModeStyleViewController.swift index 491704c6687e..d9f28259ef0d 100644 --- a/firefox-ios/Client/Frontend/Reader/View/ReaderModeStyleViewController.swift +++ b/firefox-ios/Client/Frontend/Reader/View/ReaderModeStyleViewController.swift @@ -10,23 +10,23 @@ import Common class ReaderModeStyleViewController: UIViewController, Themeable { // UI views - private var fontTypeButtons: [ReaderModeFontTypeButton]! - private var fontSizeLabel: ReaderModeFontSizeLabel! - private var fontSizeButtons: [ReaderModeFontSizeButton]! - private var themeButtons: [ReaderModeThemeButton]! + private var fontTypeButtons: [ReaderModeFontTypeButton] = [] + private var fontSizeLabel: ReaderModeFontSizeLabel? + private var fontSizeButtons: [ReaderModeFontSizeButton] = [] + private var themeButtons: [ReaderModeThemeButton] = [] private var brightnessImageViews = [UIImageView]() private var separatorLines = [UIView.build(), UIView.build(), UIView.build()] - private var fontTypeRow: UIView! - private var fontSizeRow: UIView! - private var brightnessRow: UIView! + private var fontTypeRow: UIView? + private var fontSizeRow: UIView? + private var brightnessRow: UIView? private lazy var slider: UISlider = .build { slider in slider.accessibilityLabel = .ReaderModeStyleBrightnessAccessibilityLabel slider.addTarget(self, action: #selector(self.changeBrightness), for: .valueChanged) } - private var viewModel: ReaderModeStyleViewModel! + private var viewModel: ReaderModeStyleViewModel var themeManager: ThemeManager var themeObserver: NSObjectProtocol? var notificationCenter: NotificationProtocol @@ -59,7 +59,8 @@ class ReaderModeStyleViewController: UIViewController, Themeable { ) // Font type row - fontTypeRow = .build() + + let fontTypeRow: UIView = .build() view.addSubview(fontTypeRow) NSLayoutConstraint.activate([ @@ -68,6 +69,7 @@ class ReaderModeStyleViewController: UIViewController, Themeable { fontTypeRow.rightAnchor.constraint(equalTo: view.rightAnchor), fontTypeRow.heightAnchor.constraint(equalToConstant: ReaderModeStyleViewModel.UX.RowHeight), ]) + self.fontTypeRow = fontTypeRow fontTypeButtons = [ ReaderModeFontTypeButton(fontType: ReaderModeFontType.sansSerif), @@ -81,7 +83,7 @@ class ReaderModeStyleViewController: UIViewController, Themeable { // Font size row - fontSizeRow = .build() + let fontSizeRow: UIView = .build() view.addSubview(fontSizeRow) NSLayoutConstraint.activate([ @@ -90,14 +92,16 @@ class ReaderModeStyleViewController: UIViewController, Themeable { fontSizeRow.rightAnchor.constraint(equalTo: view.rightAnchor), fontSizeRow.heightAnchor.constraint(equalToConstant: ReaderModeStyleViewModel.UX.RowHeight), ]) + self.fontSizeRow = fontSizeRow - fontSizeLabel = .build() + let fontSizeLabel: ReaderModeFontSizeLabel = .build() fontSizeRow.addSubview(fontSizeLabel) NSLayoutConstraint.activate([ fontSizeLabel.centerXAnchor.constraint(equalTo: fontSizeRow.centerXAnchor), fontSizeLabel.centerYAnchor.constraint(equalTo: fontSizeRow.centerYAnchor), ]) + self.fontSizeLabel = fontSizeLabel fontSizeButtons = [ ReaderModeFontSizeButton(fontSizeAction: FontSizeAction.smaller), @@ -137,7 +141,7 @@ class ReaderModeStyleViewController: UIViewController, Themeable { // Brightness row - brightnessRow = .build() + let brightnessRow: UIView = .build() view.addSubview(brightnessRow) NSLayoutConstraint.activate( [ @@ -151,6 +155,7 @@ class ReaderModeStyleViewController: UIViewController, Themeable { ), ] ) + self.brightnessRow = brightnessRow brightnessRow.addSubview(slider) NSLayoutConstraint.activate( @@ -216,7 +221,7 @@ class ReaderModeStyleViewController: UIViewController, Themeable { view?.backgroundColor = theme.colors.layer1 } - fontSizeLabel.textColor = theme.colors.textPrimary + fontSizeLabel?.textColor = theme.colors.textPrimary fontTypeButtons.forEach { button in button.setTitleColor(theme.colors.textPrimary, @@ -288,7 +293,7 @@ class ReaderModeStyleViewController: UIViewController, Themeable { for button in themeButtons { button.fontType = fontType } - fontSizeLabel.fontType = fontType + fontSizeLabel?.fontType = fontType } @objc From c8f4042e37393f673b92a35520ccf6cd83486d9d Mon Sep 17 00:00:00 2001 From: Marceau Tonelli Date: Thu, 19 Dec 2024 13:30:35 +0100 Subject: [PATCH 3/3] Resolve implicitly_unwrapped_optional violations in ReaderModeThemeButton --- .../Frontend/Reader/View/ReaderModeStyleViewController.swift | 3 ++- .../Client/Frontend/Reader/View/ReaderModeThemeButton.swift | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/firefox-ios/Client/Frontend/Reader/View/ReaderModeStyleViewController.swift b/firefox-ios/Client/Frontend/Reader/View/ReaderModeStyleViewController.swift index d9f28259ef0d..fcbec9e1fb13 100644 --- a/firefox-ios/Client/Frontend/Reader/View/ReaderModeStyleViewController.swift +++ b/firefox-ios/Client/Frontend/Reader/View/ReaderModeStyleViewController.swift @@ -319,7 +319,8 @@ class ReaderModeStyleViewController: UIViewController, Themeable { @objc func changeTheme(_ button: ReaderModeThemeButton) { - viewModel.readerModeDidChangeTheme(button.readerModeTheme) + guard let readerModeTheme = button.readerModeTheme else { return } + viewModel.readerModeDidChangeTheme(readerModeTheme) } @objc diff --git a/firefox-ios/Client/Frontend/Reader/View/ReaderModeThemeButton.swift b/firefox-ios/Client/Frontend/Reader/View/ReaderModeThemeButton.swift index eabae769994a..0533e370006f 100644 --- a/firefox-ios/Client/Frontend/Reader/View/ReaderModeThemeButton.swift +++ b/firefox-ios/Client/Frontend/Reader/View/ReaderModeThemeButton.swift @@ -7,7 +7,7 @@ import UIKit import Shared class ReaderModeThemeButton: UIButton { - var readerModeTheme: ReaderModeTheme! + var readerModeTheme: ReaderModeTheme? var fontType: ReaderModeFontType = .sansSerif { didSet {