Skip to content
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
40 changes: 29 additions & 11 deletions iOS/Views/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ class SettingsViewController: FRSTableViewController {
// Set up UI with proper error handling
try safeInitialize()
backdoor.Debug.shared.log(message: "SettingsViewController initialized successfully", type: .info)

// Add LED effects to important sections after a delay to ensure layout is complete
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
self?.addLEDEffectsToImportantCells()
}
} catch {
backdoor.Debug.shared.log(message: "SettingsViewController initialization failed: \(error)", type: .error)

Expand All @@ -92,11 +87,11 @@ class SettingsViewController: FRSTableViewController {

/// Add LED effects to highlight important settings cells
private func addLEDEffectsToImportantCells() {
// Only apply effects if the view is visible
guard isViewLoaded && view.window != nil else { return }

// Only apply effects if the view is visible and initialized
guard isViewLoaded && view.window != nil && isInitialized else { return }
// Get visible cells to apply effects only to what the user can see
let visibleCells = tableView.visibleCells
guard let visibleCells = tableView.visibleCells as? [UITableViewCell] else { return }

for cell in visibleCells {
// Apply LED effects based on cell content
Expand Down Expand Up @@ -171,11 +166,19 @@ class SettingsViewController: FRSTableViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

// Refresh LED effects when view appears
addLEDEffectsToImportantCells()
// Only add LED effects if view is initialized
if isInitialized {
// Delay LED effects to ensure view is fully loaded
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
self?.addLEDEffectsToImportantCells()
}
}
}

override func tableView(_: UITableView, willDisplay cell: UITableViewCell, forRowAt _: IndexPath) {
// Only apply LED effects if view is initialized
guard isInitialized else { return }

// Apply LED effects to newly visible cells
if let text = cell.textLabel?.text {
switch text {
Expand Down Expand Up @@ -309,6 +312,13 @@ extension SettingsViewController {
cell.accessoryType = .none
cell.selectionStyle = .none

// Safety check to prevent crashes
guard isInitialized,
indexPath.section < tableData.count,
indexPath.row < tableData[indexPath.section].count else {
return cell
}

let cellText = tableData[indexPath.section][indexPath.row]
cell.textLabel?.text = cellText

Expand Down Expand Up @@ -396,6 +406,14 @@ extension SettingsViewController {
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// Safety check to prevent crashes
guard isInitialized,
indexPath.section < tableData.count,
indexPath.row < tableData[indexPath.section].count else {
tableView.deselectRow(at: indexPath, animated: true)
return
}

let itemTapped = tableData[indexPath.section][indexPath.row]
switch itemTapped {
case String.localized("SETTINGS_VIEW_CONTROLLER_CELL_ABOUT", arguments: "Backdoor"):
Expand Down
Loading