Skip to content

KM-13703 Fix persisting "Enable Debug Logging" and "Help Improve PIA" toggles - #235

Merged
kp-diego-trevisan merged 1 commit into
masterfrom
KM-13703-debug-logging-toggle-does-not-persist
Jan 9, 2026
Merged

KM-13703 Fix persisting "Enable Debug Logging" and "Help Improve PIA" toggles#235
kp-diego-trevisan merged 1 commit into
masterfrom
KM-13703-debug-logging-toggle-does-not-persist

Conversation

@kp-diego-trevisan

Copy link
Copy Markdown
Collaborator

Summary

Fixes the issue that both toggles don't show correct values once the settings screen is closed and opened again.

@claude

claude Bot commented Jan 9, 2026

Copy link
Copy Markdown

Claude finished @kp-diego-trevisan's task —— View job


PR Code Review Complete ✅

Reviewing PR: KM-13703 Fix persisting "Enable Debug Logging" and "Help Improve PIA" toggles

Todo List:

  • Read and analyze the modified file
  • Review code quality and best practices
  • Check for potential bugs or issues
  • Evaluate memory management and retain cycles
  • Assess threading issues
  • Consider performance implications
  • Review security concerns
  • Evaluate test coverage needs
  • Provide comprehensive feedback

Code Quality & Analysis 📋

Positive Changes

  1. Architectural Consistency: The changes align with the existing architecture where child settings controllers inherit pendingPreferences from PIABaseSettingsViewController and use the centralized preferences management.

  2. Code Simplification: Removes redundant code by eliminating the need to create local editable preference instances and manually commit them.

  3. Bug Fix: Addresses the core issue where toggle states weren't persisting correctly by using the proper preferences reference.

⚠️ Areas of Concern

1. Missing Dependency Injection Verification

The code assumes pendingPreferences is properly injected by the parent SettingsViewController, but there's no nil-checking or defensive programming:

// Current code (vulnerable):
pendingPreferences.debugLogging = sender.isOn

// Safer approach:
guard let preferences = pendingPreferences else { return }
preferences.debugLogging = sender.isOn

Recommendation: Add nil-checking for pendingPreferences in critical methods, especially in viewDidLoad().

2. Inconsistent State Management Pattern

The changes create an inconsistency where:

  • Toggle actions now use pendingPreferences (good)
  • But there's no explicit commit() call to persist changes
  • Other settings controllers call settingsDelegate.savePreferences() or similar

File: HelpSettingsViewController.swift:82-103

Recommendation: Verify that the parent SettingsViewController handles committing these changes appropriately, or add explicit save calls.

3. Missing Error Handling

No error handling for preference updates:

// Could fail silently:
pendingPreferences.debugLogging = sender.isOn

🔒 Security Assessment

✅ No security concerns identified. The changes involve UI state management only and don't expose sensitive data or create security vulnerabilities.

🧵 Threading Analysis

✅ Thread-safe. All UI updates occur on the main thread as expected. The preference updates are synchronous and don't introduce race conditions.

Performance Considerations

✅ Minor performance improvement. Removes unnecessary object creation (Client.preferences.editable()) on each toggle action.

🧠 Memory Management

✅ No memory issues. The weak reference to pendingPreferences in the base class prevents retain cycles. No new memory concerns introduced.

🧪 Test Coverage Recommendations

Consider adding unit tests for:

  1. Verification that toggle states persist correctly after view controller dismissal/recreation
  2. Error handling when pendingPreferences is nil
  3. Integration test ensuring preference changes are saved to persistent storage

📝 Minor Code Style Issues

  1. Line 94-102: Could extract version setting logic into a helper method for better readability
  2. Missing documentation: Methods lack doc comments explaining the preference management pattern

Overall Assessment: ✅ APPROVE

This is a solid bug fix that improves the codebase by:

  • Following established architectural patterns
  • Simplifying code complexity
  • Fixing a real user-facing issue

Suggested Improvements (Non-blocking):

  1. Add nil-checking for pendingPreferences
  2. Verify the commit/save workflow with the parent controller
  3. Add unit tests to prevent regression
  4. Consider extracting service quality version setting logic

The changes are minimal, focused, and follow the existing codebase patterns. The fix addresses the reported issue effectively.


@kp-diego-trevisan
kp-diego-trevisan merged commit f341994 into master Jan 9, 2026
3 checks passed
@kp-diego-trevisan
kp-diego-trevisan deleted the KM-13703-debug-logging-toggle-does-not-persist branch January 9, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants