Skip to content

Commit f1f8d0d

Browse files
Merge pull request #8 from jamesmontemagno/agents/svg-icon-background-removal
Add ClickLight icon SVG asset
2 parents c891939 + a719952 commit f1f8d0d

5 files changed

Lines changed: 186 additions & 0 deletions

File tree

31.3 KB
Loading

AppIcon.icon/icon.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"fill" : {
3+
"linear-gradient" : [
4+
"display-p3:0.23193,0.41350,0.80588,1.00000",
5+
"display-p3:0.38860,0.77688,0.96841,1.00000"
6+
],
7+
"orientation" : {
8+
"start" : {
9+
"x" : 0.5,
10+
"y" : 1
11+
},
12+
"stop" : {
13+
"x" : 0.5,
14+
"y" : 0.3
15+
}
16+
}
17+
},
18+
"groups" : [
19+
{
20+
"layers" : [
21+
{
22+
"glass" : true,
23+
"image-name" : "ClickLight-icon.png",
24+
"name" : "ClickLight-icon",
25+
"position" : {
26+
"scale" : 1,
27+
"translation-in-points" : [
28+
17.5,
29+
35.5
30+
]
31+
}
32+
}
33+
],
34+
"shadow" : {
35+
"kind" : "neutral",
36+
"opacity" : 0.5
37+
},
38+
"translucency" : {
39+
"enabled" : true,
40+
"value" : 0.5
41+
}
42+
}
43+
],
44+
"supported-platforms" : {
45+
"circles" : [
46+
"watchOS"
47+
],
48+
"squares" : "shared"
49+
}
50+
}

Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<string>ClickLight</string>
99
<key>CFBundleIdentifier</key>
1010
<string>com.aurorascharff.ClickLight</string>
11+
<key>CFBundleIconFile</key>
12+
<string>ClickLight</string>
1113
<key>CFBundleInfoDictionaryVersion</key>
1214
<string>6.0</string>
1315
<key>CFBundleName</key>

build-app.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2525
BUILD_DIR="$ROOT_DIR/.build/$CONFIGURATION"
2626
APP_DIR="$ROOT_DIR/$APP_NAME.app"
2727
ZIP_PATH="$ROOT_DIR/$APP_NAME.zip"
28+
ICON_SOURCE="$ROOT_DIR/AppIcon.icon/Assets/ClickLight-icon.png"
29+
ICON_RENDER_SCRIPT="$ROOT_DIR/scripts/render-icon.swift"
30+
ICON_RENDERED_SOURCE="$BUILD_DIR/$APP_NAME-rendered-icon.png"
31+
ICONSET_DIR="$BUILD_DIR/$APP_NAME.iconset"
2832

2933
VERSION="$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.1.0")"
3034

@@ -40,6 +44,31 @@ cp "$ROOT_DIR/Info.plist" "$APP_DIR/Contents/Info.plist"
4044

4145
cp "$BUILD_DIR/$APP_NAME" "$APP_DIR/Contents/MacOS/$APP_NAME"
4246

47+
if [ ! -f "$ICON_SOURCE" ]; then
48+
echo "Missing app icon source: $ICON_SOURCE"
49+
exit 1
50+
fi
51+
52+
if [ ! -f "$ICON_RENDER_SCRIPT" ]; then
53+
echo "Missing app icon renderer: $ICON_RENDER_SCRIPT"
54+
exit 1
55+
fi
56+
57+
rm -rf "$ICONSET_DIR"
58+
mkdir -p "$ICONSET_DIR"
59+
swift "$ICON_RENDER_SCRIPT" "$ICON_SOURCE" "$ICON_RENDERED_SOURCE"
60+
sips -z 16 16 "$ICON_RENDERED_SOURCE" --out "$ICONSET_DIR/icon_16x16.png" >/dev/null
61+
sips -z 32 32 "$ICON_RENDERED_SOURCE" --out "$ICONSET_DIR/icon_16x16@2x.png" >/dev/null
62+
sips -z 32 32 "$ICON_RENDERED_SOURCE" --out "$ICONSET_DIR/icon_32x32.png" >/dev/null
63+
sips -z 64 64 "$ICON_RENDERED_SOURCE" --out "$ICONSET_DIR/icon_32x32@2x.png" >/dev/null
64+
sips -z 128 128 "$ICON_RENDERED_SOURCE" --out "$ICONSET_DIR/icon_128x128.png" >/dev/null
65+
sips -z 256 256 "$ICON_RENDERED_SOURCE" --out "$ICONSET_DIR/icon_128x128@2x.png" >/dev/null
66+
sips -z 256 256 "$ICON_RENDERED_SOURCE" --out "$ICONSET_DIR/icon_256x256.png" >/dev/null
67+
sips -z 512 512 "$ICON_RENDERED_SOURCE" --out "$ICONSET_DIR/icon_256x256@2x.png" >/dev/null
68+
sips -z 512 512 "$ICON_RENDERED_SOURCE" --out "$ICONSET_DIR/icon_512x512.png" >/dev/null
69+
sips -z 1024 1024 "$ICON_RENDERED_SOURCE" --out "$ICONSET_DIR/icon_512x512@2x.png" >/dev/null
70+
iconutil --convert icns "$ICONSET_DIR" --output "$APP_DIR/Contents/Resources/$APP_NAME.icns"
71+
4372
SPARKLE_PATH="$(find "$ROOT_DIR/.build" -name "Sparkle.framework" -type d | head -1)"
4473
if [ -n "$SPARKLE_PATH" ]; then
4574
cp -a "$SPARKLE_PATH" "$APP_DIR/Contents/Frameworks/"

scripts/render-icon.swift

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import CoreGraphics
2+
import Foundation
3+
import ImageIO
4+
import UniformTypeIdentifiers
5+
6+
let arguments = CommandLine.arguments
7+
8+
guard arguments.count == 3 else {
9+
fputs("Usage: render-icon.swift <glyph.png> <output.png>\n", stderr)
10+
exit(64)
11+
}
12+
13+
let glyphURL = URL(fileURLWithPath: arguments[1])
14+
let outputURL = URL(fileURLWithPath: arguments[2])
15+
16+
guard
17+
let glyphSource = CGImageSourceCreateWithURL(glyphURL as CFURL, nil),
18+
let glyph = CGImageSourceCreateImageAtIndex(glyphSource, 0, nil)
19+
else {
20+
fputs("Could not read icon glyph at \(glyphURL.path)\n", stderr)
21+
exit(66)
22+
}
23+
24+
let size = 1024
25+
let bounds = CGRect(x: 0, y: 0, width: size, height: size)
26+
27+
guard
28+
let colorSpace = CGColorSpace(name: CGColorSpace.displayP3) ?? CGColorSpace(name: CGColorSpace.sRGB),
29+
let context = CGContext(
30+
data: nil,
31+
width: size,
32+
height: size,
33+
bitsPerComponent: 8,
34+
bytesPerRow: 0,
35+
space: colorSpace,
36+
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue
37+
)
38+
else {
39+
fputs("Could not create icon render context\n", stderr)
40+
exit(70)
41+
}
42+
43+
context.clear(bounds)
44+
45+
let cornerRadius: CGFloat = 224
46+
let roundedRect = CGPath(
47+
roundedRect: bounds,
48+
cornerWidth: cornerRadius,
49+
cornerHeight: cornerRadius,
50+
transform: nil
51+
)
52+
53+
context.saveGState()
54+
context.addPath(roundedRect)
55+
context.clip()
56+
57+
let gradientColors = [
58+
CGColor(red: 0.23193, green: 0.41350, blue: 0.80588, alpha: 1),
59+
CGColor(red: 0.38860, green: 0.77688, blue: 0.96841, alpha: 1),
60+
] as CFArray
61+
62+
if let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: [0, 1]) {
63+
context.drawLinearGradient(
64+
gradient,
65+
start: CGPoint(x: bounds.midX, y: bounds.minY),
66+
end: CGPoint(x: bounds.midX, y: bounds.maxY),
67+
options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]
68+
)
69+
}
70+
71+
context.saveGState()
72+
context.setShadow(
73+
offset: CGSize(width: 0, height: -28),
74+
blur: 26,
75+
color: CGColor(gray: 0, alpha: 0.5)
76+
)
77+
context.setAlpha(0.88)
78+
context.draw(glyph, in: bounds)
79+
context.restoreGState()
80+
81+
context.setFillColor(CGColor(red: 1, green: 1, blue: 1, alpha: 0.16))
82+
context.addPath(roundedRect)
83+
context.fillPath()
84+
85+
context.restoreGState()
86+
87+
guard
88+
let image = context.makeImage(),
89+
let destination = CGImageDestinationCreateWithURL(
90+
outputURL as CFURL,
91+
UTType.png.identifier as CFString,
92+
1,
93+
nil
94+
)
95+
else {
96+
fputs("Could not create rendered icon PNG at \(outputURL.path)\n", stderr)
97+
exit(70)
98+
}
99+
100+
CGImageDestinationAddImage(destination, image, nil)
101+
102+
guard CGImageDestinationFinalize(destination) else {
103+
fputs("Could not write rendered icon to \(outputURL.path)\n", stderr)
104+
exit(73)
105+
}

0 commit comments

Comments
 (0)