Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
push:
branches: [main]
pull_request:

permissions:
contents: read

jobs:
build-and-check:
runs-on: macos-15
steps:
- uses: actions/checkout@v4

- name: Lint build script
run: |
bash -n build.sh
command -v shellcheck >/dev/null 2>&1 || brew install shellcheck
shellcheck -S error build.sh

- name: Validate Info.plist
run: plutil -lint Info.plist

- name: Typecheck make_icon.swift
run: swiftc -typecheck -swift-version 5 -warn-concurrency make_icon.swift

- name: Build and verify app bundle
run: |
./build.sh --build-only
codesign --verify --deep --strict build/TwoUp.app
test -s build/TwoUp.app/Contents/Resources/TwoUp.icns
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build/
.DS_Store
.impeccable/
.claude/
8 changes: 8 additions & 0 deletions Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleInfoDictionaryVersion</key><string>6.0</string>
<key>CFBundleName</key><string>TwoUp</string>
<key>CFBundleDisplayName</key><string>TwoUp</string>
<key>CFBundleIdentifier</key><string>com.mclemore.twoup</string>
Expand All @@ -10,9 +11,16 @@
<key>CFBundlePackageType</key><string>APPL</string>
<key>CFBundleShortVersionString</key><string>1.0</string>
<key>CFBundleVersion</key><string>1</string>
<key>LSApplicationCategoryType</key><string>public.app-category.news</string>
<key>LSMinimumSystemVersion</key><string>13.0</string>
<key>NSHighResolutionCapable</key><true/>
<key>NSHumanReadableCopyright</key><string>Copyright © 2026 Will McLemore</string>
<key>NSPrincipalClass</key><string>NSApplication</string>
<key>NSAppleEventsUsageDescription</key><string>TwoUp reads the article in your browser's current tab.</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
</dict>
</plist>
Binary file removed Resources/TwoUp.icns
Binary file not shown.
72 changes: 54 additions & 18 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,65 @@
#!/bin/zsh
# Builds TwoUp.app and installs it to ~/Applications.
#!/usr/bin/env bash
# Builds TwoUp.app and (unless --build-only is passed) installs it to ~/Applications.
set -euo pipefail
cd "$(dirname "$0")"
APP=build/TwoUp.app
rm -rf build && mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources"

if [[ ! -f Resources/TwoUp.icns ]]; then
swiftc -O make_icon.swift -o build/make_icon
./build/make_icon build/icon.png
mkdir -p build/TwoUp.iconset
for s in 16 32 128 256 512; do
sips -z $s $s build/icon.png --out build/TwoUp.iconset/icon_${s}x${s}.png >/dev/null
sips -z $((s*2)) $((s*2)) build/icon.png --out build/TwoUp.iconset/icon_${s}x${s}@2x.png >/dev/null
done
iconutil -c icns build/TwoUp.iconset -o Resources/TwoUp.icns

BUILD_ONLY=false
while [[ $# -gt 0 ]]; do
case "$1" in
--build-only)
BUILD_ONLY=true
shift
;;
-h|--help)
echo "Usage: ./build.sh [--build-only]"
exit 0
;;
*)
echo "Unknown option: $1" >&2
echo "Usage: ./build.sh [--build-only]" >&2
exit 1
;;
esac
done

cd "$(dirname "${BASH_SOURCE[0]}")"

SIGN_IDENTITY="${SIGN_IDENTITY:--}"
APP="build/TwoUp.app"

plutil -lint Info.plist >/dev/null

rm -rf build/TwoUp.app build/TwoUp.icns build/TwoUp.iconset
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources"

swift make_icon.swift build/TwoUp.icns

SWIFT_SOURCES=(main.swift)
if [[ -f Core.swift ]]; then
SWIFT_SOURCES=(Core.swift main.swift)
fi

swiftc -O -swift-version 5 main.swift -o "$APP/Contents/MacOS/TwoUp" -framework Cocoa -framework WebKit
swiftc -O -swift-version 5 "${SWIFT_SOURCES[@]}" -o "$APP/Contents/MacOS/TwoUp" -framework Cocoa -framework WebKit

cp Info.plist "$APP/Contents/Info.plist"
cp Resources/* "$APP/Contents/Resources/"
codesign --force --sign - "$APP"
cp build/TwoUp.icns "$APP/Contents/Resources/TwoUp.icns"

codesign --force --deep --sign "$SIGN_IDENTITY" "$APP"
codesign --verify --deep --strict "$APP"

if [[ "$BUILD_ONLY" == "true" ]]; then
echo "Built $APP"
exit 0
fi

mkdir -p "$HOME/Applications"
DEST="$HOME/Applications/TwoUp.app"
if [[ -d "$DEST" ]]; then
if command -v trash >/dev/null; then trash "$DEST"; else rm -rf "$DEST"; fi
if command -v trash >/dev/null 2>&1; then
trash "$DEST"
else
rm -rf "$DEST"
fi
fi
cp -R "$APP" "$DEST"
echo "Installed $DEST"
Binary file modified docs/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
158 changes: 139 additions & 19 deletions make_icon.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,143 @@
import Cocoa

// Draws the app icon: an open two-page spread on a dark tile.
let size: CGFloat = 1024
let img = NSImage(size: NSSize(width: size, height: size))
img.lockFocus()
NSColor(calibratedRed: 0.13, green: 0.12, blue: 0.11, alpha: 1).setFill()
NSBezierPath(roundedRect: NSRect(x: 100, y: 100, width: 824, height: 824), xRadius: 185, yRadius: 185).fill()
let paper = NSColor(calibratedRed: 0.98, green: 0.96, blue: 0.91, alpha: 1)
let ink = NSColor(calibratedRed: 0.55, green: 0.52, blue: 0.46, alpha: 1)
for x in [222.0, 522.0] {
paper.setFill()
NSBezierPath(roundedRect: NSRect(x: x, y: 250, width: 280, height: 524), xRadius: 14, yRadius: 14).fill()
ink.setFill()
var y = 690.0
while y > 300 {
let w = (y < 340 && x > 500) ? 120.0 : 216.0
NSBezierPath(roundedRect: NSRect(x: x + 32, y: y, width: w, height: 14), xRadius: 7, yRadius: 7).fill()
y -= 38
enum IconError: LocalizedError {
case bitmapCreationFailed(Int)
case graphicsContextFailed(Int)
case pngEncodingFailed(Int)
case iconutilFailed(Int32, String)

var errorDescription: String? {
switch self {
case .bitmapCreationFailed(let px):
return "Failed to allocate \(px)x\(px) bitmap image rep."
case .graphicsContextFailed(let px):
return "Failed to create graphics context for \(px)x\(px) icon."
case .pngEncodingFailed(let px):
return "Failed to encode \(px)x\(px) icon as PNG."
case .iconutilFailed(let status, let stderr):
return "iconutil failed with exit code \(status)\(stderr.isEmpty ? "" : ": \(stderr)")."
}
}
}
img.unlockFocus()
let rep = NSBitmapImageRep(data: img.tiffRepresentation!)!
try! rep.representation(using: .png, properties: [:])!.write(to: URL(fileURLWithPath: CommandLine.arguments[1]))

func renderIconPNG(pixels px: Int) throws -> Data {
guard let rep = NSBitmapImageRep(
bitmapDataPlanes: nil,
pixelsWide: px,
pixelsHigh: px,
bitsPerSample: 8,
samplesPerPixel: 4,
hasAlpha: true,
isPlanar: false,
colorSpaceName: .calibratedRGB,
bytesPerRow: 0,
bitsPerPixel: 0
) else {
throw IconError.bitmapCreationFailed(px)
}

guard let ctx = NSGraphicsContext(bitmapImageRep: rep) else {
throw IconError.graphicsContextFailed(px)
}

NSGraphicsContext.saveGraphicsState()
NSGraphicsContext.current = ctx
defer { NSGraphicsContext.restoreGraphicsState() }

ctx.shouldAntialias = true
ctx.imageInterpolation = .high
let scale = CGFloat(px) / 1024.0
ctx.cgContext.scaleBy(x: scale, y: scale)

NSColor(calibratedRed: 0.13, green: 0.12, blue: 0.11, alpha: 1).setFill()
NSBezierPath(roundedRect: NSRect(x: 100, y: 100, width: 824, height: 824), xRadius: 185, yRadius: 185).fill()

let paper = NSColor(calibratedRed: 0.98, green: 0.96, blue: 0.91, alpha: 1)
let ink = NSColor(calibratedRed: 0.55, green: 0.52, blue: 0.46, alpha: 1)
for x in [222.0, 522.0] {
paper.setFill()
NSBezierPath(roundedRect: NSRect(x: x, y: 250, width: 280, height: 524), xRadius: 14, yRadius: 14).fill()
ink.setFill()
var y = 690.0
while y > 300 {
let w = (y < 340 && x > 500) ? 120.0 : 216.0
NSBezierPath(roundedRect: NSRect(x: x + 32, y: y, width: w, height: 14), xRadius: 7, yRadius: 7).fill()
y -= 38
}
}

guard let pngData = rep.representation(using: .png, properties: [:]) else {
throw IconError.pngEncodingFailed(px)
}
return pngData
}

func buildICNS(at outputURL: URL) throws {
let fm = FileManager.default
let iconsetURL = fm.temporaryDirectory
.appendingPathComponent("TwoUp-\(ProcessInfo.processInfo.globallyUniqueString).iconset", isDirectory: true)
try fm.createDirectory(at: iconsetURL, withIntermediateDirectories: true)
defer { try? fm.removeItem(at: iconsetURL) }

let sizes: [(name: String, pixels: Int)] = [
("icon_16x16.png", 16),
("icon_16x16@2x.png", 32),
("icon_32x32.png", 32),
("icon_32x32@2x.png", 64),
("icon_128x128.png", 128),
("icon_128x128@2x.png", 256),
("icon_256x256.png", 256),
("icon_256x256@2x.png", 512),
("icon_512x512.png", 512),
("icon_512x512@2x.png", 1024),
]

for entry in sizes {
let data = try renderIconPNG(pixels: entry.pixels)
try data.write(to: iconsetURL.appendingPathComponent(entry.name), options: .atomic)
}

let process = Process()
process.executableURL = URL(fileURLWithPath: "/usr/bin/iconutil")
process.arguments = ["-c", "icns", iconsetURL.path, "-o", outputURL.path]
let stderrPipe = Pipe()
process.standardError = stderrPipe
try process.run()
let stderrData = stderrPipe.fileHandleForReading.readDataToEndOfFile()
process.waitUntilExit()

if process.terminationStatus != 0 {
let message = String(data: stderrData, encoding: .utf8)?
.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
throw IconError.iconutilFailed(process.terminationStatus, message)
}
}

guard CommandLine.arguments.count == 2 else {
fputs("Usage: swift make_icon.swift <output.icns|output.png>\n", stderr)
exit(1)
}

let outputArg = CommandLine.arguments[1]
if outputArg.isEmpty || outputArg == "-h" || outputArg == "--help" {
fputs("Usage: swift make_icon.swift <output.icns|output.png>\n", stderr)
exit(outputArg == "-h" || outputArg == "--help" ? 0 : 1)
}

let outputURL = URL(fileURLWithPath: outputArg)
do {
try FileManager.default.createDirectory(
at: outputURL.deletingLastPathComponent(),
withIntermediateDirectories: true
)
if outputURL.pathExtension.lowercased() == "png" {
let data = try renderIconPNG(pixels: 1024)
try data.write(to: outputURL, options: .atomic)
} else {
try buildICNS(at: outputURL)
}
} catch {
fputs("make_icon.swift: \(error.localizedDescription)\n", stderr)
exit(1)
}
Loading