Files
backspace/packages/desktop/scripts/gen-dock-icon.swift
T
Jannis Braun c176ea801a feat: squircle dock icon for macOS dev mode
macOS only applies the squircle mask to packaged .app bundles. For dev
mode, generate a pre-masked icon-dock.png via Swift/AppKit at launch
and set it with app.dock.setIcon(). Silently skipped on non-macOS.
2026-03-16 04:15:09 +01:00

22 lines
812 B
Swift

// Generates a squircle-masked dock icon for macOS dev mode.
// macOS only applies the squircle mask to packaged .app bundles,
// so app.dock.setIcon() needs a pre-masked PNG.
import AppKit
let src = NSImage(contentsOfFile: "build/icon.png")!
let size = src.size
let out = NSImage(size: size)
out.lockFocus()
let radius = size.width * 0.2237
let path = NSBezierPath(roundedRect: NSRect(origin: .zero, size: size), xRadius: radius, yRadius: radius)
path.addClip()
src.draw(in: NSRect(origin: .zero, size: size), from: NSRect(origin: .zero, size: size), operation: .sourceOver, fraction: 1.0)
out.unlockFocus()
let tiff = out.tiffRepresentation!
let rep = NSBitmapImageRep(data: tiff)!
let png = rep.representation(using: .png, properties: [:])!
try! png.write(to: URL(fileURLWithPath: "build/icon-dock.png"))