|
| 1 | +import CodexBarCore |
| 2 | + |
| 3 | +enum IconRemainingResolver { |
| 4 | + private static func codexProjection(snapshot: UsageSnapshot) -> CodexConsumerProjection { |
| 5 | + CodexConsumerProjection.make( |
| 6 | + surface: .menuBar, |
| 7 | + context: CodexConsumerProjection.Context( |
| 8 | + snapshot: snapshot, |
| 9 | + rawUsageError: nil, |
| 10 | + liveCredits: nil, |
| 11 | + rawCreditsError: nil, |
| 12 | + liveDashboard: nil, |
| 13 | + rawDashboardError: nil, |
| 14 | + dashboardAttachmentAuthorized: false, |
| 15 | + dashboardRequiresLogin: false, |
| 16 | + now: snapshot.updatedAt)) |
| 17 | + } |
| 18 | + |
| 19 | + private static func codexVisibleWindows(snapshot: UsageSnapshot) -> [RateWindow] { |
| 20 | + let projection = self.codexProjection(snapshot: snapshot) |
| 21 | + return projection.visibleRateLanes.compactMap { projection.rateWindow(for: $0) } |
| 22 | + } |
| 23 | + |
| 24 | + static func resolvedWindows( |
| 25 | + snapshot: UsageSnapshot, |
| 26 | + style: IconStyle) |
| 27 | + -> (primary: RateWindow?, secondary: RateWindow?) |
| 28 | + { |
| 29 | + if style == .perplexity { |
| 30 | + let windows = snapshot.orderedPerplexityDisplayWindows() |
| 31 | + return ( |
| 32 | + primary: windows.first, |
| 33 | + secondary: windows.dropFirst().first) |
| 34 | + } |
| 35 | + if style == .antigravity { |
| 36 | + let windows = [snapshot.primary, snapshot.secondary, snapshot.tertiary].compactMap(\.self) |
| 37 | + return ( |
| 38 | + primary: windows.first, |
| 39 | + secondary: windows.dropFirst().first) |
| 40 | + } |
| 41 | + if style == .codex { |
| 42 | + let windows = self.codexVisibleWindows(snapshot: snapshot) |
| 43 | + return ( |
| 44 | + primary: windows.first, |
| 45 | + secondary: windows.dropFirst().first) |
| 46 | + } |
| 47 | + return ( |
| 48 | + primary: snapshot.primary, |
| 49 | + secondary: snapshot.secondary) |
| 50 | + } |
| 51 | + |
| 52 | + static func resolvedRemaining( |
| 53 | + snapshot: UsageSnapshot, |
| 54 | + style: IconStyle) |
| 55 | + -> (primary: Double?, secondary: Double?) |
| 56 | + { |
| 57 | + if style == .perplexity { |
| 58 | + let windows = snapshot.orderedPerplexityDisplayWindows() |
| 59 | + return ( |
| 60 | + primary: windows.first?.remainingPercent, |
| 61 | + secondary: windows.dropFirst().first?.remainingPercent) |
| 62 | + } |
| 63 | + if style == .antigravity { |
| 64 | + let windows = [snapshot.primary, snapshot.secondary, snapshot.tertiary].compactMap(\.self) |
| 65 | + return ( |
| 66 | + primary: windows.first?.remainingPercent, |
| 67 | + secondary: windows.dropFirst().first?.remainingPercent) |
| 68 | + } |
| 69 | + if style == .codex { |
| 70 | + let windows = self.codexVisibleWindows(snapshot: snapshot) |
| 71 | + return ( |
| 72 | + primary: windows.first?.remainingPercent, |
| 73 | + secondary: windows.dropFirst().first?.remainingPercent) |
| 74 | + } |
| 75 | + return ( |
| 76 | + primary: snapshot.primary?.remainingPercent, |
| 77 | + secondary: snapshot.secondary?.remainingPercent) |
| 78 | + } |
| 79 | + |
| 80 | + static func resolvedPercents( |
| 81 | + snapshot: UsageSnapshot, |
| 82 | + style: IconStyle, |
| 83 | + showUsed: Bool) |
| 84 | + -> (primary: Double?, secondary: Double?) |
| 85 | + { |
| 86 | + let windows = Self.resolvedWindows(snapshot: snapshot, style: style) |
| 87 | + return ( |
| 88 | + primary: showUsed ? windows.primary?.usedPercent : windows.primary?.remainingPercent, |
| 89 | + secondary: showUsed ? windows.secondary?.usedPercent : windows.secondary?.remainingPercent) |
| 90 | + } |
| 91 | +} |
0 commit comments