Skip to content

Conversation

@danperks
Copy link

@danperks danperks commented Sep 8, 2025

This pull request introduces a comprehensive color theme system for the application, enabling users to select from a variety of color schemes—including a customizable option—and ensuring adaptive foreground colors for improved accessibility and visual consistency. The changes span theme management, UI integration, and color utility enhancements.

Theme system and color customization:

  • Added a new ColorTheme enum and ThemeConstants struct to Theme.swift, supporting multiple built-in color themes and a "Custom" option. The theme now adapts its colors based on user selection, with custom colors stored in UserDefaults and updated via notifications.
  • Integrated a color scheme selector UI in GeneralSettingsView.swift, allowing users to pick a theme or define a custom color using a color picker. Custom colors are persisted and trigger live theme updates.
  • Updated AppearanceManager.swift to manage and persist the selected color theme, broadcasting changes via NotificationCenter for reactive updates throughout the app.

Adaptive and contrasting colors:

  • Extended Color+Hex.swift with utility methods for adjusting brightness/saturation, calculating luminance, and determining adaptive/contrasting foreground colors for accessibility. These are used throughout the theme system and UI components.
  • Modified theme and search engine logic to consistently use adaptive foreground colors, ensuring text/icons remain readable across different backgrounds and themes. [1] [2] [3] [4] [5]

Theme propagation and environment integration:

  • Refactored the Theme struct and its environment key to support color theme and update triggers, ensuring theme changes propagate reactively via SwiftUI's environment system. [1] [2]
  • Added adaptive foreground color properties to the Theme struct for various UI backgrounds, improving consistency and readability throughout the app.

- added `ColorTheme` enum with associated colors
- introduced `ThemeConstants` for theme-related constants
- created `ColorPickerView` for selecting custom colors
- updated `GeneralSettingsView` to include color scheme selector
- integrated notifications for theme changes
- enhanced `Color` extension with brightness and saturation adjustments
- added adaptive foreground color properties to `ColorTheme` and `Theme`
- updated `SearchEngine` and `GeneralSettingsView` to use adaptive foreground colors
- improved `Color` extension with luminance calculation and adaptive foreground methods
- refactored color handling for better theme integration
Copilot AI review requested due to automatic review settings September 8, 2025 17:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces a comprehensive color theme system enabling users to select from predefined color schemes or create custom themes through an interactive color picker. The changes ensure adaptive foreground colors for improved accessibility and visual consistency across the application.

  • Added ColorTheme enum with multiple built-in themes and custom option with persistent storage
  • Integrated color picker UI for custom color selection with live preview capabilities
  • Enhanced color utilities with luminance calculation and adaptive foreground color determination

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
ColorPickerView.swift New interactive color picker component with HSB controls and hex input
SearchEngineService.swift Updated to use adaptive foreground colors for search engine icons
AppearanceManager.swift Extended to manage color theme persistence and notifications
GeneralSettingsView.swift Added color scheme selector UI with custom color picker integration
SearchEngine.swift Modified to use adaptive foreground color as fallback
Color+Hex.swift Enhanced with color adjustment, luminance calculation, and adaptive foreground utilities
Theme.swift Restructured to support color themes with adaptive foreground properties

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

DragGesture()
.onChanged { value in
let linearValue = min(max(0, value.location.x / geometry.size.width), 1)
brightness = max(0.35, linearToNonLinearBrightness(linearValue))
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 0.35 appears multiple times (lines 37, 56) as a minimum brightness value. Consider defining this as a constant at the top of the struct for better maintainability.

Copilot uses AI. Check for mistakes.
Comment on lines +137 to +148
private func nonLinearBrightnessToLinear(_ brightness: Double) -> Double {
// Use a power curve: y = x^2 for more precision in bright values
// This maps 0.5 brightness to 0.25 slider position, 0.8 to 0.64, etc.
return pow(brightness, 2.0)
}

// Convert linear slider position (0-1) to non-linear brightness (0-1)
private func linearToNonLinearBrightness(_ linear: Double) -> Double {
// Inverse of the power curve: y = x^0.5
// This maps 0.25 slider to 0.5 brightness, 0.64 to 0.8, etc.
return pow(linear, 0.5)
}
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic numbers 2.0 and 0.5 for the power curve calculations should be defined as constants to make the relationship between these functions clearer and easier to modify.

Copilot uses AI. Check for mistakes.

hue = Double(normalizedAngle)
// Apply inverse non-linear mapping to saturation for more precision in desaturated colors
saturation = Double(pow(normalizedDistance, 2.0))
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another magic number 2.0 used for saturation mapping. This should be consistent with the brightness power curve constants or defined separately if intentionally different.

Copilot uses AI. Check for mistakes.

// Generate a darker version for dark mode
let lightHex = newColor.toHex() ?? "#f3e5d6"
let darkColor = newColor.adjusted(brightness: 0.3, saturation: 1.2)
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic numbers 0.3 and 1.2 for brightness and saturation adjustments should be defined as constants, possibly in ThemeConstants, to make the dark mode color generation logic more transparent and configurable.

Copilot uses AI. Check for mistakes.
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.

1 participant