diff --git a/Sources/ContentView.swift b/Sources/ContentView.swift index 48aaacb5..cb4e565b 100644 --- a/Sources/ContentView.swift +++ b/Sources/ContentView.swift @@ -28,6 +28,19 @@ private func coloredCircleImage(color: NSColor) -> NSImage { return image } +func sidebarStatusPillActiveForegroundNSColor( + colorScheme: ColorScheme, + opacity: CGFloat +) -> NSColor { + let clampedOpacity = max(0, min(opacity, 1)) + switch colorScheme { + case .dark: + return NSColor.white.withAlphaComponent(clampedOpacity) + default: + return NSColor.black.withAlphaComponent(clampedOpacity) + } +} + struct ShortcutHintPillBackground: View { var emphasis: Double = 1.0 @@ -6811,12 +6824,13 @@ private struct SidebarStatusPillsRow: View { let onFocus: () -> Void @State private var isExpanded: Bool = false + @Environment(\.colorScheme) private var colorScheme var body: some View { VStack(alignment: .leading, spacing: 2) { Text(statusText) .font(.system(size: 10)) - .foregroundColor(isActive ? .white.opacity(0.8) : .secondary) + .foregroundColor(isActive ? activePrimaryTextColor : .secondary) .lineLimit(isExpanded ? nil : 3) .truncationMode(.tail) .multilineTextAlignment(.leading) @@ -6839,13 +6853,21 @@ private struct SidebarStatusPillsRow: View { } .buttonStyle(.plain) .font(.system(size: 10, weight: .semibold)) - .foregroundColor(isActive ? .white.opacity(0.65) : .secondary.opacity(0.9)) + .foregroundColor(isActive ? activeSecondaryTextColor : .secondary.opacity(0.9)) .frame(maxWidth: .infinity, alignment: .leading) } } .help(statusText) } + private var activePrimaryTextColor: Color { + Color(nsColor: sidebarStatusPillActiveForegroundNSColor(colorScheme: colorScheme, opacity: 0.8)) + } + + private var activeSecondaryTextColor: Color { + Color(nsColor: sidebarStatusPillActiveForegroundNSColor(colorScheme: colorScheme, opacity: 0.65)) + } + private var statusText: String { entries .map { entry in diff --git a/cmuxTests/CmuxWebViewKeyEquivalentTests.swift b/cmuxTests/CmuxWebViewKeyEquivalentTests.swift index d2ee116a..3c212b85 100644 --- a/cmuxTests/CmuxWebViewKeyEquivalentTests.swift +++ b/cmuxTests/CmuxWebViewKeyEquivalentTests.swift @@ -773,6 +773,38 @@ final class BrowserPanelOmnibarPillBackgroundColorTests: XCTestCase { } } +final class SidebarStatusPillActiveForegroundColorTests: XCTestCase { + func testLightModeUsesBlackWithRequestedOpacity() { + guard let color = sidebarStatusPillActiveForegroundNSColor( + colorScheme: .light, + opacity: 0.8 + ).usingColorSpace(.sRGB) else { + XCTFail("Expected sRGB-convertible color") + return + } + + XCTAssertEqual(color.redComponent, 0, accuracy: 0.001) + XCTAssertEqual(color.greenComponent, 0, accuracy: 0.001) + XCTAssertEqual(color.blueComponent, 0, accuracy: 0.001) + XCTAssertEqual(color.alphaComponent, 0.8, accuracy: 0.001) + } + + func testDarkModeUsesWhiteWithRequestedOpacity() { + guard let color = sidebarStatusPillActiveForegroundNSColor( + colorScheme: .dark, + opacity: 0.65 + ).usingColorSpace(.sRGB) else { + XCTFail("Expected sRGB-convertible color") + return + } + + XCTAssertEqual(color.redComponent, 1, accuracy: 0.001) + XCTAssertEqual(color.greenComponent, 1, accuracy: 0.001) + XCTAssertEqual(color.blueComponent, 1, accuracy: 0.001) + XCTAssertEqual(color.alphaComponent, 0.65, accuracy: 0.001) + } +} + final class BrowserDeveloperToolsShortcutDefaultsTests: XCTestCase { func testSafariDefaultShortcutForToggleDeveloperTools() { let shortcut = KeyboardShortcutSettings.Action.toggleBrowserDeveloperTools.defaultShortcut