diff --git a/Sources/CodeCaps/ConsoleViews.swift b/Sources/CodeCaps/ConsoleViews.swift index 217fe8d5..cf860374 100644 --- a/Sources/CodeCaps/ConsoleViews.swift +++ b/Sources/CodeCaps/ConsoleViews.swift @@ -10,7 +10,6 @@ enum ConsolePage: Hashable { case runawayAlerts case plugin(String) case settingsMenuBar - case settingsPlatforms case settingsLogoStyle case settingsSourcesFleet case settingsNotifications @@ -32,7 +31,6 @@ enum ConsolePage: Hashable { case .runawayAlerts: return "runawayAlerts" case .plugin(let pluginId): return "plugin:" + pluginId case .settingsMenuBar: return "settingsMenuBar" - case .settingsPlatforms: return "settingsPlatforms" case .settingsLogoStyle: return "settingsLogoStyle" case .settingsSourcesFleet: return "settingsSourcesFleet" case .settingsNotifications: return "settingsNotifications" @@ -47,7 +45,10 @@ enum ConsolePage: Hashable { case "allPlatforms": return .allPlatforms case "runawayAlerts": return .runawayAlerts case "settingsMenuBar": return .settingsMenuBar - case "settingsPlatforms": return .settingsPlatforms + // The old Platforms page merged into Platforms & Sources (owner, + // 2026-11-27): a saved selection under the old key lands on the + // merged page forever. + case "settingsPlatforms": return .settingsSourcesFleet case "settingsLogoStyle": return .settingsLogoStyle case "settingsSourcesFleet": return .settingsSourcesFleet case "settingsNotifications": return .settingsNotifications @@ -70,9 +71,8 @@ enum ConsolePage: Hashable { case .runawayAlerts: return "Runaway Alerts" case .plugin(let pluginId): return CodeCapsPlugin.named(pluginId)?.title ?? "Plugin" case .settingsMenuBar: return "Menu Bar & PiP" - case .settingsPlatforms: return "Platforms" case .settingsLogoStyle: return "Logo Style" - case .settingsSourcesFleet: return "Sources & Fleet" + case .settingsSourcesFleet: return "Platforms & Sources" case .settingsNotifications: return "Alerts & Alarms" case .settingsAppearance: return "Appearance" case .settingsInfisical: return "Infisical Sync" @@ -87,7 +87,6 @@ enum ConsolePage: Hashable { case .runawayAlerts: return "flame.fill" case .plugin(let pluginId): return CodeCapsPlugin.named(pluginId)?.symbol ?? "puzzlepiece.extension" case .settingsMenuBar: return "menubar.rectangle" - case .settingsPlatforms: return "square.grid.2x2" case .settingsLogoStyle: return "photo.on.rectangle.angled" case .settingsSourcesFleet: return "arrow.up.arrow.down.circle" case .settingsNotifications: return "bell.badge" @@ -99,7 +98,7 @@ enum ConsolePage: Hashable { } static let settingsPages: [ConsolePage] = [ - .settingsMenuBar, .settingsPlatforms, .settingsLogoStyle, .settingsSourcesFleet, .settingsNotifications, .settingsAppearance, .settingsInfisical, .settingsAbout, + .settingsMenuBar, .settingsLogoStyle, .settingsSourcesFleet, .settingsNotifications, .settingsAppearance, .settingsInfisical, .settingsAbout, ] static let pluginPages: [ConsolePage] = CodeCapsPlugin.allCases.map { .plugin($0.id) } @@ -337,7 +336,7 @@ struct ConsoleView: View { .accessibilityHidden(true) } if let unavailable = state.unavailableAlert { - Text("Alert source unavailable: \(unavailable.providerKey)\(unavailable.windowId.map { " · \($0)" } ?? "").\(sentenceGap)Check Sources & Fleet for this provider.") + Text("Alert source unavailable: \(unavailable.providerKey)\(unavailable.windowId.map { " · \($0)" } ?? "").\(sentenceGap)Check Platforms & Sources for this provider.") .font(.callout) .foregroundStyle(Theme.warning) .padding(.horizontal, Metrics.pagePadding) @@ -359,12 +358,10 @@ struct ConsoleView: View { .padding(Metrics.pagePadding) case .settingsMenuBar: SettingsMenuBarPage(model: model) - case .settingsPlatforms: - SettingsPlatformsPage(model: model) case .settingsLogoStyle: SettingsLogoStylePage(model: model) case .settingsSourcesFleet: - SettingsSourcesFleetPage(model: model) + SettingsPlatformsAndSourcesPage(model: model) case .settingsNotifications: SettingsNotificationsPage(model: model, state: state) case .settingsAppearance: diff --git a/Sources/CodeCaps/GlanceViews.swift b/Sources/CodeCaps/GlanceViews.swift index 59f53478..f64b45e2 100644 --- a/Sources/CodeCaps/GlanceViews.swift +++ b/Sources/CodeCaps/GlanceViews.swift @@ -2516,7 +2516,7 @@ struct GlanceRow: View { /// Shown below the platform list when a reader's saved login is present on /// this Mac but unreadable until the owner allows this build once. The button -/// deep-links to Sources & Fleet, where the one-time step lives. +/// deep-links to Platforms & Sources, where the one-time step lives. struct ConsentRow: View { let message: String var action: () -> Void diff --git a/Sources/CodeCaps/MonitorModel.swift b/Sources/CodeCaps/MonitorModel.swift index b72eda82..561eab04 100644 --- a/Sources/CodeCaps/MonitorModel.swift +++ b/Sources/CodeCaps/MonitorModel.swift @@ -855,6 +855,7 @@ final class MonitorModel: ObservableObject { localEnabled = defaults.object(forKey: "localEnabled") as? Bool ?? true glanceLogosFollowAccent = defaults.bool(forKey: "glanceLogosFollowAccent") pipBackground = PipBackground(rawValue: defaults.string(forKey: "pipBackground") ?? "") ?? .black + pipLogoStyle = PipLogoStyle(rawValue: defaults.string(forKey: "pipLogoStyle") ?? "") ?? .automatic pipShowProviderNames = defaults.bool(forKey: "pipShowProviderNames") providerChecksEnabled = SourceRefreshPreference.enabled(SourceRefreshPreference.providerEnabled, defaults: defaults) sessionFileChecksEnabled = SourceRefreshPreference.enabled(SourceRefreshPreference.sessionEnabled, defaults: defaults) @@ -2039,6 +2040,18 @@ final class MonitorModel: ObservableObject { } } + /// Which artwork the PiP HUD draws beside each provider. Automatic — the + /// shipped default — keeps silhouettes on a dark HUD and brand-colour + /// marks on a white one; the explicit choices override that because the + /// owner asked to choose which logo the PiP uses (2026-11-27). A per-user + /// display preference, like the PiP background. + @Published var pipLogoStyle: PipLogoStyle { + didSet { + defaults.set(pipLogoStyle.rawValue, forKey: "pipLogoStyle") + if presentsPipWindows { PipWidgetController.shared.update(model: self) } + } + } + /// Whether the Glance popover's provider logos wear the chosen accent. /// /// Off by default, and deliberately so. A logo in the accent stops looking diff --git a/Sources/CodeCaps/PipWidget.swift b/Sources/CodeCaps/PipWidget.swift index 12824e4c..709d86a9 100644 --- a/Sources/CodeCaps/PipWidget.swift +++ b/Sources/CodeCaps/PipWidget.swift @@ -730,21 +730,56 @@ final class PipWidgetController: NSObject, NSWindowDelegate { disabledSources: Set = [], peerRows: [DisplaySection] = []) -> [QuotaWindowSnapshot] { let windows = currentWindows(for: row, now: now, issue: issue, disabledSources: disabledSources, peerRows: peerRows) - let minPercent = windows.compactMap(\.remainingPercent).min() - let current = DisplaySection(id: row.id, providerKey: row.providerKey, title: row.title, - platformTitle: row.platformTitle, - section: QuotaPlatformSection(providerKey: row.providerKey, providerLabel: row.section.providerLabel, - via: row.section.via, expected: row.section.expected, windows: windows, iconHint: row.section.iconHint), - poolKey: row.poolKey, remainingPercent: minPercent, - resetAt: nil, maskedWindowIds: row.maskedWindowIds, - drivingWindowId: minPercent.flatMap({ mp in windows.first(where: { $0.remainingPercent == mp })?.window.id })) - let meters = glanceMeterPair(for: current, now: now) - var out: [QuotaWindowSnapshot] = [] - if let short = meters.short { out.append(short) } - if let long = meters.long, long.window.id != meters.short?.window.id { - out.append(long) - } else if meters.short == nil, let primary = windows.first { - out.append(primary) + // One pairing helper for both window sets, so the narrow and wide + // answers can never disagree about how a pair is picked. + func pair(for ws: [QuotaWindowSnapshot]) -> [QuotaWindowSnapshot] { + let minPercent = ws.compactMap(\.remainingPercent).min() + let current = DisplaySection(id: row.id, providerKey: row.providerKey, title: row.title, + platformTitle: row.platformTitle, + section: QuotaPlatformSection(providerKey: row.providerKey, providerLabel: row.section.providerLabel, + via: row.section.via, expected: row.section.expected, windows: ws, iconHint: row.section.iconHint), + poolKey: row.poolKey, remainingPercent: minPercent, + resetAt: nil, maskedWindowIds: row.maskedWindowIds, + drivingWindowId: minPercent.flatMap({ mp in ws.first(where: { $0.remainingPercent == mp })?.window.id })) + let meters = glanceMeterPair(for: current, now: now) + var out: [QuotaWindowSnapshot] = [] + if let short = meters.short { out.append(short) } + if let long = meters.long, long.window.id != meters.short?.window.id { + out.append(long) + } else if meters.short == nil, let primary = ws.first { + out.append(primary) + } + return out + } + var out = pair(for: windows) + // The dropdown pairs its meters over every drawable window, including + // one whose period has ended — it draws as a full bar with a "due" + // countdown. `currentWindows` drops that awaiting-refresh window + // before the pairing sees it, so a pool with a due 5h and a live 7d + // showed only the 7d in the HUD while the dropdown showed both + // (owner, 2026-11-27, Antigravity Third-Party). When a drawable row + // comes up short, re-pair over the same drawable set the dropdown + // uses (supplementary, masked, and disabled sources still excluded, + // so the HUD never draws a window its surfaces turned off). Three + // gates keep the rescue from disagreeing with the surfaces: + // a failed row keeps its status words instead of meters; a row + // with no current windows at all — every period ended, or sources + // off — keeps its empty meter set so the status carries the story + // (CI, 2026-11-27, PipInteractionTests); and a unified-pool row + // never rescues, because `currentWindows` suppresses its own stale + // windows in favour of a peer's fresher reading, and re-pairing the + // row's own windows would put a suppressed meter back in the HUD + // (Kody finding, 2026-11-27). + if !windows.isEmpty, out.count < 2, issue == nil, + !UnifiedSubscriptionPool.participantKeys.contains(row.providerKey) { + let drawable = row.section.windows + .filter { + !$0.window.isSupplementaryVideoQuota && !row.isMasked($0) + && !disabledSources.contains($0.window.source ?? "") + } + .map { QuotaWindowSnapshot(window: $0.window, now: now) } + let wide = pair(for: drawable) + if wide.count > out.count { out = wide } } return out } @@ -875,11 +910,13 @@ struct PipWidgetView: View { /// site is how a light HUD ends up with white text or a dark mark on white. private var background: PipBackground { model.pipBackground } - /// The mark style a provider's logo takes on this background. Same logos as - /// the popover (the owner asked for that on 2026-10-10), then adapted to the - /// fill so they read on it. - private func markStyle(for row: DisplaySection) -> MarkStyle { - background.markStyle(for: model.glanceMarkStyle(for: row.id)) + /// The mark presentation the owner's PiP logo choice asks for on this + /// background. The old rule — always the background-adapted silhouette, + /// always monochrome-forced — is the Automatic default; Brand Color and + /// Light/Dark override it (owner, 2026-11-27: "it should be an option in + /// settings to use which logo for PiP"). + private func logoPresentation(for row: DisplaySection) -> (style: MarkStyle, forceMonochrome: Bool) { + model.pipLogoStyle.presentation(on: background, ownerStyle: model.glanceMarkStyle(for: row.id)) } /// The one row the detail view is showing, or nil. @@ -1147,11 +1184,12 @@ struct PipWidgetView: View { return HStack(spacing: PipMetrics.rowSpacing) { if detail.showsProviderLogo { + let logo = logoPresentation(for: row) PlatformLogo(providerKey: row.id, size: PipMetrics.providerLogoSize, - style: markStyle(for: row), + style: logo.style, iconHint: row.poolKey == nil ? row.section.iconHint : nil, - forceMonochrome: true) + forceMonochrome: logo.forceMonochrome) // Owner 2026-10-10: "after the platform name (or logo if no // name shown) there should be a little flame for usage spike". // Beside the LOGO rather than after the name, because the name @@ -1270,11 +1308,12 @@ struct PipWidgetView: View { return ScrollView(.vertical, showsIndicators: false) { VStack(alignment: .leading, spacing: 0) { HStack(spacing: 6) { + let logo = logoPresentation(for: row) PlatformLogo(providerKey: row.id, size: 16, - style: markStyle(for: row), + style: logo.style, iconHint: row.poolKey == nil ? row.section.iconHint : nil, - forceMonochrome: true) + forceMonochrome: logo.forceMonochrome) Text(row.title) .font(.system(size: 12, weight: .bold)) .foregroundStyle(background.ink) diff --git a/Sources/CodeCaps/PlatformLogo.swift b/Sources/CodeCaps/PlatformLogo.swift index fb124201..753ee954 100644 --- a/Sources/CodeCaps/PlatformLogo.swift +++ b/Sources/CodeCaps/PlatformLogo.swift @@ -358,6 +358,13 @@ private static let resourceNames: [String: String] = [ "cursor": "cursor", "github-copilot": "copilot", "copilot": "copilot", + // Alibaba's two plans share the one brand mark; the provider keys stay + // the stable quota-reader ids (owner, 2026-11-27: "Alibaba logo + // probably"). + "alibaba-token-plan": "alibaba", + "alibaba-coding-plan": "alibaba", + "mimo-token-plan": "mimo", + "opencode-go": "opencode-go", ] /// The file a style and appearance ask for, or `nil` when the mark is absent. @@ -591,6 +598,17 @@ private static func variantFile(base: String, style: MarkStyle, isDark: Bool) -> /// "artwork is there and the bundle could not open it". private static var lastFailure: String? = nil + /// Consecutive mapped-mark probes that found no candidate file at all + /// while a bundle was pinned. Three in a row trip the watchdog that + /// drops the pin (see `bundledImage`). Reset by any successful decode. + private static var mappedMissStreak = 0 + /// When the watchdog last dropped the bundle pin, in reference-date + /// seconds. The cooldown keeps a genuinely broken install from + /// dropping and re-resolving in a hot loop. + private static var lastBundleDrop: TimeInterval = 0 + /// Minimum seconds between watchdog bundle drops. + private static let bundleDropCooldown: TimeInterval = 30 + private static func noteFailure(_ reason: String) { stateLock.lock() guard lastFailure != reason else { stateLock.unlock(); return } @@ -659,22 +677,64 @@ private static func variantFile(base: String, style: MarkStyle, isDark: Bool) -> filenames.append(filename) } } + var sawAnyFile = false for filename in filenames { - if let image = imageFromBundle(filename: filename, key: identity.key, cacheKey: identity.cacheKey, cache: identity.cache, refreshing: refreshing) { + let (image, sawFile) = imageFromBundle(filename: filename, key: identity.key, cacheKey: identity.cacheKey, cache: identity.cache, refreshing: refreshing) + sawAnyFile = sawAnyFile || sawFile + if let image { // A decode is what makes every surface drop the placeholder, // including a row whose own task is still inside its backoff. + stateLock.lock() + mappedMissStreak = 0 + stateLock.unlock() publishMarksResolved() return image } } + var droppedPin = false + var droppedPinFilename: String? stateLock.lock() // No bundle yet: the failure is environmental. Storing it would // make the next draw, and the launch preload, keep returning nil // after the bundle is there. if cachedBundle != nil && !bundleUnavailableForTesting { missingBundledKeys[cacheKeyString] = catalogEpoch + // Watchdog: a MAPPED mark with NO candidate file anywhere says + // the pinned bundle cannot deliver, not that the artwork is + // absent — a stale copy that won the search order, or a bundle + // directory caught half-copied by an update. The pin used to + // hold for the life of the process. Three such misses drop it + // once per cooldown so re-resolution (and the shadow-bundle + // sweep in the candidate list) can land on a good copy, and one + // notification wakes every open placeholder row (owner, + // 2026-11-27). Two gates keep the watchdog honest (Seer and + // Kody findings, 2026-11-27): files that exist but fail to + // decode (`sawAnyFile`) are an artwork problem, not a bundle + // problem, and keys with no catalog mapping (endpoint plugins, + // unknown keys) have no files to find by construction — either + // incrementing here would drop a healthy bundle on a loop. + if !sawAnyFile, mappedBase != nil { + mappedMissStreak += 1 + let now = Date().timeIntervalSinceReferenceDate + if mappedMissStreak >= 3, now - lastBundleDrop >= bundleDropCooldown { + lastBundleDrop = now + mappedMissStreak = 0 + bundleGeneration &+= 1 + cachedBundle = nil + candidateURLCache.removeAll() + missingBundledKeys.removeAll() + droppedPinFilename = filenames.first ?? "a mapped mark" + droppedPin = true + } + } } stateLock.unlock() + // The log and the wake both take the lock themselves, so they wait + // until the pin work above has released it. + if let droppedPinFilename { + noteFailure("the pinned resource bundle delivered no files for '\(droppedPinFilename)'; dropped the pin so it re-resolves") + } + if droppedPin { publishMarksResolved() } return nil } /// A missing appearance variant should not hide a usable brand mark. @@ -687,7 +747,11 @@ private static func variantFile(base: String, style: MarkStyle, isDark: Bool) -> return names } - private static func imageFromBundle(filename: String, key: NSString, cacheKey: NSString, cache: NSCache, refreshing: Bool) -> NSImage? { + /// Decodes `filename` from the first candidate that yields pixels, and + /// reports whether ANY candidate file existed on disk. `sawFile == false` + /// for a mapped mark is the signature of a bundle that cannot deliver, + /// which is what the watchdog below acts on. + private static func imageFromBundle(filename: String, key: NSString, cacheKey: NSString, cache: NSCache, refreshing: Bool) -> (image: NSImage?, sawFile: Bool) { // Walk EVERY candidate, decoding as we go, and take the first that // yields pixels. // @@ -701,17 +765,19 @@ private static func variantFile(base: String, style: MarkStyle, isDark: Bool) -> bundledCandidateProbes += 1 stateLock.unlock() let urls = candidateURLs(filename: filename, refreshing: refreshing) + var sawFile = false for candidate in urls { guard FileManager.default.fileExists(atPath: candidate.path) else { continue } + sawFile = true guard let image = NSImage(contentsOf: candidate) ?? NSImage(contentsOfFile: candidate.path) else { noteFailure("'\(filename)' exists at \(candidate.path) but would not decode; trying the next location") continue } - return finalize(image: image, url: candidate, key: key, - cacheKey: cacheKey, cache: cache) + return (finalize(image: image, url: candidate, key: key, + cacheKey: cacheKey, cache: cache), true) } noteFailure("'\(filename)' is mapped for '\(key as String)' but was not found in any of the \(urls.count) known locations") - return nil + return (nil, sawFile) } /// Every place the mark could legitimately live, across both the resolved @@ -742,18 +808,22 @@ private static func variantFile(base: String, style: MarkStyle, isDark: Bool) -> return urls } + /// The five places a mark can sit inside one bundle, in probe order. + private static func appendBundleCandidates(_ bundle: Bundle, filename: String, to urls: inout [URL]) { + let name = (filename as NSString).deletingPathExtension + let ext = (filename as NSString).pathExtension + if let u = bundle.url(forResource: name, withExtension: ext) { urls.append(u) } + if let u = bundle.url(forResource: name, withExtension: ext, subdirectory: "ProviderMarks") { urls.append(u) } + if let base = bundle.resourceURL { urls.append(fileURL(appending: filename, to: base)) } + urls.append(fileURL(appending: "Contents/Resources/\(filename)", to: bundle.bundleURL)) + urls.append(fileURL(appending: filename, to: bundle.bundleURL)) + } + private static func makeCandidateURLs(filename: String) -> [URL] { var urls: [URL] = [] let bundled = directoryURL(appending: "Contents/Resources/CodeCaps_CodeCaps.bundle", to: Bundle.main.bundleURL) - let bundles = [currentBundle(), Bundle(url: bundled)] - for bundle in bundles.compactMap({ $0 }) { - let name = (filename as NSString).deletingPathExtension - let ext = (filename as NSString).pathExtension - if let u = bundle.url(forResource: name, withExtension: ext) { urls.append(u) } - if let u = bundle.url(forResource: name, withExtension: ext, subdirectory: "ProviderMarks") { urls.append(u) } - if let base = bundle.resourceURL { urls.append(fileURL(appending: filename, to: base)) } - urls.append(fileURL(appending: "Contents/Resources/\(filename)", to: bundle.bundleURL)) - urls.append(fileURL(appending: filename, to: bundle.bundleURL)) + for bundle in [currentBundle(), Bundle(url: bundled)].compactMap({ $0 }) { + appendBundleCandidates(bundle, filename: filename, to: &urls) } if let res = Bundle.main.resourceURL { urls.append(fileURL(appending: "CodeCaps_CodeCaps.bundle/Contents/Resources/\(filename)", to: res)) @@ -765,6 +835,20 @@ private static func variantFile(base: String, style: MarkStyle, isDark: Bool) -> urls.append(fileURL(appending: "Contents/Resources/CodeCaps_CodeCaps.bundle/\(filename)", to: main)) urls.append(fileURL(appending: "Contents/Resources/\(filename)", to: main)) + // Shadow-bundle sweep. A stale or half-copied resource bundle earlier + // in the search order used to win the pin for the life of the process, + // and every mark that copy lacked drew the placeholder — a different + // subset on different launches, which is exactly the owner's report + // (2026-11-27, "which ones don't load changes all the time"). The + // pinned bundle and the app's own bundle keep priority; these are the + // same roots `resolveBundle` walks, asked only for the filenames the + // front of the order could not deliver. + for root in ResourceBundle.searchRoots { + let candidate = root.appendingPathComponent("\(ResourceBundle.name).bundle", isDirectory: true) + guard let bundle = Bundle(url: candidate) else { continue } + appendBundleCandidates(bundle, filename: filename, to: &urls) + } + // De-duplicate while preserving order, so the common case (the first // candidate hits) does the least work. var seen = Set() @@ -1416,7 +1500,11 @@ private static func variantFile(base: String, style: MarkStyle, isDark: Bool) -> /// first draw should not leave placeholder glyphs lingering), then five /// seconds for the install/update window, then once a minute so a mark /// that appears later — a custom import, a late-mounted bundle — still - /// heals without a relaunch. + /// heals without a relaunch. The tail stays at a minute on purpose + /// (Kody finding, 2026-11-27): a healed bundle announces itself with a + /// decode, which publishes the marks-resolved wave and wakes every open + /// placeholder immediately, so a faster tail would only multiply the + /// candidate sweep's filesystem probes during an outage. public static func missingMarkRetryDelay(forAttempt attempt: Int) -> UInt64 { if attempt < 3 { return 1_000_000_000 } return attempt < 12 ? 5_000_000_000 : 60_000_000_000 diff --git a/Sources/CodeCaps/QuotaComponents.swift b/Sources/CodeCaps/QuotaComponents.swift index ef767e33..8fe2bb85 100644 --- a/Sources/CodeCaps/QuotaComponents.swift +++ b/Sources/CodeCaps/QuotaComponents.swift @@ -176,6 +176,53 @@ enum PipBackground: String, CaseIterable, Identifiable { } } +/// Which artwork the PiP HUD draws beside each provider. Automatic keeps the +/// shipped behaviour — the logo follows the background (silhouette on a dark +/// HUD, brand-colour mark on a white one) and stays monochrome either way. +/// The two explicit choices exist because the owner asked to be able to pick +/// which logo the PiP uses (2026-11-27). +enum PipLogoStyle: String, CaseIterable, Identifiable { + case automatic + case brandColor + case lightDark + + var id: String { rawValue } + + var title: String { + switch self { + case .automatic: return "Automatic" + case .brandColor: return "Brand Color" + case .lightDark: return "Light/Dark" + } + } + + var detail: String { + switch self { + case .automatic: return "Follows the PiP background: silhouettes on a dark HUD, brand-colour marks on a white one." + case .brandColor: return "Always the full-colour mark, whatever the background." + case .lightDark: return "Always the light/dark silhouette, adapting to the background." + } + } + + /// The mark style and monochrome forcing this choice asks for on the + /// given background. A provider whose owner picked a custom mark keeps + /// it in every style; only the monochrome forcing changes, so a custom + /// logo can still be asked to read as a silhouette. The shipped HUD is + /// monochrome everywhere but Brand Color, and Automatic is that shipped + /// behaviour — so every choice but Brand Color forces monochrome + /// (Kody/Seer findings, 2026-11-27). + func presentation(on background: PipBackground, ownerStyle: MarkStyle) -> (style: MarkStyle, forceMonochrome: Bool) { + if ownerStyle == .custom { + return (.custom, self != .brandColor) + } + switch self { + case .automatic: return (background.markStyle(for: ownerStyle), true) + case .brandColor: return (.standard, false) + case .lightDark: return (.template, true) + } + } +} + enum Theme { /// Pure black on light, pure white on dark, when high contrast is on. private static var highContrastInk: Color { diff --git a/Sources/CodeCaps/Resources/ProviderMarks/README.md b/Sources/CodeCaps/Resources/ProviderMarks/README.md index 2b81d04b..5770473a 100644 --- a/Sources/CodeCaps/Resources/ProviderMarks/README.md +++ b/Sources/CodeCaps/Resources/ProviderMarks/README.md @@ -41,4 +41,6 @@ Several families were deliberately left alone, because there is no same-art high `ProviderMarkDetailTests` holds the same rule as a test, so a blurry upscale cannot come back unnoticed. It measures the same thing, against the committed assets rather than a copy the build happened to make. A mark here may not have a silhouette edge wider than one device pixel at 28pt on a 2x display, except the two families named above, whose soft edge is the artwork's own. The companion's marks are measured in the pixels of the screen that serves them, because a 1x file is drawn on a 1x screen and a 3x file on a 3x one, so the file's own pixels are already the device pixels; their limit is 1.65 device pixels, which is about what a 24px raster can do at all. The two limits live in `scripts/regenerate-provider-marks.py`, which refuses to write a mark that would break them, and the test reads them from there so the two cannot drift apart. -Kimi ships the supplied `kimi-color.svg` as its Standard colour source and `kimi.svg` as its Light/Dark source. Z.ai ships the supplied mark in its brand navy for Standard (`zai-color.svg`, the ink the supplied raster carries) and the same silhouette in white for dark surfaces. Their PNG variants are transparent 256px AppKit rasterizations of those vectors. The companion catalog carries both marks with dark appearances, so the phone keeps the colour in light mode and stays legible in dark. +Kimi ships the supplied `kimi-color.svg` as its Standard colour source and `kimi.svg` as its Light/Dark source. Z.ai ships the supplied mark in its brand navy for Standard (`zai-color.svg`, the ink the supplied raster carries) and the same silhouette in white for dark surfaces. Their PNG variants are transparent 256px AppKit rasterizations of those vectors. The companion catalog carries both marks with dark appearances, so the phone keeps the colour in light mode and stays legible in dark. + +November 27 update: three new plans ship drawn marks, because no same-art source for any of them exists in the fleet's checkouts. `alibaba-{color,light,dark}.png` (provider keys `alibaba-token-plan` and `alibaba-coding-plan`) is the owner-commissioned abstract Alibaba mark: Alibaba orange `#FF6A00`, an open ring whose smile bowl ends on a right stem, reading as a lowercase "a" at draw size; it is a clean geometric interpretation, not a counterfeit of the trademark. `mimo-{color,light,dark}.png` (key `mimo-token-plan`) is a Xiaomi-orange `#FF6900` rounded square (corner radius 22% of the square) with a bold white geometric "M"; the monochrome variants knock the "M" out of the square so the silhouette survives template rendering. `opencode-go-{color,light,dark}.png` (key `opencode-go`) is a charcoal `#1F2430` rounded square with a teal `#2DD4BF` terminal prompt, a chevron plus underscore; the prompt won the draw-size read-off against an "OC" monogram. Monochrome inks match the family convention: `#1A1A1A` for `-light`, `#F5F5F5` for `-dark`. All nine PNGs were drawn at 2048px and downscaled to 256px LANCZOS, so each silhouette edge measures about 0.3 device pixels at 28pt on a 2x display (about 0.6 on the companion's 108px reading), well inside the edge limits and level with the sharpest shipped marks. `alibaba.svg`, `mimo.svg` and `opencode-go.svg` are the static vector sources the PNGs were drawn from (script-free, static shapes only); the PNGs are canonical because this host has no SVG rasterizer. The companion catalog carries all three as `provider-.png` single-scale universals with light-ink `provider--dark.png` dark appearances and `template-rendering-intent: original`, so each mark keeps its colour in light mode and stays legible in dark. diff --git a/Sources/CodeCaps/Resources/ProviderMarks/alibaba-color.png b/Sources/CodeCaps/Resources/ProviderMarks/alibaba-color.png new file mode 100644 index 00000000..8e028088 Binary files /dev/null and b/Sources/CodeCaps/Resources/ProviderMarks/alibaba-color.png differ diff --git a/Sources/CodeCaps/Resources/ProviderMarks/alibaba-dark.png b/Sources/CodeCaps/Resources/ProviderMarks/alibaba-dark.png new file mode 100644 index 00000000..09969d5f Binary files /dev/null and b/Sources/CodeCaps/Resources/ProviderMarks/alibaba-dark.png differ diff --git a/Sources/CodeCaps/Resources/ProviderMarks/alibaba-light.png b/Sources/CodeCaps/Resources/ProviderMarks/alibaba-light.png new file mode 100644 index 00000000..810aed3e Binary files /dev/null and b/Sources/CodeCaps/Resources/ProviderMarks/alibaba-light.png differ diff --git a/Sources/CodeCaps/Resources/ProviderMarks/alibaba.svg b/Sources/CodeCaps/Resources/ProviderMarks/alibaba.svg new file mode 100644 index 00000000..928b2a50 --- /dev/null +++ b/Sources/CodeCaps/Resources/ProviderMarks/alibaba.svg @@ -0,0 +1,8 @@ + + + + + diff --git a/Sources/CodeCaps/Resources/ProviderMarks/mimo-color.png b/Sources/CodeCaps/Resources/ProviderMarks/mimo-color.png new file mode 100644 index 00000000..89a850d6 Binary files /dev/null and b/Sources/CodeCaps/Resources/ProviderMarks/mimo-color.png differ diff --git a/Sources/CodeCaps/Resources/ProviderMarks/mimo-dark.png b/Sources/CodeCaps/Resources/ProviderMarks/mimo-dark.png new file mode 100644 index 00000000..3257f182 Binary files /dev/null and b/Sources/CodeCaps/Resources/ProviderMarks/mimo-dark.png differ diff --git a/Sources/CodeCaps/Resources/ProviderMarks/mimo-light.png b/Sources/CodeCaps/Resources/ProviderMarks/mimo-light.png new file mode 100644 index 00000000..545e48ca Binary files /dev/null and b/Sources/CodeCaps/Resources/ProviderMarks/mimo-light.png differ diff --git a/Sources/CodeCaps/Resources/ProviderMarks/mimo.svg b/Sources/CodeCaps/Resources/ProviderMarks/mimo.svg new file mode 100644 index 00000000..b4c6ecb3 --- /dev/null +++ b/Sources/CodeCaps/Resources/ProviderMarks/mimo.svg @@ -0,0 +1,7 @@ + + + + + diff --git a/Sources/CodeCaps/Resources/ProviderMarks/opencode-go-color.png b/Sources/CodeCaps/Resources/ProviderMarks/opencode-go-color.png new file mode 100644 index 00000000..5e264771 Binary files /dev/null and b/Sources/CodeCaps/Resources/ProviderMarks/opencode-go-color.png differ diff --git a/Sources/CodeCaps/Resources/ProviderMarks/opencode-go-dark.png b/Sources/CodeCaps/Resources/ProviderMarks/opencode-go-dark.png new file mode 100644 index 00000000..22955eb1 Binary files /dev/null and b/Sources/CodeCaps/Resources/ProviderMarks/opencode-go-dark.png differ diff --git a/Sources/CodeCaps/Resources/ProviderMarks/opencode-go-light.png b/Sources/CodeCaps/Resources/ProviderMarks/opencode-go-light.png new file mode 100644 index 00000000..052af31e Binary files /dev/null and b/Sources/CodeCaps/Resources/ProviderMarks/opencode-go-light.png differ diff --git a/Sources/CodeCaps/Resources/ProviderMarks/opencode-go.svg b/Sources/CodeCaps/Resources/ProviderMarks/opencode-go.svg new file mode 100644 index 00000000..78fb990f --- /dev/null +++ b/Sources/CodeCaps/Resources/ProviderMarks/opencode-go.svg @@ -0,0 +1,8 @@ + + + + + + diff --git a/Sources/CodeCaps/SettingsViews.swift b/Sources/CodeCaps/SettingsViews.swift index 9f01790e..61a058ca 100644 --- a/Sources/CodeCaps/SettingsViews.swift +++ b/Sources/CodeCaps/SettingsViews.swift @@ -159,6 +159,22 @@ struct SettingsMenuBarPage: View { .font(.caption) .foregroundStyle(.secondary) + // Owner 2026-11-27: choose which logo the PiP draws. + // Automatic keeps the shipped background-following + // behaviour; the other two pin it. + Picker("PiP Logos", selection: $model.pipLogoStyle) { + ForEach(PipLogoStyle.allCases) { choice in + Text(choice.title).tag(choice) + } + } + .pickerStyle(.segmented) + .help(model.pipLogoStyle.detail) + .accessibilityLabel("PiP logos") + + Text(model.pipLogoStyle.detail) + .font(.caption) + .foregroundStyle(.secondary) + // Owner 2026-10-28: the name is the first thing the // width ladder drops, and the room it takes is worth // more to the meters. Off by default. @@ -259,120 +275,23 @@ struct PipOptionsReorderList: View { } } -// MARK: - Platforms - -struct SettingsPlatformsPage: View { - @ObservedObject var model: MonitorModel - @State private var selection: String? - - private var orderedKeys: [String] { - let live = model.sections.map(\.providerKey) - guard !model.platformOrder.isEmpty else { return live } - let ordered = model.platformOrder.filter(live.contains) - return ordered + live.filter { !ordered.contains($0) } - } - - private func label(for providerKey: String) -> String { - model.sections.first { $0.providerKey == providerKey }?.providerLabel ?? providerKey - } - - var body: some View { - VStack(alignment: .leading, spacing: 12) { - Text("Drag to reorder." + sentenceGap - + "A platform's switch hides it from the dashboard — the quota list, the Docked Bar, and the menu bar — without stopping its refreshes.") - .font(.caption) - .foregroundStyle(.secondary) - .fixedSize(horizontal: false, vertical: true) +// MARK: - Platforms & Sources - // A plain List outside a Form group, because `.onMove`'s drop - // indicator misbehaves inside `.formStyle(.grouped)`. - List(selection: $selection) { - ForEach(orderedKeys, id: \.self) { providerKey in - HStack(spacing: 10) { - Image(systemName: "line.3.horizontal") - .font(.system(size: 11)) - .foregroundStyle(.tertiary) - .help("Drag to Reorder") - .accessibilityHidden(true) - PlatformLogo(providerKey: providerKey, size: 16, - style: model.markStyle(for: providerKey)) - Text(label(for: providerKey)) - .font(.subheadline.weight(.medium)) - .foregroundStyle(model.isProviderVisible(providerKey) ? Theme.ink : .secondary) - Spacer() - Toggle("", isOn: Binding( - get: { model.isProviderVisible(providerKey) }, - set: { model.setProviderVisible($0, providerKey: providerKey) })) - .labelsHidden() - .toggleStyle(.switch) - .controlSize(.mini) - .help(model.isProviderVisible(providerKey) - ? "Hide \(label(for: providerKey)) from the dashboard" - : "Show \(label(for: providerKey)) in the dashboard") - .accessibilityLabel(model.isProviderVisible(providerKey) - ? "Hide \(label(for: providerKey)) from the dashboard" - : "Show \(label(for: providerKey)) in the dashboard") - } - .tag(providerKey) - .accessibilityLabel("\(label(for: providerKey)), position \((orderedKeys.firstIndex(of: providerKey) ?? 0) + 1) of \(orderedKeys.count)") - } - .onMove(perform: move) - } - .listStyle(.inset) - // One expression, because a `minHeight` of 240 above a `maxHeight` - // of 226 (seven platforms) clipped the last row by 14pt. - .frame(height: max(240, CGFloat(orderedKeys.count) * 30 + 16)) - - HStack(spacing: 8) { - // Visible equivalents of the Option+Command arrow shortcuts - // above: drag-to-reorder alone cannot be operated with a - // keyboard or VoiceOver (Slice 4, FIX-A11Y-KEYBOARD). - Button("Move Up") { moveSelection(by: -1) } - .disabled(selection == nil || selection == orderedKeys.first) - .help("Move Up") - .accessibilityLabel("Move Up") - Button("Move Down") { moveSelection(by: 1) } - .disabled(selection == nil || selection == orderedKeys.last) - .help("Move Down") - .accessibilityLabel("Move Down") - Spacer() - Button("Reset Default Order") { model.resetPlatformOrder() } - .help("Reset Default Order") - .accessibilityLabel("Reset Default Order") - } - } - .padding(Metrics.pagePadding) - .background { - // Keyboard equivalents for the drag the chevrons used to stand in for. - VStack { - Button("") { moveSelection(by: -1) } - .keyboardShortcut(.upArrow, modifiers: [.option, .command]) - Button("") { moveSelection(by: 1) } - .keyboardShortcut(.downArrow, modifiers: [.option, .command]) - } - .opacity(0) - .accessibilityHidden(true) - } - } - - private func move(from source: IndexSet, to destination: Int) { - var keys = orderedKeys - keys.move(fromOffsets: source, toOffset: destination) - model.platformOrder = keys - } - - private func moveSelection(by delta: Int) { - guard let selection else { return } - if delta < 0 { model.movePlatformUp(providerKey: selection) } - else { model.movePlatformDown(providerKey: selection) } - } -} - -// MARK: - Sources & Fleet - -struct SettingsSourcesFleetPage: View { +/// The merged Platforms + Sources & Fleet settings page (owner, 2026-11-27). +/// +/// One provider roster carries order, dashboard visibility, per-provider +/// reading setup, and per-source ranking; machine-level plumbing, push, and +/// pull keep their own sections below. The two old pages answered different +/// questions about the same provider and duplicated its controls with two +/// same-looking switches that meant different things; here the roster's one +/// switch always means dashboard visibility, and "stop reading" is a named +/// control inside the provider's own detail. +struct SettingsPlatformsAndSourcesPage: View { @ObservedObject var model: MonitorModel + // Fleet draft state. One struct owns all of it: the dirty tracking and + // the empty-endpoint deadlock guard read these together, and splitting + // them across child views would break both. @State private var syncEndpoint = "" @State private var syncToken = "" @State private var syncFormat: QuotaSyncFormat = .usageMonitorV2 @@ -398,6 +317,16 @@ struct SettingsSourcesFleetPage: View { @State private var claudeConsentMessage: String? @State private var claudeConsentSucceeded = false + /// Providers whose detail is expanded. A row that carries a blocking + /// problem (consent, chiefly) starts expanded, so the fix shows without + /// hunting; the old page kept that button always visible. + @State private var expandedProviders: Set = [] + @State private var draggedProviderKey: String? + /// The row the hidden Option+Command arrow shortcuts act on. A tap sets + /// it; VoiceOver rows move themselves through custom actions, and the + /// context menu covers pointer users who skipped the tap. + @State private var selectedProviderKey: String? + private var pushDirty: Bool { pushEnabled != model.syncEnabled || syncEndpoint != model.syncEndpoint || syncFormat != model.syncFormat || !syncToken.isEmpty } @@ -413,15 +342,11 @@ struct SettingsSourcesFleetPage: View { var body: some View { SettingsPage { - Section { - Link("Setup & Data Guide", destination: URL(string: "https://codecaps.simplewithus.com/setup.html")!) - Text("Turn on this Mac, sharing, and other devices separately.") - .font(.caption).foregroundStyle(.secondary) - } + providersSection thisMacSection - sourcesRankSection shareSection pullSection + setupGuideSection } .onAppear { syncEndpoint = model.syncEndpoint @@ -429,10 +354,416 @@ struct SettingsSourcesFleetPage: View { pullEndpoint = model.endpoint pushEnabled = model.syncEnabled pullEnabled = model.serverEnabled + expandedProviders.formUnion(claudeConsentKeys) + } + // Consent can arrive after the page opens — `refreshSavedTokenStates` + // answers on the async path — so a row that starts blocking later + // opens with its fix showing, exactly as it would have on appear + // (Kody finding, 2026-11-27). + .onChange(of: model.consentNeeded) { _, _ in + expandedProviders.formUnion(claudeConsentKeys) } .task { await model.refreshSavedTokenStates() } .onChange(of: model.syncEnabled) { _, newValue in pushEnabled = newValue } .onChange(of: model.serverEnabled) { _, newValue in pullEnabled = newValue } + .background { + // Keyboard equivalents for the drag, kept from the old Platforms + // page and installed exactly once: duplicating them per row + // would fire each shortcut twice. + VStack { + Button("") { moveSelected(by: -1) } + .keyboardShortcut(.upArrow, modifiers: [.option, .command]) + Button("") { moveSelected(by: 1) } + .keyboardShortcut(.downArrow, modifiers: [.option, .command]) + } + .opacity(0) + .accessibilityHidden(true) + } + } + + // MARK: Providers roster + + private var claudeConsentKeys: Set { + Set(model.consentNeeded.filter { $0 == "anthropic" || $0 == "claude" }) + } + + /// One canonical roster: every provider a reader knows about plus every + /// platform a live section reports, in the owner's platform order, with + /// never-ordered keys appended in reader order. The old Platforms page + /// listed live sections only — empty before the first read — and the old + /// Sources list ordered by `ReaderStatus`, so a newly added provider + /// could exist on one page and miss the other. + private var rosterKeys: [String] { + var keys: [String] = [] + var seen = Set() + for candidate in ReaderStatus.current.map(\.providerKey) where !seen.contains(candidate) { + seen.insert(candidate) + keys.append(candidate) + } + for key in model.sections.map(\.providerKey) where !seen.contains(key) { + seen.insert(key) + keys.append(key) + } + guard !model.platformOrder.isEmpty else { return keys } + let ordered = model.platformOrder.filter(seen.contains) + return ordered + keys.filter { !ordered.contains($0) } + } + + private func rosterLabel(for providerKey: String) -> String { + if let live = model.sections.first(where: { $0.providerKey == providerKey })?.providerLabel { + return live + } + return ReaderStatus.current.first { $0.providerKey == providerKey }?.label ?? providerKey + } + + private func reader(for providerKey: String) -> ReaderStatus? { + ReaderStatus.current.first { $0.providerKey == providerKey } + } + + private func needsConsent(_ providerKey: String) -> Bool { + claudeConsentKeys.contains(providerKey) + } + + /// Whether a row has anything to open. Plain rows render no chevron and + /// never expand, so the roster stays scannable; expansion is an offer, + /// not a tab stop. + private func hasDetail(_ providerKey: String) -> Bool { + if needsConsent(providerKey) { return true } + if let optionalReaderID = reader(for: providerKey)?.optionalReaderID { return true } + return model.availableSources(for: providerKey).count > 1 + } + + private var providersSection: some View { + Section { + VStack(alignment: .leading, spacing: 0) { + ForEach(Array(rosterKeys.enumerated()), id: \.element) { index, providerKey in + rosterRow(providerKey, position: index + 1, total: rosterKeys.count) + if index < rosterKeys.count - 1 { + Divider() + .padding(.leading, 40) + } + } + HStack { + Spacer() + // The one visible secondary control: the drag handle is + // primary, and reset belongs out of the row flow. + Button("Reset Default Order") { model.resetPlatformOrder() } + .buttonStyle(.borderless) + .font(.caption) + .help("Reset Default Order") + .accessibilityLabel("Reset Default Order") + } + .padding(.top, 4) + } + } header: { + Eyebrow("PROVIDERS") + } footer: { + Text("Drag rows to set the order every surface uses — the Console cards, the Docked Bar, and the menu bar." + sentenceGap + + "A switch hides a platform from the dashboard without stopping its refreshes." + sentenceGap + + "Most plans read the sign-in already on this Mac; open a provider's detail for its reader switch, setup, and sources.") + .font(.caption) + .foregroundStyle(.secondary) + .fixedSize(horizontal: false, vertical: true) + } + } + + @ViewBuilder + private func rosterRow(_ providerKey: String, position: Int, total: Int) -> some View { + let label = rosterLabel(for: providerKey) + let visible = model.isProviderVisible(providerKey) + let reader = reader(for: providerKey) + let issue = model.issues[providerKey] + let optionalEnabled = reader?.optionalReaderID.map(model.isOptionalQuotaReaderEnabled) ?? true + let sectionHasWindows = !(model.sections.first { $0.providerKey == providerKey }?.windows.isEmpty ?? true) + let healthy = optionalEnabled && issue == nil && sectionHasWindows + let expanded = expandedProviders.contains(providerKey) + VStack(alignment: .leading, spacing: 0) { + HStack(spacing: 8) { + Image(systemName: "line.3.horizontal") + .font(.system(size: 11)) + .foregroundStyle(.tertiary) + .help("Drag to Reorder") + .accessibilityHidden(true) + PlatformLogo(providerKey: providerKey, size: 16, + style: model.markStyle(for: providerKey)) + VStack(alignment: .leading, spacing: 1) { + Text(label) + .font(.subheadline.weight(.medium)) + .foregroundStyle(visible ? Theme.ink : Color.secondary) + .lineLimit(1) + rowCaption(providerKey: providerKey, reader: reader, + issue: issue, optionalEnabled: optionalEnabled) + } + // The tap lives on the label area only, so a flip of the + // visibility switch never also expands or collapses the + // detail (Kody finding, 2026-11-27). + .contentShape(Rectangle()) + .onTapGesture { + selectedProviderKey = providerKey + if hasDetail(providerKey) { + toggleDetail(providerKey, expanded: expanded) + } + } + if hasDetail(providerKey) { + Button { + toggleDetail(providerKey, expanded: expanded) + } label: { + Image(systemName: "chevron.right") + .font(.system(size: 9, weight: .semibold)) + .rotationEffect(.degrees(expanded ? 90 : 0)) + .foregroundStyle(.tertiary) + } + .buttonStyle(.borderless) + .help(expanded ? "Hide \(label) Detail" : "Show \(label) Detail") + .accessibilityLabel(expanded ? "Hide \(label) Detail" : "Show \(label) Detail") + } + Spacer(minLength: 8) + // The glyph column is fixed so every switch on the page lands + // at the same x. Hidden and reader-off rows already say why; + // the glyph would only repeat them. + if visible && optionalEnabled { + Image(systemName: healthy ? "checkmark.circle" : "exclamationmark.triangle") + .font(.system(size: 12)) + .foregroundStyle(healthy ? Theme.success : Theme.warning) + .frame(width: 16) + .accessibilityHidden(true) + } else { + Color.clear.frame(width: 16, height: 12) + } + Toggle("", isOn: Binding( + get: { model.isProviderVisible(providerKey) }, + set: { model.setProviderVisible($0, providerKey: providerKey) })) + .labelsHidden() + .toggleStyle(.switch) + .controlSize(.mini) + .help(visible ? "Hide \(label) from the dashboard" : "Show \(label) in the dashboard") + .accessibilityLabel(visible ? "Hide \(label) from the dashboard" : "Show \(label) in the dashboard") + } + .padding(.vertical, 5) + .onDrag { + draggedProviderKey = providerKey + return NSItemProvider(object: providerKey as NSString) + } + .onDrop(of: [UTType.text], delegate: ProviderRosterDropDelegate( + targetKey: providerKey, + draggedKey: $draggedProviderKey, + onMove: { moveProvider($0, onto: $1) })) + .contextMenu { + Button("Move Up") { moveProviderUp(providerKey) } + .disabled(providerKey == rosterKeys.first) + Button("Move Down") { moveProviderDown(providerKey) } + .disabled(providerKey == rosterKeys.last) + } + .accessibilityElement(children: .contain) + .accessibilityLabel("\(label), position \(position) of \(total)") + // The named actions are VoiceOver's equivalent of the drag and + // the context menu — the old page's visible arrow buttons, kept + // operable without a pointer. The detail toggle only exists on + // rows with something to open, so a plain row never offers a + // no-op action (Kody finding, 2026-11-27). + .accessibilityAction(named: Text("Move Up")) { moveProviderUp(providerKey) } + .accessibilityAction(named: Text("Move Down")) { moveProviderDown(providerKey) } + .modifier(DetailToggleAccessibilityAction( + hasDetail: hasDetail(providerKey), + title: expanded ? "Hide Detail" : "Show Detail", + action: { toggleDetail(providerKey, expanded: expanded) })) + if expanded, hasDetail(providerKey) { + providerDetail(providerKey, reader: reader) + .padding(.leading, 40) + .padding(.bottom, 6) + } + } + } + + private func toggleDetail(_ providerKey: String, expanded: Bool) { + if expanded { + expandedProviders.remove(providerKey) + } else { + expandedProviders.insert(providerKey) + } + } + + /// The caption under the provider name, in priority order: the problem + /// first, the off state second, then what the provider reads from. A + /// multi-source provider gets a summary that also hints there is a + /// detail to open — no badge, no chip, one line. + @ViewBuilder + private func rowCaption(providerKey: String, reader: ReaderStatus?, + issue: String?, optionalEnabled: Bool) -> some View { + if let issue { + Text(issue) + .font(.caption) + .foregroundStyle(Color.secondary) + .fixedSize(horizontal: false, vertical: true) + } else if !optionalEnabled { + Text("Quota reads are off for this provider.") + .font(.caption) + .foregroundStyle(Color.secondary) + } else { + let sources = model.availableSources(for: providerKey) + let preferred = sources.first { !model.disabledSources.contains($0) } + Group { + if sources.count > 1, let preferred { + Text("\(sources.count) sources · prefers \(preferred)") + } else if let reader { + Text(reader.source) + .help(reader.optionalReaderID == "alibaba-token-plan" ? AlibabaTokenPlanHelp.tooltip : "") + } else { + Text("Local readings") + } + } + .font(.caption) + .foregroundStyle(Color.secondary) + .lineLimit(1) + .truncationMode(.middle) + } + } + + @ViewBuilder + private func providerDetail(_ providerKey: String, reader: ReaderStatus?) -> some View { + VStack(alignment: .leading, spacing: 8) { + if needsConsent(providerKey) { claudeConsentControls } + if let optionalReaderID = reader?.optionalReaderID { + // The reader switch lives here under its own name, because + // the roster switch means visibility. Two same-looking + // switches with different consequences was the merge's + // reason to exist. + HStack { + Text("Quota Reads On This Mac") + .font(.caption.weight(.medium)) + Spacer() + Toggle("", isOn: Binding( + get: { model.isOptionalQuotaReaderEnabled(optionalReaderID) }, + set: { model.setOptionalQuotaReaderEnabled($0, readerID: optionalReaderID) })) + .labelsHidden() + .toggleStyle(.switch) + .controlSize(.mini) + .help(model.isOptionalQuotaReaderEnabled(optionalReaderID) + ? "Turn Off \(reader?.label ?? providerKey) Quota Reads" + : "Turn On \(reader?.label ?? providerKey) Quota Reads") + .accessibilityLabel("Read \(reader?.label ?? providerKey) Quota") + } + if optionalReaderID == "zcode" { ZAIQuotaSettingsView(controller: model.zAIQuotaSetup) } + if optionalReaderID == "alibaba-token-plan" { AlibabaTokenPlanHelpView() } + if optionalReaderID == "mimo-token-plan" { MiMoQuotaSettings(model: model) } + } + sourceRankDetail(for: providerKey) + } + } + + /// The provider's per-source enable + rank, shown only when more than + /// one source was observed — the Dashboard page should not tease a + /// control that has no effect. + @ViewBuilder + private func sourceRankDetail(for providerKey: String) -> some View { + let sources = model.availableSources(for: providerKey) + if sources.count > 1 { + VStack(alignment: .leading, spacing: 4) { + HStack { + Text("Sources · Preferred First") + .font(.caption2.weight(.semibold)) + .foregroundStyle(.secondary) + Spacer() + Text("\(sources.count) sources") + .font(.caption2) + .foregroundStyle(.tertiary) + } + ForEach(Array(sources.enumerated()), id: \.element) { index, source in + sourceRow(source: source, index: index, total: sources.count, + providerKey: providerKey) + } + } + } + } + + @ViewBuilder + private func sourceRow(source: String, index: Int, total: Int, providerKey: String) -> some View { + let enabled = !model.disabledSources.contains(source) + HStack(spacing: 8) { + Toggle("", isOn: Binding( + get: { enabled }, + set: { model.setSourceEnabled($0, source, for: providerKey) })) + .labelsHidden() + .toggleStyle(.switch) + .controlSize(.mini) + .help(enabled ? "Hide windows from \(source)" : "Show windows from \(source)") + .accessibilityLabel(enabled ? "Hide windows from \(source)" : "Show windows from \(source)") + + Text(source) + .font(.system(.callout, design: .monospaced)) + .foregroundStyle(enabled ? Theme.ink : Color.secondary) + .lineLimit(1) + .truncationMode(.middle) + .frame(maxWidth: .infinity, alignment: .leading) + + Text("#\(index + 1)") + .font(.system(.caption, design: .monospaced).weight(.medium)) + .foregroundStyle(.secondary) + .frame(width: 24, alignment: .trailing) + + Button { + model.moveSource(source, by: -1, for: providerKey) + } label: { + Image(systemName: "arrow.up").font(.system(size: 10)) + } + .buttonStyle(.borderless) + .disabled(index == 0) + .help("Move \(source) up") + .accessibilityLabel("Move \(source) up") + + Button { + model.moveSource(source, by: 1, for: providerKey) + } label: { + Image(systemName: "arrow.down").font(.system(size: 10)) + } + .buttonStyle(.borderless) + .disabled(index == total - 1) + .help("Move \(source) down") + .accessibilityLabel("Move \(source) down") + } + .padding(.leading, 4) + } + + // Roster order helpers + + /// Move within the roster the page displays, not within `platformOrder` + /// or the live sections: the roster adds readers a live section has + /// never reported, and the model helpers would silently no-op or swap a + /// different list than the one on screen (Seer finding, 2026-11-27). + /// Committing the whole roster keeps `platformOrder` a faithful record + /// of what the owner arranged. + private func moveProviderUp(_ providerKey: String) { + var keys = rosterKeys + guard let index = keys.firstIndex(of: providerKey), index > 0 else { return } + keys.swapAt(index, index - 1) + model.platformOrder = keys + } + + private func moveProviderDown(_ providerKey: String) { + var keys = rosterKeys + guard let index = keys.firstIndex(of: providerKey), index < keys.count - 1 else { return } + keys.swapAt(index, index + 1) + model.platformOrder = keys + } + + /// Live reorder for the drag: move `dragged` onto `target` in the + /// roster and commit the whole order, so `platformOrder` always + /// describes what the roster shows. `toOffset` alone serves both + /// directions: the `move(fromOffsets:toOffset:)` contract measures the + /// destination against the array after the removal, so a downward drag + /// inserts at the target, not after it (Kody finding, 2026-11-27). + private func moveProvider(_ dragged: String, onto target: String) { + var keys = rosterKeys + guard let from = keys.firstIndex(of: dragged), + let to = keys.firstIndex(of: target), from != to else { return } + keys.move(fromOffsets: IndexSet(integer: from), toOffset: to) + model.platformOrder = keys + } + + private func moveSelected(by delta: Int) { + guard let selectedProviderKey else { return } + if delta < 0 { moveProviderUp(selectedProviderKey) } + else { moveProviderDown(selectedProviderKey) } } // MARK: This Mac @@ -480,18 +811,10 @@ struct SettingsSourcesFleetPage: View { } } .disabled(!model.localEnabled || !model.sessionFileChecksEnabled) - ForEach(ReaderStatus.current, id: \.providerKey) { reader in - readerRow(reader) - if reader.optionalReaderID == "zcode" { ZAIQuotaSettingsView(controller: model.zAIQuotaSetup) } - if reader.optionalReaderID == "alibaba-token-plan" { AlibabaTokenPlanHelpView() } - if reader.optionalReaderID == "mimo-token-plan" { MiMoQuotaSettings(model: model) } - } } header: { Eyebrow("THIS MAC") } footer: { VStack(alignment: .leading, spacing: 4) { - Text("Most plans use the sign-in already on this Mac." + sentenceGap - + "Z.ai Coding Plan reads use your ZCode sign-in, or the regional API key you save here.") Text("Plan checks use the sign-in already on this Mac." + sentenceGap + "Copilot uses your existing GitHub sign-in.") Text("Codex session checks read a file on this Mac." + sentenceGap @@ -510,68 +833,15 @@ struct SettingsSourcesFleetPage: View { } } - private func readerRow(_ reader: ReaderStatus) -> some View { - let section = model.sections.first { $0.providerKey == reader.providerKey } - let issue = model.issues[reader.providerKey] - let optionalEnabled = reader.optionalReaderID.map(model.isOptionalQuotaReaderEnabled) ?? true - let healthy = optionalEnabled && issue == nil && !(section?.windows.isEmpty ?? true) - // A reader whose credential is on this Mac but unreadable by this - // build gets a button rather than a sentence it cannot act on. - let needsConsent = model.consentNeeded.contains(reader.providerKey) - return VStack(alignment: .leading, spacing: 2) { - HStack(spacing: 8) { - PlatformLogo(providerKey: reader.providerKey, size: 16, - style: model.markStyle(for: reader.providerKey)) - Text(section?.providerLabel ?? reader.label) - .font(.subheadline.weight(.medium)) - .frame(width: 110, alignment: .leading) - Text(reader.source) - .font(.caption) - .foregroundStyle(.secondary) - .help(reader.optionalReaderID == "alibaba-token-plan" ? AlibabaTokenPlanHelp.tooltip : "") - Spacer(minLength: 8) - if let readerID = reader.optionalReaderID { - Toggle("", isOn: Binding( - get: { model.isOptionalQuotaReaderEnabled(readerID) }, - set: { model.setOptionalQuotaReaderEnabled($0, readerID: readerID) })) - .labelsHidden() - .toggleStyle(.switch) - .controlSize(.mini) - .help(optionalEnabled ? "Turn Off \(reader.label) Quota Reads" : "Turn On \(reader.label) Quota Reads") - .accessibilityLabel("Read \(reader.label) Quota") - } else { - Image(systemName: healthy ? "checkmark.circle" : "exclamationmark.triangle") - .font(.system(size: 12)) - .foregroundStyle(healthy ? Theme.success : Theme.warning) - .accessibilityHidden(true) - } - } - if !optionalEnabled { - Text("Quota reads are off for this provider.") - .font(.caption) - .foregroundStyle(.secondary) - .fixedSize(horizontal: false, vertical: true) - } else if let issue { - Text(issue) - .font(.caption) - .foregroundStyle(.secondary) - .fixedSize(horizontal: false, vertical: true) - } else if !healthy && model.localEnabled { - Text("Not signed in locally.") - .font(.caption) - .foregroundStyle(.secondary) - } - if needsConsent { claudeConsentControls } - } - // A row carrying a button must stay navigable, so only the plain rows - // collapse into one element. - .accessibilityElement(children: needsConsent ? .contain : .combine) - } - /// The consent step, shown only when macOS explicitly refuses the /// `security` read the refresh loop makes. The button runs that same - /// `security` read without a short deadline, so the panel macOS shows, and - /// the Always Allow answered in it, apply to the program the loop reads as. + /// `security` read without a short deadline, so the panel macOS shows, + /// and the Always Allow answered in it, apply to the program the loop + /// reads as. Only Claude's detail carries it: an interactive sign-in + /// failure from any other reader (Antigravity, for one) also lands in + /// consentNeeded, and its fix is signing in to that provider, not + /// granting macOS permission to read Claude Code's saved login + /// (owner, 2026-11-27). @ViewBuilder private var claudeConsentControls: some View { VStack(alignment: .leading, spacing: 4) { @@ -608,132 +878,6 @@ struct SettingsSourcesFleetPage: View { .padding(.top, 2) } - // MARK: Source Ranking - - /// Per-provider source enable + rank. Sections only render for providers - /// that have more than one observed source — the Dashboard page should not - /// tease a control that has no effect. - @ViewBuilder - private var sourcesRankSection: some View { - let grouped: [(key: String, label: String, sources: [String])] = model.displaySections - .map(\.section.providerKey) - .reduce(into: [String]()) { acc, key in - let sources = model.availableSources(for: key) - guard sources.count > 1 else { return } - if !acc.contains(key) { acc.append(key) } - } - .map { key in - let label = model.sections.first { $0.providerKey == key }?.providerLabel ?? key - return (key: key, label: label, sources: model.availableSources(for: key)) - } - if !grouped.isEmpty { - Section { - ForEach(grouped, id: \.key) { group in - sourceGroup(for: group.key, label: group.label, sources: group.sources) - } - } header: { - Eyebrow("SOURCES PER PLATFORM") - } footer: { - Text("CodeCaps pulls each provider's quota from whichever sources can answer." + sentenceGap - + "Turn a source off to drop its windows everywhere — the menu bar, Docked Bar, and Console all skip it." + sentenceGap - + "Reorder to tell CodeCaps which source wins when two disagree; the top of the list is preferred, the bottom is the fallback.") - .font(.caption) - .foregroundStyle(.secondary) - .fixedSize(horizontal: false, vertical: true) - } - } - } - - @ViewBuilder - private func sourceGroup(for providerKey: String, label: String, sources: [String]) -> some View { - VStack(alignment: .leading, spacing: 6) { - HStack(spacing: 8) { - // This one shipped without a `style:`, so it drew the init's - // old default of `.template` and every mark here came out grey - // no matter what the Logo Style page had set. The init no - // longer has a default for exactly this reason. - PlatformLogo(providerKey: providerKey, size: 16, - style: model.markStyle(for: providerKey)) - Text(label) - .font(.subheadline.weight(.medium)) - Spacer() - Text("\(sources.count) sources") - .font(.caption2) - .foregroundStyle(.tertiary) - } - ForEach(Array(sources.enumerated()), id: \.element) { index, source in - sourceRow(source: source, - index: index, - total: sources.count, - providerKey: providerKey) - } - } - .padding(.vertical, 4) - } - - @ViewBuilder - private func sourceRow(source: String, index: Int, total: Int, providerKey: String) -> some View { - let enabled = !model.disabledSources.contains(source) - HStack(spacing: 8) { - Toggle("", isOn: Binding( - get: { enabled }, - set: { model.setSourceEnabled($0, source, for: providerKey) })) - .labelsHidden() - .toggleStyle(.switch) - .controlSize(.mini) - .help(enabled ? "Hide windows from \(source)" : "Show windows from \(source)") - .accessibilityLabel(enabled ? "Hide windows from \(source)" : "Show windows from \(source)") - - Text(source) - .font(.system(.callout, design: .monospaced)) - .foregroundStyle(enabled ? Theme.ink : .secondary) - .lineLimit(1) - .truncationMode(.middle) - .frame(maxWidth: .infinity, alignment: .leading) - - Text("#\(index + 1)") - .font(.system(.caption, design: .monospaced).weight(.medium)) - .foregroundStyle(.secondary) - .frame(width: 24, alignment: .trailing) - - Button { - model.moveSource(source, by: -1, for: providerKey) - } label: { - Image(systemName: "arrow.up").font(.system(size: 10)) - } - .buttonStyle(.borderless) - .disabled(index == 0) - .help("Move \(source) up") - .accessibilityLabel("Move \(source) up") - - Button { - model.moveSource(source, by: 1, for: providerKey) - } label: { - Image(systemName: "arrow.down").font(.system(size: 10)) - } - .buttonStyle(.borderless) - .disabled(index == total - 1) - .help("Move \(source) down") - .accessibilityLabel("Move \(source) down") - } - .padding(.leading, 24) - } - - -/// Shown under a group's header when a token is on file that this build cannot -/// read. Plain words, because the alternative the owner actually met was a -/// pull that failed with nothing to act on. -private struct ReauthorizeCaption: View { - var body: some View { - Text("This build cannot read the saved token yet." + sentenceGap - + "Re-authorize it, or paste the token again.") - .font(.caption) - .foregroundStyle(Theme.warning) - .textCase(nil) - .fixedSize(horizontal: false, vertical: true) - } -} - // MARK: Share This Mac private var shareSection: some View { @@ -867,7 +1011,7 @@ private struct ReauthorizeCaption: View { } } - // MARK: Pull The Fleet + // MARK: Other Devices private var pullSection: some View { Section { @@ -944,26 +1088,26 @@ private struct ReauthorizeCaption: View { } } header: { VStack(alignment: .leading, spacing: 3) { - HStack { - Eyebrow("OTHER DEVICES") - Spacer() - if let dashboardURL { - Button { - NSWorkspace.shared.open(dashboardURL) - } label: { - Label("Open Web Dashboard", systemImage: "arrow.up.right.square") + HStack { + Eyebrow("OTHER DEVICES") + Spacer() + if let dashboardURL { + Button { + NSWorkspace.shared.open(dashboardURL) + } label: { + Label("Open Web Dashboard", systemImage: "arrow.up.right.square") + } + .buttonStyle(.plain) + .font(.caption) + .textCase(nil) + .help("Open Web Dashboard") + .accessibilityLabel("Open Web Dashboard") } - .buttonStyle(.plain) - .font(.caption) - .textCase(nil) - .help("Open Web Dashboard") - .accessibilityLabel("Open Web Dashboard") + Text(model.lastPullTime.map { "Pulled \($0.formatted(date: .omitted, time: .shortened))" } ?? "Never pulled") + .font(.caption) + .foregroundStyle(.secondary) + .textCase(nil) } - Text(model.lastPullTime.map { "Pulled \($0.formatted(date: .omitted, time: .shortened))" } ?? "Never pulled") - .font(.caption) - .foregroundStyle(.secondary) - .textCase(nil) - } if model.readTokenState.needsReauthorization { ReauthorizeCaption() } @@ -1002,8 +1146,84 @@ private struct ReauthorizeCaption: View { } } } + + // MARK: Setup Guide + + /// Reference material, so it sits at the foot: the page leads with its + /// namesake content and owners who need the guide will find it either way. + private var setupGuideSection: some View { + Section { + Link("Setup & Data Guide", destination: URL(string: "https://codecaps.simplewithus.com/setup.html")!) + Text("Turn on this Mac, sharing, and other devices separately.") + .font(.caption) + .foregroundStyle(.secondary) + } header: { + Eyebrow("SETUP & DATA GUIDE") + } + } +} + +/// Shown under a group's header when a token is on file that this build cannot +/// read. Plain words, because the alternative the owner actually met was a +/// pull that failed with nothing to act on. +private struct ReauthorizeCaption: View { + var body: some View { + Text("This build cannot read the saved token yet." + sentenceGap + + "Re-authorize it, or paste the token again.") + .font(.caption) + .foregroundStyle(Theme.warning) + .textCase(nil) + .fixedSize(horizontal: false, vertical: true) + } +} + +/// Live reflow for the roster drag, on the `PipOptionsReorderList` pattern: +/// onDrag/onDrop with a drop delegate, which works inside a grouped Form +/// where `List.onMove`'s drop indicator does not. +/// The detail toggle as a named VoiceOver action, offered only on rows that +/// have something to open — plain rows must not advertise a no-op. +private struct DetailToggleAccessibilityAction: ViewModifier { + let hasDetail: Bool + let title: String + let action: () -> Void + + func body(content: Content) -> some View { + Group { + if hasDetail { + content.accessibilityAction(named: Text(title)) { action() } + } else { + content + } + } + } } +/// Live reflow for the roster drag, on the `PipOptionsReorderList` pattern: +/// onDrag/onDrop with a drop delegate, which works inside a grouped Form +/// where `List.onMove`'s drop indicator does not. +private struct ProviderRosterDropDelegate: DropDelegate { + let targetKey: String + @Binding var draggedKey: String? + let onMove: (String, String) -> Void + + func dropEntered(info: DropInfo) { + guard let dragged = draggedKey, dragged != targetKey else { return } + withAnimation(.easeInOut(duration: 0.18)) { + onMove(dragged, targetKey) + } + } + + func performDrop(info: DropInfo) -> Bool { + draggedKey = nil + return true + } + + func dropUpdated(info: DropInfo) -> DropProposal? { + DropProposal(operation: .move) + } +} + + /// Local quota readers, named by the credential they actually read. struct ReaderStatus { let providerKey: String diff --git a/Sources/CodeCaps/TokenStore.swift b/Sources/CodeCaps/TokenStore.swift index a354c63c..0b22b35d 100644 --- a/Sources/CodeCaps/TokenStore.swift +++ b/Sources/CodeCaps/TokenStore.swift @@ -109,7 +109,7 @@ enum TokenStore { switch self { // The old wording named the problem and left the owner with // nothing to do about it. This one points at the button. - case .read: return "The saved token is unavailable in Keychain.\u{00A0} Re-authorize it in Sources & Fleet, or paste it again." + case .read: return "The saved token is unavailable in Keychain.\u{00A0} Re-authorize it in Platforms & Sources, or paste it again." case let .write(status, service): return TokenStore.writeFailureMessage(status: status, service: service) } } diff --git a/Sources/QuotaCore/TokenPlanQuotaReader.swift b/Sources/QuotaCore/TokenPlanQuotaReader.swift index bbc39ebb..9ad7fafa 100644 --- a/Sources/QuotaCore/TokenPlanQuotaReader.swift +++ b/Sources/QuotaCore/TokenPlanQuotaReader.swift @@ -41,7 +41,7 @@ struct MiMoTokenPlanReader: LocalQuotaReading { func read() async -> LocalQuotaResult { let id = "mimo-token-plan" guard let credential = await credential(), credential.isValid else { - return LocalQuotaResult(issues: [id: "Save an individual MiMo Token Plan key in Sources & Fleet."]) + return LocalQuotaResult(issues: [id: "Save an individual MiMo Token Plan key in Platforms & Sources."]) } var request = URLRequest(url: credential.region.quotaURL) request.httpMethod = "GET" diff --git a/Sources/QuotaCore/WidgetPlatformDisplay.swift b/Sources/QuotaCore/WidgetPlatformDisplay.swift index a83fa716..ec6b9a62 100644 --- a/Sources/QuotaCore/WidgetPlatformDisplay.swift +++ b/Sources/QuotaCore/WidgetPlatformDisplay.swift @@ -496,6 +496,12 @@ public enum CompanionProviderMarkAssets { if low.contains("muse") { return "provider-muse-assist" } if low.contains("antigravity") { return "provider-antigravity" } if low.contains("gemini") { return "provider-gemini" } + // Alibaba's two plans share the one brand mark; MiMo and OpenCode Go + // carry their own. Checked after the established keys so an + // overlapping substring cannot steal a row. + if low.contains("alibaba") || low.contains("qwen") { return "provider-alibaba" } + if low.contains("mimo") { return "provider-mimo" } + if low.contains("opencode") { return "provider-opencode-go" } switch CompanionProviderRouting.canonicalKey(provider: providerKey, providerKey: providerKey, via: nil) { case "grok-bot": return "provider-grok-bot" diff --git a/Sources/QuotaCore/ZCodeQuotaReader.swift b/Sources/QuotaCore/ZCodeQuotaReader.swift index 212a1b71..ff33ab01 100644 --- a/Sources/QuotaCore/ZCodeQuotaReader.swift +++ b/Sources/QuotaCore/ZCodeQuotaReader.swift @@ -670,7 +670,7 @@ private struct ExplicitZCodeQuotaReader: Sendable { do { try Task.checkCancellation() guard let credential = await credential(), credential.isValid else { - return LocalQuotaResult(issues: ["zcode": "Z.ai quota setup is needed.\u{00A0} Save a Coding Plan API key in Sources & Fleet."]) + return LocalQuotaResult(issues: ["zcode": "Z.ai quota setup is needed.\u{00A0} Save a Coding Plan API key in Platforms & Sources."]) } try Task.checkCancellation() let result = try await Self.fetchQuota(url: credential.region.quotaURL, token: credential.apiKey, fetch: fetch) diff --git a/Tests/CodeCapsTests/ConsoleNavigationTests.swift b/Tests/CodeCapsTests/ConsoleNavigationTests.swift index 5489603c..1347dc75 100644 --- a/Tests/CodeCapsTests/ConsoleNavigationTests.swift +++ b/Tests/CodeCapsTests/ConsoleNavigationTests.swift @@ -14,7 +14,6 @@ final class ConsoleNavigationTests: XCTestCase { .platform("anthropic"), .runawayAlerts, .settingsMenuBar, - .settingsPlatforms, .settingsLogoStyle, .settingsSourcesFleet, .settingsNotifications, @@ -29,6 +28,14 @@ final class ConsoleNavigationTests: XCTestCase { } } + /// The old Platforms page merged into Platforms & Sources (owner, + /// 2026-11-27): the case is gone, but a saved selection under the old + /// storage key must land on the merged page, not nil. + func testLegacyPlatformsKeyLandsOnTheMergedPage() { + XCTAssertEqual(ConsolePage.fromStorageKey("settingsPlatforms"), .settingsSourcesFleet) + XCTAssertEqual(ConsolePage.settingsSourcesFleet.settingsTitle, "Platforms & Sources") + } + func testConsolePageIsSettings() { XCTAssertFalse(ConsolePage.allPlatforms.isSettings) XCTAssertFalse(ConsolePage.platform("anthropic").isSettings) diff --git a/Tests/CodeCapsTests/PipLogoStyleTests.swift b/Tests/CodeCapsTests/PipLogoStyleTests.swift new file mode 100644 index 00000000..ffa0cced --- /dev/null +++ b/Tests/CodeCapsTests/PipLogoStyleTests.swift @@ -0,0 +1,71 @@ +import XCTest +@testable import CodeCaps +import QuotaCore + +/// Which artwork the PiP HUD draws beside each provider. Automatic keeps the +/// shipped background-following behaviour; the two explicit choices exist +/// because the owner asked to choose which logo the PiP uses (2026-11-27). +@MainActor +final class PipLogoStyleTests: XCTestCase { + + /// Automatic is exactly the old rule: silhouettes on a dark HUD, brand + /// colour on a white one, always monochrome-forced. + func testAutomaticFollowsTheBackgroundAndForcesMonochrome() { + for background in PipBackground.allCases { + let presentation = PipLogoStyle.automatic.presentation( + on: background, ownerStyle: .standard) + XCTAssertEqual(presentation.style, background.markStyle(for: .standard), + "\(background.rawValue) changed its mark rule under Automatic") + XCTAssertTrue(presentation.forceMonochrome, + "\(background.rawValue) must keep the monochrome default") + } + } + + /// Brand Color pins the full-colour mark whatever the background. + func testBrandColorPinsTheColourMark() { + for background in PipBackground.allCases { + let presentation = PipLogoStyle.brandColor.presentation( + on: background, ownerStyle: .standard) + XCTAssertEqual(presentation.style, .standard, + "\(background.rawValue) must not restyle the colour mark") + XCTAssertFalse(presentation.forceMonochrome, + "\(background.rawValue) must not force monochrome on a colour mark") + } + } + + /// Light/Dark pins the adapting silhouette. + func testLightDarkPinsTheTemplateMark() { + for background in PipBackground.allCases { + let presentation = PipLogoStyle.lightDark.presentation( + on: background, ownerStyle: .standard) + XCTAssertEqual(presentation.style, .template, + "\(background.rawValue) must keep the light/dark silhouette") + XCTAssertTrue(presentation.forceMonochrome, + "\(background.rawValue) must force monochrome on the silhouette") + } + } + + /// An owner-imported mark is never restyled in any PiP choice; only the + /// monochrome forcing follows the style. + func testACustomMarkIsNeverRewritten() { + for style in PipLogoStyle.allCases { + for background in PipBackground.allCases { + let presentation = style.presentation(on: background, ownerStyle: .custom) + XCTAssertEqual(presentation.style, .custom, + "\(style.rawValue) restyled an owner-imported mark on \(background.rawValue)") + } + } + XCTAssertTrue(PipLogoStyle.automatic.presentation(on: .black, ownerStyle: .custom).forceMonochrome) + XCTAssertFalse(PipLogoStyle.brandColor.presentation(on: .black, ownerStyle: .custom).forceMonochrome) + } + + /// The preference round-trips through its raw value, so a saved choice + /// restores instead of silently reverting to Automatic. + func testRawValueRoundTrips() { + for style in PipLogoStyle.allCases { + XCTAssertEqual(PipLogoStyle(rawValue: style.rawValue), style) + } + XCTAssertNil(PipLogoStyle(rawValue: "bogus"), + "an unknown saved value must fall back to Automatic at the caller") + } +} diff --git a/Tests/CodeCapsTests/SettingsMigrationTests.swift b/Tests/CodeCapsTests/SettingsMigrationTests.swift index 4b3e7267..a91aa615 100644 --- a/Tests/CodeCapsTests/SettingsMigrationTests.swift +++ b/Tests/CodeCapsTests/SettingsMigrationTests.swift @@ -113,7 +113,7 @@ final class ConsolePageStorageTests: XCTestCase { let pages: [ConsolePage] = [ .allPlatforms, .platform("anthropic"), .platform("google-antigravity:gemini"), - .platform("a:b"), .settingsMenuBar, .settingsPlatforms, .settingsSourcesFleet, + .platform("a:b"), .settingsMenuBar, .settingsSourcesFleet, .settingsAppearance, .settingsAbout, ] for page in pages { @@ -121,6 +121,13 @@ final class ConsolePageStorageTests: XCTestCase { } } + /// The old Platforms page merged into Platforms & Sources (owner, + /// 2026-11-27): the case is gone, and a persisted selection under the old + /// storage key lands on the merged page instead of being dropped. + func testLegacyPlatformsStorageKeyMapsToTheMergedPage() { + XCTAssertEqual(ConsolePage.fromStorageKey("settingsPlatforms"), .settingsSourcesFleet) + } + func testAnUnknownKeyIsRejectedRatherThanGuessed() { XCTAssertNil(ConsolePage.fromStorageKey("")) XCTAssertNil(ConsolePage.fromStorageKey("bogusKey")) diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/Contents.json b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/Contents.json index d9a07d41..72160f01 100644 --- a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,95 +1,275 @@ { "images": [ + { + "filename": "light-icon-20.png", + "idiom": "universal", + "platform": "ios", + "size": "20x20" + }, { "filename": "icon-20.png", "idiom": "universal", "platform": "ios", + "size": "20x20", + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ] + }, + { + "filename": "light-icon-20@2x.png", + "idiom": "universal", + "platform": "ios", "size": "20x20" }, { "filename": "icon-20@2x.png", "idiom": "universal", "platform": "ios", + "size": "20x20", + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ] + }, + { + "filename": "light-icon-20@3x.png", + "idiom": "universal", + "platform": "ios", "size": "20x20" }, { "filename": "icon-20@3x.png", "idiom": "universal", "platform": "ios", - "size": "20x20" + "size": "20x20", + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ] + }, + { + "filename": "light-icon-29.png", + "idiom": "universal", + "platform": "ios", + "size": "29x29" }, { "filename": "icon-29.png", "idiom": "universal", "platform": "ios", + "size": "29x29", + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ] + }, + { + "filename": "light-icon-29@2x.png", + "idiom": "universal", + "platform": "ios", "size": "29x29" }, { "filename": "icon-29@2x.png", "idiom": "universal", "platform": "ios", + "size": "29x29", + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ] + }, + { + "filename": "light-icon-29@3x.png", + "idiom": "universal", + "platform": "ios", "size": "29x29" }, { "filename": "icon-29@3x.png", "idiom": "universal", "platform": "ios", - "size": "29x29" + "size": "29x29", + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ] + }, + { + "filename": "light-icon-40.png", + "idiom": "universal", + "platform": "ios", + "size": "40x40" }, { "filename": "icon-40.png", "idiom": "universal", "platform": "ios", + "size": "40x40", + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ] + }, + { + "filename": "light-icon-40@2x.png", + "idiom": "universal", + "platform": "ios", "size": "40x40" }, { "filename": "icon-40@2x.png", "idiom": "universal", "platform": "ios", + "size": "40x40", + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ] + }, + { + "filename": "light-icon-40@3x.png", + "idiom": "universal", + "platform": "ios", "size": "40x40" }, { "filename": "icon-40@3x.png", "idiom": "universal", "platform": "ios", - "size": "40x40" + "size": "40x40", + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ] + }, + { + "filename": "light-icon-60@2x.png", + "idiom": "universal", + "platform": "ios", + "size": "60x60" }, { "filename": "icon-60@2x.png", "idiom": "universal", "platform": "ios", + "size": "60x60", + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ] + }, + { + "filename": "light-icon-60@3x.png", + "idiom": "universal", + "platform": "ios", "size": "60x60" }, { "filename": "icon-60@3x.png", "idiom": "universal", "platform": "ios", - "size": "60x60" + "size": "60x60", + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ] + }, + { + "filename": "light-icon-76.png", + "idiom": "universal", + "platform": "ios", + "size": "76x76" }, { "filename": "icon-76.png", "idiom": "universal", "platform": "ios", + "size": "76x76", + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ] + }, + { + "filename": "light-icon-76@2x.png", + "idiom": "universal", + "platform": "ios", "size": "76x76" }, { "filename": "icon-76@2x.png", "idiom": "universal", "platform": "ios", - "size": "76x76" + "size": "76x76", + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ] }, { - "filename": "icon-83.5@2x.png", + "filename": "light-icon-83.5@2x.png", "idiom": "universal", "platform": "ios", "size": "83.5x83.5" }, { - "filename": "icon-1024.png", + "filename": "icon-83.5@2x.png", + "idiom": "universal", + "platform": "ios", + "size": "83.5x83.5", + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ] + }, + { + "filename": "light-icon-1024.png", "idiom": "universal", "platform": "ios", "size": "1024x1024" }, + { + "filename": "icon-1024.png", + "idiom": "universal", + "platform": "ios", + "size": "1024x1024", + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ] + }, { "filename": "mac-16.png", "idiom": "mac", diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-1024.png b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-1024.png new file mode 100644 index 00000000..f31ba2fa Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-1024.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-20.png b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-20.png new file mode 100644 index 00000000..3d6a7cf8 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-20.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-20@2x.png b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-20@2x.png new file mode 100644 index 00000000..20ffd4b2 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-20@2x.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-20@3x.png b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-20@3x.png new file mode 100644 index 00000000..2f46719e Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-20@3x.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-29.png b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-29.png new file mode 100644 index 00000000..16f0c6d6 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-29.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-29@2x.png b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-29@2x.png new file mode 100644 index 00000000..c761ce3d Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-29@2x.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-29@3x.png b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-29@3x.png new file mode 100644 index 00000000..b0346ab1 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-29@3x.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-40.png b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-40.png new file mode 100644 index 00000000..20ffd4b2 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-40.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-40@2x.png b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-40@2x.png new file mode 100644 index 00000000..e0d95846 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-40@2x.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-40@3x.png b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-40@3x.png new file mode 100644 index 00000000..327d42a9 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-40@3x.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-60@2x.png b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-60@2x.png new file mode 100644 index 00000000..327d42a9 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-60@2x.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-60@3x.png b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-60@3x.png new file mode 100644 index 00000000..df2bf8be Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-60@3x.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-76.png b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-76.png new file mode 100644 index 00000000..5317f878 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-76.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-76@2x.png b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-76@2x.png new file mode 100644 index 00000000..a1a5d1a4 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-76@2x.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-83.5@2x.png b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-83.5@2x.png new file mode 100644 index 00000000..3e8a6cf3 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/AppIcon.appiconset/light-icon-83.5@2x.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/provider-alibaba.imageset/Contents.json b/ios/CodeCapsCompanion/Assets.xcassets/provider-alibaba.imageset/Contents.json new file mode 100644 index 00000000..c10cc0b4 --- /dev/null +++ b/ios/CodeCapsCompanion/Assets.xcassets/provider-alibaba.imageset/Contents.json @@ -0,0 +1,25 @@ +{ + "images": [ + { + "filename": "provider-alibaba.png", + "idiom": "universal" + }, + { + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ], + "filename": "provider-alibaba-dark.png", + "idiom": "universal" + } + ], + "info": { + "author": "xcode", + "version": 1 + }, + "properties": { + "template-rendering-intent": "original" + } +} diff --git a/ios/CodeCapsCompanion/Assets.xcassets/provider-alibaba.imageset/provider-alibaba-dark.png b/ios/CodeCapsCompanion/Assets.xcassets/provider-alibaba.imageset/provider-alibaba-dark.png new file mode 100644 index 00000000..09969d5f Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/provider-alibaba.imageset/provider-alibaba-dark.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/provider-alibaba.imageset/provider-alibaba.png b/ios/CodeCapsCompanion/Assets.xcassets/provider-alibaba.imageset/provider-alibaba.png new file mode 100644 index 00000000..8e028088 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/provider-alibaba.imageset/provider-alibaba.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/provider-mimo.imageset/Contents.json b/ios/CodeCapsCompanion/Assets.xcassets/provider-mimo.imageset/Contents.json new file mode 100644 index 00000000..e5d84bc4 --- /dev/null +++ b/ios/CodeCapsCompanion/Assets.xcassets/provider-mimo.imageset/Contents.json @@ -0,0 +1,25 @@ +{ + "images": [ + { + "filename": "provider-mimo.png", + "idiom": "universal" + }, + { + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ], + "filename": "provider-mimo-dark.png", + "idiom": "universal" + } + ], + "info": { + "author": "xcode", + "version": 1 + }, + "properties": { + "template-rendering-intent": "original" + } +} diff --git a/ios/CodeCapsCompanion/Assets.xcassets/provider-mimo.imageset/provider-mimo-dark.png b/ios/CodeCapsCompanion/Assets.xcassets/provider-mimo.imageset/provider-mimo-dark.png new file mode 100644 index 00000000..3257f182 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/provider-mimo.imageset/provider-mimo-dark.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/provider-mimo.imageset/provider-mimo.png b/ios/CodeCapsCompanion/Assets.xcassets/provider-mimo.imageset/provider-mimo.png new file mode 100644 index 00000000..89a850d6 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/provider-mimo.imageset/provider-mimo.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/provider-opencode-go.imageset/Contents.json b/ios/CodeCapsCompanion/Assets.xcassets/provider-opencode-go.imageset/Contents.json new file mode 100644 index 00000000..1c9a3abd --- /dev/null +++ b/ios/CodeCapsCompanion/Assets.xcassets/provider-opencode-go.imageset/Contents.json @@ -0,0 +1,25 @@ +{ + "images": [ + { + "filename": "provider-opencode-go.png", + "idiom": "universal" + }, + { + "appearances": [ + { + "appearance": "luminosity", + "value": "dark" + } + ], + "filename": "provider-opencode-go-dark.png", + "idiom": "universal" + } + ], + "info": { + "author": "xcode", + "version": 1 + }, + "properties": { + "template-rendering-intent": "original" + } +} diff --git a/ios/CodeCapsCompanion/Assets.xcassets/provider-opencode-go.imageset/provider-opencode-go-dark.png b/ios/CodeCapsCompanion/Assets.xcassets/provider-opencode-go.imageset/provider-opencode-go-dark.png new file mode 100644 index 00000000..22955eb1 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/provider-opencode-go.imageset/provider-opencode-go-dark.png differ diff --git a/ios/CodeCapsCompanion/Assets.xcassets/provider-opencode-go.imageset/provider-opencode-go.png b/ios/CodeCapsCompanion/Assets.xcassets/provider-opencode-go.imageset/provider-opencode-go.png new file mode 100644 index 00000000..5e264771 Binary files /dev/null and b/ios/CodeCapsCompanion/Assets.xcassets/provider-opencode-go.imageset/provider-opencode-go.png differ