From 51909d28da9545abae50a1ea81dc21ce653c0110 Mon Sep 17 00:00:00 2001 From: progresshans Date: Sat, 28 Nov 2026 14:43:27 +0900 Subject: [PATCH 1/2] feat: a DEV or TEST tag on a Debug build's Dock icon A Debug build in the Dock looked like the installed Kaern beside it, and so did a flow check's test instances, a few at a time. Now a Debug build draws a tag on the top right of its Dock icon: an orange DEV on a build you run yourself (build_and_run.sh, Xcode), a purple TEST on an instance of a test session (-KaernSessionFile: the flow checks, checks/launch.sh). DockTag sets the Dock tile's content view (NSDockTile.contentView, a public AppKit API since macOS 10.5) to the app's icon with the tag drawn in the icon's 1024-unit grid, the tag and its shadow inside the canvas. A shadow's blur and offset are in device pixels, so they are scaled with the drawing: unscaled, a small tile's shadow spread past the canvas and was cut off at its edge. Only the Dock tile changes: the app's icon, which the alerts drawn in the window show, stays as it is. All of it is in #if DEBUG; a Release build has none of it. Co-Authored-By: Claude Opus 5.5 --- Kaern/App/AppDelegate.swift | 2 + Kaern/App/DockTag.swift | 86 +++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 Kaern/App/DockTag.swift diff --git a/Kaern/App/AppDelegate.swift b/Kaern/App/AppDelegate.swift index f671af3..7c92dac 100644 --- a/Kaern/App/AppDelegate.swift +++ b/Kaern/App/AppDelegate.swift @@ -19,6 +19,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ notification: Notification) { #if DEBUG + // DEV or TEST on the Dock icon, so a Debug build isn't taken for the installed Kaern (DockTag). + DockTag.install() // Debug commands (stage, commit, discard…) are broadcast to every running Kaern. Only an // instance on a test session listens, so a Debug build open on your own repositories never // acts on commands a test run sends to its sample repositories. diff --git a/Kaern/App/DockTag.swift b/Kaern/App/DockTag.swift new file mode 100644 index 0000000..2fb3c50 --- /dev/null +++ b/Kaern/App/DockTag.swift @@ -0,0 +1,86 @@ +#if DEBUG +import AppKit + +/// A tag on a Debug build's Dock icon, so it isn't taken for the installed Kaern beside it: DEV on a build you run +/// yourself (build_and_run.sh, Xcode), TEST on an instance of a test session (`-KaernSessionFile`: the flow checks, +/// checks/launch.sh). Release builds have none of it. +/// +/// Only the Dock tile changes (`NSDockTile.contentView`): the app's icon (`NSApp.applicationIconImage`) stays as it +/// is, so the alerts drawn in the window, and the checks' pictures of them, keep the plain one. +enum DockTag: String { + case dev = "DEV" + case test = "TEST" + + /// This instance's: a test session's, or a build of your own. + static var current: DockTag { SessionStore.testSessionPath != nil ? .test : .dev } + + /// The tag on this instance's Dock tile, once `install()` has run. + private(set) static var shown: DockTag? + + var color: NSColor { + switch self { + case .dev: NSColor(srgbRed: 0.96, green: 0.45, blue: 0.05, alpha: 1) + case .test: NSColor(srgbRed: 0.53, green: 0.32, blue: 0.92, alpha: 1) + } + } + + static func install() { + let tile = NSApp.dockTile + tile.contentView = DockTagView(current, size: tile.size) + tile.display() + shown = current + } +} + +/// The app's icon with a tag on its top right corner. Drawn in the icon's own grid (an 824-unit tile in a 1024-unit +/// canvas, `script/make_icon.swift`), the tag and its shadow inside the canvas: the Dock shows nothing past it. +final class DockTagView: NSView { + let kind: DockTag + + init(_ kind: DockTag, size: NSSize) { + self.kind = kind + super.init(frame: NSRect(origin: .zero, size: size)) + } + + @available(*, unavailable) + required init?(coder: NSCoder) { fatalError() } + + override func draw(_ dirtyRect: NSRect) { + guard let context = NSGraphicsContext.current else { return } + context.imageInterpolation = .high + NSApp.applicationIconImage?.draw(in: bounds) + + NSGraphicsContext.saveGraphicsState() + let grid = NSAffineTransform() + grid.scale(by: bounds.width / 1024) + grid.concat() + let kern: CGFloat = 6 + let font = NSFont.systemFont(ofSize: 162, weight: .heavy) + let text = NSAttributedString(string: kind.rawValue, attributes: [.font: font, .foregroundColor: NSColor.white, .kern: kern]) + let textWidth = text.size().width - kern // no kern after the last letter + let height: CGFloat = 270 + let tag = NSRect(x: 990 - (textWidth + 120), y: 990 - height, width: textWidth + 120, height: height) + let path = NSBezierPath(roundedRect: tag, xRadius: 68, yRadius: 68) + + // A shadow's blur and offset are in device pixels whatever the drawing's scale: scaled to the grid here, or a + // small tile's shadow would spread past the canvas and be cut off at its edge. + NSGraphicsContext.saveGraphicsState() + let scale = hypot(context.cgContext.ctm.a, context.cgContext.ctm.b) + let shadow = NSShadow() + shadow.shadowColor = NSColor(white: 0, alpha: 0.28) + shadow.shadowBlurRadius = 12 * scale + shadow.shadowOffset = NSSize(width: 0, height: -6 * scale) + shadow.set() + kind.color.setFill() + path.fill() + NSGraphicsContext.restoreGraphicsState() + + NSColor.white.setStroke() + path.lineWidth = 22 + path.stroke() + // The capitals centred by their cap height. + text.draw(at: NSPoint(x: tag.midX - textWidth / 2, y: tag.midY - font.capHeight / 2 + font.descender)) + NSGraphicsContext.restoreGraphicsState() + } +} +#endif From a6411f2a4248054977a43408704f1c11261dfcc7 Mon Sep 17 00:00:00 2001 From: progresshans Date: Sat, 28 Nov 2026 14:43:27 +0900 Subject: [PATCH 2/2] test: t_isolation checks a test instance's TEST tag on its Dock icon The dump's driver section has dockTag (the tag DockTag installed), and `dockTile [dev|test]` writes the Dock tile's drawing as a PNG at twice the tile's size: this instance's, or the named tag's. t_isolation checks that a test instance shows TEST and keeps a picture of each tag in shots/; the checks' README says what the tags are. t_isolation passed, and the tiles it pictured read clearly at 58 pt and 105 pt (the Dock's size and its magnified size on this Mac), in a light and a dark Dock. The Release build (script/release.sh --unsigned) compiles without any of it. The full suite: 52 of 52. Co-Authored-By: Claude Opus 5.5 --- Kaern/App/DebugDriver.swift | 19 +++++++++++++++++++ checks/README.md | 4 ++++ checks/t_isolation.py | 7 +++++++ 3 files changed, 30 insertions(+) diff --git a/Kaern/App/DebugDriver.swift b/Kaern/App/DebugDriver.swift index d2bddd3..993c56c 100644 --- a/Kaern/App/DebugDriver.swift +++ b/Kaern/App/DebugDriver.swift @@ -107,6 +107,9 @@ final class DebugDriver { switch command { case "snapshot": snapshot(to: args.first ?? "/tmp/kaern.png", window: args.count > 1 ? Int(args[1]) : nil) + case "dockTile": + // dockTile [dev|test]: the Dock tile's drawing; with a kind, that tag's instead of this instance's. + dockTilePicture(to: args.first ?? "/tmp/kaern-dock.png", kind: args.count > 1 ? DockTag(rawValue: args[1].uppercased()) : nil) case "appearance": NSApp.appearance = args.first == "dark" ? NSAppearance(named: .darkAqua) : NSAppearance(named: .aqua) case "activate": @@ -983,6 +986,20 @@ final class DebugDriver { try? data.write(to: URL(filePath: path)) } + /// The Dock tile's drawing (`DockTag`) as a PNG at twice the tile's size, as a Retina Dock draws it. + private func dockTilePicture(to path: String, kind: DockTag?) { + let size = NSApp.dockTile.size + guard let view = kind.map({ DockTagView($0, size: size) }) ?? NSApp.dockTile.contentView, + let rep = NSBitmapImageRep( + bitmapDataPlanes: nil, pixelsWide: Int(size.width * 2), pixelsHigh: Int(size.height * 2), bitsPerSample: 8, + samplesPerPixel: 4, hasAlpha: true, isPlanar: false, colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0) + else { return } + rep.size = size + view.cacheDisplay(in: view.bounds, to: rep) + guard let data = rep.representation(using: .png, properties: [:]) else { return } + try? data.write(to: URL(filePath: path)) + } + private func dump(to path: String) { var windows: [[String: Any]] = [] for controller in app.windows { @@ -1142,6 +1159,8 @@ final class DebugDriver { "fieldText": editor?.string ?? "", "fieldPlaceholder": field?.placeholderString ?? field?.placeholderAttributedString?.string ?? "", "appearance": NSApp.effectiveAppearance.isDark ? "dark" : "light", + // The tag on the Dock icon (DockTag): TEST on a test instance. + "dockTag": DockTag.shown?.rawValue ?? "", "pointerBusy": pointerTasks > 0, "drag": ["sequence": lastDragSequence, "handle": lastResizeHandle, "value": lastResizeValue, "storedAfterChange": sizesAfterDragChange, "storedAfterMouseUp": sizesAfterMouseUp] as [String: Any], diff --git a/checks/README.md b/checks/README.md index 6024f5e..5f69b27 100644 --- a/checks/README.md +++ b/checks/README.md @@ -45,6 +45,10 @@ are the same. The menus and popovers a check opens come up beside them, where th instance's screens answer from there as well, `TestSession.moveScreensAside`), so the pictures have them too. `KAERN_ON_SCREEN=1` keeps the windows on the screen, to watch a check. +A test instance's Dock icon has a purple TEST tag, and a Debug build you run yourself an orange DEV one +(`Kaern/App/DockTag.swift`), so neither is taken for the Kaern you use. `t_isolation` checks it and keeps a picture +of each tag in `shots/`. + ## Where things are `python3 checks/paths.py` prints the work folder and the app. The work folder is in the temporary folder, one per diff --git a/checks/t_isolation.py b/checks/t_isolation.py index f19c709..a5f4418 100644 --- a/checks/t_isolation.py +++ b/checks/t_isolation.py @@ -13,6 +13,13 @@ def real_state(): real_before = real_state() start_app('light', columns=False, git_config=False) d = wait_launched() +# Its Dock icon has the TEST tag, so it isn't taken for your own Kaern, or for a Debug build you run yourself (DEV). +tag = d['driver']['dockTag']; print('dock tag:', tag) +assert tag == 'TEST', 'a test instance shows %r on its Dock icon' % tag +for kind in ('test', 'dev'): + tile = shot_path('isolation-dock-tile-' + kind, 'light') + k('dockTile', tile, kind); sync() + assert os.path.getsize(tile) > 0, 'no picture of the %s Dock tile' % kind genv = d['gitConfigEnvironment']; print('git config environment:', genv) assert genv.get('GIT_CONFIG_GLOBAL') == STEM + '.gitconfig' assert '' in genv.values() and any(v.startswith('store --file=') for v in genv.values())