Skip to content

Refactor FXIOS-7301 - Remove 2 closure_body_length violations from MainMenuMiddleware.swift (Firefox) and InternalTelemetrySettingsView.swift (Focus) #26242

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3b968da
Decrease warning and error threshold
ionixjunior Apr 14, 2025
8bb8a0f
Extract the MainMenuActionType to a new function
ionixjunior Apr 14, 2025
258e789
Rename function
ionixjunior Apr 14, 2025
c84de6a
Extract the GeneralBrowserActionType to a new function
ionixjunior Apr 14, 2025
d00f11b
Extract the MainMenuDetailsActionType to a new function
ionixjunior Apr 14, 2025
7a6e5a5
Use the new function to handle MainMenuActionType
ionixjunior Apr 14, 2025
eceae43
Use the new function to handle GeneralBrowserActionType
ionixjunior Apr 14, 2025
6144980
Use the new function to handle MainMenuDetailsActionType
ionixjunior Apr 14, 2025
316a47f
Remove the inner switch case
ionixjunior Apr 14, 2025
fc7f42a
Extract the logging section to a new property
ionixjunior Apr 22, 2025
c9337b3
Use the new property to show the logging section
ionixjunior Apr 22, 2025
7db04a4
Extract the debug view section to a new property
ionixjunior Apr 22, 2025
db2778f
Use the new property to show the debug view section
ionixjunior Apr 22, 2025
2d97454
Extract the event pings section to a new property
ionixjunior Apr 22, 2025
5bddc22
Use the new property to show the event pings section
ionixjunior Apr 22, 2025
9fd2c54
Check action type before to call handle method
ionixjunior Apr 28, 2025
844d0f1
Check action type before to call handle method
ionixjunior Apr 28, 2025
99c9e2b
Check action type before to call handle method
ionixjunior Apr 28, 2025
3b6d3f7
Revert "Check action type before to call handle method"
ionixjunior May 12, 2025
c5ddf5e
Revert "Check action type before to call handle method"
ionixjunior May 12, 2025
d762b6e
Revert "Check action type before to call handle method"
ionixjunior May 12, 2025
e42a346
Revert "Remove the inner switch case"
ionixjunior May 12, 2025
0e66df5
Revert "Use the new function to handle MainMenuDetailsActionType"
ionixjunior May 12, 2025
f11b152
Revert "Use the new function to handle GeneralBrowserActionType"
ionixjunior May 12, 2025
daa65a9
Revert "Use the new function to handle MainMenuActionType"
ionixjunior May 12, 2025
77bb467
Revert "Extract the MainMenuDetailsActionType to a new function"
ionixjunior May 12, 2025
5ea26eb
Revert "Extract the GeneralBrowserActionType to a new function"
ionixjunior May 12, 2025
a8c9b78
Revert "Rename function"
ionixjunior May 12, 2025
2792508
Revert "Extract the MainMenuActionType to a new function"
ionixjunior May 12, 2025
ae4761b
Extract the entire switch case statement to a new function
ionixjunior May 12, 2025
fa25411
Use the new function to handle all main menu actions
ionixjunior May 12, 2025
6e80514
Fix trailing whitespace violation
ionixjunior May 12, 2025
28d2b1c
Remove self
ionixjunior May 12, 2025
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
4 changes: 2 additions & 2 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ line_length:
ignores_interpolated_strings: true

closure_body_length:
warning: 43
error: 43
warning: 42
error: 42

file_header:
required_string: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,63 +54,67 @@ final class MainMenuMiddleware {
guard let action = action as? MainMenuAction else { return }
let isHomepage = action.telemetryInfo?.isHomepage ?? false

self.handleMainMenuActions(action: action, isHomepage: isHomepage)
}

private func handleMainMenuActions(action: MainMenuAction, isHomepage: Bool) {
switch action.actionType {
case MainMenuActionType.tapNavigateToDestination:
self.handleTapNavigateToDestinationAction(action: action, isHomepage: isHomepage)
handleTapNavigateToDestinationAction(action: action, isHomepage: isHomepage)

case MainMenuActionType.tapShowDetailsView:
self.handleTapShowDetailsViewAction(action: action, isHomepage: isHomepage)
handleTapShowDetailsViewAction(action: action, isHomepage: isHomepage)

case MainMenuActionType.tapToggleUserAgent:
self.handleTapToggleUserAgentAction(action: action, isHomepage: isHomepage)
handleTapToggleUserAgentAction(action: action, isHomepage: isHomepage)

case MainMenuActionType.tapCloseMenu:
self.telemetry.closeButtonTapped(isHomepage: isHomepage)
telemetry.closeButtonTapped(isHomepage: isHomepage)

case GeneralBrowserActionType.showReaderMode:
self.handleShowReaderModeAction(action: action)
handleShowReaderModeAction(action: action)

case MainMenuActionType.didInstantiateView:
self.handleDidInstantiateViewAction(action: action)
handleDidInstantiateViewAction(action: action)

case MainMenuActionType.viewDidLoad:
self.handleViewDidLoadAction(action: action)
handleViewDidLoadAction(action: action)

case MainMenuActionType.menuDismissed:
self.telemetry.menuDismissed(isHomepage: isHomepage)
telemetry.menuDismissed(isHomepage: isHomepage)

case MainMenuDetailsActionType.tapZoom:
self.telemetry.toolsSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.zoom)
telemetry.toolsSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.zoom)

case MainMenuDetailsActionType.tapReportBrokenSite:
self.telemetry.toolsSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.reportBrokenSite)
telemetry.toolsSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.reportBrokenSite)

case MainMenuDetailsActionType.tapAddToBookmarks:
self.telemetry.saveSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.bookmarkThisPage)
telemetry.saveSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.bookmarkThisPage)

case MainMenuDetailsActionType.tapEditBookmark:
self.telemetry.saveSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.editBookmark)
telemetry.saveSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.editBookmark)

case MainMenuDetailsActionType.tapAddToShortcuts:
self.telemetry.saveSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.addToShortcuts)
telemetry.saveSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.addToShortcuts)

case MainMenuDetailsActionType.tapRemoveFromShortcuts:
self.telemetry.saveSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.removeFromShortcuts)
telemetry.saveSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.removeFromShortcuts)

case MainMenuDetailsActionType.tapAddToReadingList:
self.telemetry.saveSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.saveToReadingList)
telemetry.saveSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.saveToReadingList)

case MainMenuDetailsActionType.tapRemoveFromReadingList:
self.telemetry.saveSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.removeFromReadingList)
telemetry.saveSubmenuOptionTapped(with: isHomepage, and: TelemetryAction.removeFromReadingList)

case MainMenuDetailsActionType.tapToggleNightMode:
self.handleTapToggleNightModeAction(action: action, isHomepage: isHomepage)
handleTapToggleNightModeAction(action: action, isHomepage: isHomepage)

case MainMenuDetailsActionType.tapBackToMainMenu:
self.handleTapBackToMainMenuAction(action: action, isHomepage: isHomepage)
handleTapBackToMainMenuAction(action: action, isHomepage: isHomepage)

case MainMenuDetailsActionType.tapDismissView:
self.telemetry.closeButtonTapped(isHomepage: isHomepage)
telemetry.closeButtonTapped(isHomepage: isHomepage)

default: break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,57 +56,69 @@ extension InternalTelemetrySettingsView: View {
var body: some View {
Form {
if #available(iOS 14, *) {
SwiftUI.Section(header: Text(verbatim: "Logging")) {
Toggle(isOn: $internalSettings.gleanLogPingsToConsole) {
VStack(alignment: .leading) {
Text(verbatim: "Log Pings to Console")
}
}.onChange(of: internalSettings.gleanLogPingsToConsole, perform: changeLogPingsToConsole)
loggingSection

debugViewSection

eventPingsSection
} else {
Text(verbatim: "Internal Telemetry Settings are only available on iOS 14 and newer.")
}
}.navigationBarTitle(Text(verbatim: "Telemetry"))
}

private var loggingSection: some View {
return SwiftUI.Section(header: Text(verbatim: "Logging")) {
Toggle(isOn: $internalSettings.gleanLogPingsToConsole) {
VStack(alignment: .leading) {
Text(verbatim: "Log Pings to Console")
}
}.onChange(of: internalSettings.gleanLogPingsToConsole, perform: changeLogPingsToConsole)
}
}

SwiftUI.Section(header: Text(verbatim: "Debug View")) {
Toggle(isOn: $internalSettings.gleanEnableDebugView) {
VStack(alignment: .leading) {
Text(verbatim: "Enable Debug View")
Text(verbatim: "Requires app restart").font(.caption)
}
}.disabled(internalSettings.gleanDebugViewTag.isEmpty)

VStack(alignment: .leading) {
TextField("Debug View Tag", text: $internalSettings.gleanDebugViewTag)
.onChange(of: internalSettings.gleanDebugViewTag, perform: changeDebugViewTag)
}

Button(action: { UIApplication.shared.open(GleanDebugViewURL) }) {
Text(verbatim: "Open Debug View (In Default Browser)")
}

Button(action: { UIPasteboard.general.url = GleanDebugViewURL }) {
Text(verbatim: "Copy Debug View Link")
}
private var debugViewSection: some View {
return SwiftUI.Section(header: Text(verbatim: "Debug View")) {
Toggle(isOn: $internalSettings.gleanEnableDebugView) {
VStack(alignment: .leading) {
Text(verbatim: "Enable Debug View")
Text(verbatim: "Requires app restart").font(.caption)
}
}.disabled(internalSettings.gleanDebugViewTag.isEmpty)

VStack(alignment: .leading) {
TextField("Debug View Tag", text: $internalSettings.gleanDebugViewTag)
.onChange(of: internalSettings.gleanDebugViewTag, perform: changeDebugViewTag)
}

Button(action: { UIApplication.shared.open(GleanDebugViewURL) }) {
Text(verbatim: "Open Debug View (In Default Browser)")
}

SwiftUI.Section {
Button(action: { sendPendingEventPings() }) {
Text(verbatim: "Send Pending Event Pings")
}
Button(action: { UIPasteboard.general.url = GleanDebugViewURL }) {
Text(verbatim: "Copy Debug View Link")
}
}
}

Button(action: { sendPendingBaselinePings() }) {
Text(verbatim: "Send Baseline Event Pings")
}
private var eventPingsSection: some View {
return SwiftUI.Section {
Button(action: { sendPendingEventPings() }) {
Text(verbatim: "Send Pending Event Pings")
}

Button(action: { sendPendingMetricsPings() }) {
Text(verbatim: "Send Metrics Event Pings")
}
Button(action: { sendPendingBaselinePings() }) {
Text(verbatim: "Send Baseline Event Pings")
}

Button(action: { sendPendingDeletionRequestPings() }) {
Text(verbatim: "Send Deletion Request Event Pings")
}
}
} else {
Text(verbatim: "Internal Telemetry Settings are only available on iOS 14 and newer.")
Button(action: { sendPendingMetricsPings() }) {
Text(verbatim: "Send Metrics Event Pings")
}
}.navigationBarTitle(Text(verbatim: "Telemetry"))

Button(action: { sendPendingDeletionRequestPings() }) {
Text(verbatim: "Send Deletion Request Event Pings")
}
}
}
}

Expand Down