fixed warnings

Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
Matt Bruce 2026-02-07 10:35:00 -06:00
parent 7252500c9a
commit 4bf7994e31
5 changed files with 31 additions and 40 deletions

View File

@ -344,9 +344,8 @@ final class ClockStyle: Codable, Equatable {
/// Check if ambient light is low enough to trigger night mode
private func isAmbientLightLow() -> Bool {
// Use screen brightness as a proxy for ambient light
// In a real implementation, you'd use the ambient light sensor
let currentBrightness = UIScreen.main.brightness
// Use the ambient light service's tracked brightness as a proxy
let currentBrightness = AmbientLightService.shared.currentBrightness
return currentBrightness < ambientLightThreshold
}
@ -425,7 +424,7 @@ final class ClockStyle: Codable, Equatable {
/// Get ambient light factor (0.5 to 1.0)
private func getAmbientLightFactor() -> Double {
let currentBrightness = UIScreen.main.brightness
let currentBrightness = AmbientLightService.shared.currentBrightness
// Map screen brightness to ambient light factor
if currentBrightness < 0.2 {

View File

@ -12,7 +12,8 @@ import Bedrock
/// Service for monitoring ambient light and managing brightness
@Observable
class AmbientLightService {
@MainActor
final class AmbientLightService {
// MARK: - Properties
private(set) var currentBrightness: Double = 1.0
@ -31,6 +32,22 @@ class AmbientLightService {
// Private initializer for singleton
}
// MARK: - Screen Access
/// Resolve the current UIScreen from the active window scene (iOS 26+ safe)
private var activeScreen: UIScreen? {
UIApplication.shared
.connectedScenes
.compactMap { $0 as? UIWindowScene }
.first(where: { $0.activationState == .foregroundActive })?
.screen
}
/// Current screen brightness from the active scene, falling back to stored value
private var screenBrightness: CGFloat {
activeScreen?.brightness ?? CGFloat(currentBrightness)
}
// MARK: - Public Interface
/// Start monitoring ambient light and brightness
@ -42,7 +59,10 @@ class AmbientLightService {
// Check brightness every 5 seconds
brightnessTimer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true) { [weak self] _ in
self?.updateCurrentBrightness()
guard let self else { return }
Task { @MainActor [weak self] in
self?.updateCurrentBrightness()
}
}
}
@ -58,23 +78,16 @@ class AmbientLightService {
/// Set screen brightness (0.0 to 1.0)
func setBrightness(_ brightness: Double) {
let clampedBrightness = max(0.0, min(1.0, brightness))
let previousBrightness = UIScreen.main.brightness
// Design.debugLog("[ambient] AmbientLightService.setBrightness:")
// Design.debugLog("[ambient] - Requested brightness: \(String(format: "%.2f", brightness))")
// Design.debugLog("[ambient] - Clamped brightness: \(String(format: "%.2f", clampedBrightness))")
// Design.debugLog("[ambient] - Previous screen brightness: \(String(format: "%.2f", previousBrightness))")
UIScreen.main.brightness = clampedBrightness
if let screen = activeScreen {
screen.brightness = clampedBrightness
}
currentBrightness = clampedBrightness
// Design.debugLog("[ambient] - New screen brightness: \(String(format: "%.2f", UIScreen.main.brightness))")
// Design.debugLog("[ambient] - Service currentBrightness: \(String(format: "%.2f", currentBrightness))")
}
/// Get current screen brightness
func getCurrentBrightness() -> Double {
return UIScreen.main.brightness
return Double(screenBrightness)
}
/// Check if ambient light is below threshold
@ -85,13 +98,10 @@ class AmbientLightService {
// MARK: - Private Methods
private func updateCurrentBrightness() {
let newBrightness = UIScreen.main.brightness
let newBrightness = Double(screenBrightness)
if abs(newBrightness - currentBrightness) > 0.05 { // Only update if significant change
let previousBrightness = currentBrightness
currentBrightness = newBrightness
//Design.debugLog("[ambient] AmbientLightService: Brightness changed from \(String(format: "%.2f", previousBrightness)) to \(String(format: "%.2f", newBrightness))")
// Notify that brightness changed
onBrightnessChange?()
}

View File

@ -267,24 +267,8 @@ final class ClockViewModel {
private func updateBrightness() {
if style.autoBrightness {
let targetBrightness = style.effectiveBrightness
let currentScreenBrightness = UIScreen.main.brightness
let isNightMode = style.isNightModeActive
// Design.debugLog("[brightness] Auto Brightness Debug:")
// Design.debugLog("[brightness] - Auto brightness enabled: \(style.autoBrightness)")
// Design.debugLog("[brightness] - Current screen brightness: \(String(format: "%.2f", currentScreenBrightness))")
// Design.debugLog("[brightness] - Target brightness: \(String(format: "%.2f", targetBrightness))")
// Design.debugLog("[brightness] - Night mode active: \(isNightMode)")
// Design.debugLog("[brightness] - Color theme: \(style.selectedColorTheme)")
// Design.debugLog("[brightness] - Ambient light threshold: \(String(format: "%.2f", style.ambientLightThreshold))")
ambientLightService.setBrightness(targetBrightness)
// Design.debugLog("[brightness] - Brightness set to: \(String(format: "%.2f", targetBrightness))")
// Design.debugLog("[brightness] - Actual screen brightness now: \(String(format: "%.2f", UIScreen.main.brightness))")
// Design.debugLog("[brightness] ---")
// } else {
// Design.debugLog("[brightness] Auto Brightness: DISABLED")
}
}
}

View File

@ -39,7 +39,6 @@ struct ClockView: View {
// Get safe area insets from UIWindow since GeometryReader ignores them
let windowInsets = Self.getWindowSafeAreaInsets()
let safeInsets = geometry.safeAreaInsets // May be 0 due to ignoresSafeArea
// Dynamic Island handling:
// In landscape, apply symmetric padding to keep content centered

View File

@ -233,7 +233,7 @@ struct TimeDisplayView: View {
Text("Digit Slot: \(Int(digitSlotSize.width))×\(Int(digitSlotSize.height))")
Text("Font Size: \(Int(fontSize))")
Text("Cols: \(Int(digitColumns)) Rows: \(Int(digitRows))")
Text("Portrait: \(portrait)")
Text("Portrait: \(portrait ? "true" : "false")")
Text("Family: \(fontFamily.rawValue)")
}
.font(.system(size: 10, weight: .bold, design: .monospaced))
@ -251,7 +251,6 @@ struct TimeDisplayView: View {
let digitColumns: CGFloat = portrait ? 2.0 : (showSeconds ? 6.0 : 4.0)
let digitRows: CGFloat = portrait ? (showSeconds ? 3.0 : 2.0) : 1.0
let colonCount: CGFloat = showSeconds ? 2.0 : 1.0
let previousFontSize = fontSize
func calculateFontSize(reservingColonSize colonSize: CGFloat) -> CGFloat {
let availableWidth = portrait