fix: center emoji artwork in launcher icon slot

This commit is contained in:
Valdemar Lorenzen
2026-10-15 15:35:20 +02:00
parent da1493a3c8
commit 0ba61153d4
3 changed files with 37 additions and 4 deletions
@@ -0,0 +1,28 @@
import AppKit
import Testing
@testable import Conjure
@Test @MainActor func emojiCommandArtworkHasBalancedVisiblePadding() throws {
_ = NSApplication.shared
let launcher = LauncherWindowController()
func descendants(_ view: NSView) -> [NSView] { [view] + view.subviews.flatMap(descendants) }
let views = descendants(try #require(launcher.window?.contentView))
let search = try #require(views.compactMap { $0 as? NSSearchField }.first)
search.stringValue = "emoji"
launcher.controlTextDidChange(Notification(name: NSControl.textDidChangeNotification, object: search))
let table = try #require(views.compactMap { $0 as? NSTableView }.first)
let cell = try #require(launcher.tableView(table, viewFor: nil, row: 0) as? ApplicationCell)
let image = try #require(cell.imageView?.image)
let data = try #require(image.tiffRepresentation)
let bitmap = try #require(NSBitmapImageRep(data: data))
var left = bitmap.pixelsWide, right = -1, top = bitmap.pixelsHigh, bottom = -1
for y in 0..<bitmap.pixelsHigh {
for x in 0..<bitmap.pixelsWide where (bitmap.colorAt(x: x, y: y)?.alphaComponent ?? 0) > 0.5 {
left = min(left, x); right = max(right, x)
top = min(top, y); bottom = max(bottom, y)
}
}
#expect(right > left && bottom > top)
#expect(abs(left - (bitmap.pixelsWide - right - 1)) <= 2)
#expect(abs(top - (bitmap.pixelsHigh - bottom - 1)) <= 2)
}