-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix single-quota menu bar icon scaling #3155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
steipete
merged 1 commit into
steipete:main
from
akshayprabhu200:codex/fix-menu-icon-usage-scale
Aug 23, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
Tests/CodexBarTests/IconRendererScreenshotRenderTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import AppKit | ||
| import XCTest | ||
| @testable import CodexBar | ||
|
|
||
| /// Developer tool, skipped by default: renders a synthetic single-quota icon for PR proof. | ||
| /// | ||
| /// Run with: | ||
| /// CODEXBAR_ICON_SCREENSHOT_DIR=docs/screenshots \ | ||
| /// swift test --filter IconRendererScreenshotRenderTests | ||
| @MainActor | ||
| final class IconRendererScreenshotRenderTests: XCTestCase { | ||
| private static let canvasSize = NSSize(width: 360, height: 240) | ||
|
|
||
| func test_renderSyntheticSingleQuotaIcon() throws { | ||
| guard let dir = ProcessInfo.processInfo.environment["CODEXBAR_ICON_SCREENSHOT_DIR"] else { | ||
| throw XCTSkip("Set CODEXBAR_ICON_SCREENSHOT_DIR to render the synthetic icon proof.") | ||
| } | ||
| let directory = URL(fileURLWithPath: dir, isDirectory: true) | ||
| try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true) | ||
|
|
||
| let icon = IconRenderer.makeIcon( | ||
| primaryRemaining: 46, | ||
| weeklyRemaining: nil, | ||
| creditsRemaining: nil, | ||
| stale: false, | ||
| style: .combined, | ||
| hideCritters: true, | ||
| quotaLayoutPolicy: .provider(.codex)) | ||
| let data = try XCTUnwrap(Self.proofPNG(icon: icon), "synthetic icon proof render failed") | ||
| let url = directory.appendingPathComponent("codex-single-quota-icon.png") | ||
| try data.write(to: url, options: .atomic) | ||
| print("Wrote \(url.lastPathComponent)") | ||
| } | ||
|
|
||
| private static func proofPNG(icon: NSImage) -> Data? { | ||
| guard let representation = NSBitmapImageRep( | ||
| bitmapDataPlanes: nil, | ||
| pixelsWide: Int(canvasSize.width), | ||
| pixelsHigh: Int(canvasSize.height), | ||
| bitsPerSample: 8, | ||
| samplesPerPixel: 4, | ||
| hasAlpha: true, | ||
| isPlanar: false, | ||
| colorSpaceName: .deviceRGB, | ||
| bytesPerRow: 0, | ||
| bitsPerPixel: 0), | ||
| let context = NSGraphicsContext(bitmapImageRep: representation) | ||
| else { return nil } | ||
| representation.size = Self.canvasSize | ||
|
|
||
| NSGraphicsContext.saveGraphicsState() | ||
| NSGraphicsContext.current = context | ||
| NSColor(srgbRed: 0.10, green: 0.11, blue: 0.12, alpha: 1).setFill() | ||
| NSRect(origin: .zero, size: Self.canvasSize).fill() | ||
|
|
||
| let paragraph = NSMutableParagraphStyle() | ||
| paragraph.alignment = .center | ||
| let titleAttributes: [NSAttributedString.Key: Any] = [ | ||
| .font: NSFont.systemFont(ofSize: 26, weight: .semibold), | ||
| .foregroundColor: NSColor.white, | ||
| .paragraphStyle: paragraph, | ||
| ] | ||
| let subtitleAttributes: [NSAttributedString.Key: Any] = [ | ||
| .font: NSFont.monospacedDigitSystemFont(ofSize: 22, weight: .regular), | ||
| .foregroundColor: NSColor(white: 0.72, alpha: 1), | ||
| .paragraphStyle: paragraph, | ||
| ] | ||
| NSString(string: "Synthetic proof").draw( | ||
| in: NSRect(x: 24, y: 192, width: 312, height: 36), | ||
| withAttributes: titleAttributes) | ||
| NSString(string: "46% remaining").draw( | ||
| in: NSRect(x: 24, y: 158, width: 312, height: 32), | ||
| withAttributes: subtitleAttributes) | ||
|
|
||
| context.imageInterpolation = .none | ||
| icon.isTemplate = false | ||
| icon.draw( | ||
| in: NSRect(x: 108, y: 20, width: 144, height: 144), | ||
| from: NSRect(origin: .zero, size: icon.size), | ||
| operation: .sourceOver, | ||
| fraction: 1, | ||
| respectFlipped: false, | ||
| hints: nil) | ||
| NSGraphicsContext.restoreGraphicsState() | ||
| return representation.representation(using: .png, properties: [.interlaced: false]) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.