commit a8bb9785d28fe7c4703d8707e62bfdc4dc11b8b9
parent 324c6e87242c2ce0caea9e5d9161255d9fba3b1e
Author: Michael Camilleri <[email protected]>
Date: Fri, 23 Oct 2026 11:33:20 +0900
Refine script to generate marketing screenshots
Diffstat
| M | Reportage/Services/DemoSeed.swift | | | 158 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- |
| M | Reportage/Views/Home/HomeView.swift | | | 10 | +++++++++- |
| M | Reportage/Views/RootView.swift | | | 2 | +- |
| M | Scripts/demo-simulator.sh | | | 5 | +++-- |
| A | Scripts/screenshots-iphone-compose.swift | | | 114 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | Scripts/screenshots-marketing.sh | | | 90 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 files changed, 361 insertions(+), 18 deletions(-)
diff --git a/Reportage/Services/DemoSeed.swift b/Reportage/Services/DemoSeed.swift
@@ -12,6 +12,29 @@ enum DemoSeed {
static let isActive = false
#endif
+ /// A screen the demo opens to, for `Scripts/screenshots-marketing.sh`.
+ enum Screen: String {
+ case timeline
+ /// The afternoon's report, opened from the timeline.
+ case detail
+ case charts
+ /// A new manual report's survey.
+ case survey
+ }
+
+ /// The screen named by `--reportage-demo-screen <name>`; the timeline
+ /// without it, or outside the demo.
+ static let screen: Screen = {
+ let arguments = ProcessInfo.processInfo.arguments
+ guard isActive, let index = arguments.firstIndex(of: "--reportage-demo-screen"),
+ arguments.indices.contains(index + 1)
+ else { return .timeline }
+ return Screen(rawValue: arguments[index + 1]) ?? .timeline
+ }()
+
+ /// The report the detail screen opens: the last one seeded.
+ static let detailReportID = UUID(uuidString: "DE000000-0000-4000-8000-000000000006")!
+
#if DEBUG
/// Adds the reports, dated today and yesterday, after the default
/// questions have been seeded. Their answers use the default questions.
@@ -36,24 +59,38 @@ enum DemoSeed {
place: place.map { PlaceDetails(coordinate: $0) }, narrativeForm: form, modifiedAt: now)
}
- let home = Coordinate(latitude: 35.6950, longitude: 139.6290)
- let park = Coordinate(latitude: 35.7017, longitude: 139.6153)
+ let home = Coordinate(latitude: 53.3866, longitude: -2.9185)
+ let park = Coordinate(latitude: 53.38133, longitude: -2.93534)
+ let cavern = Coordinate(latitude: 53.4064, longitude: -2.9876)
+ let strawberry = Coordinate(latitude: 53.3889, longitude: -2.8869)
let tokens = [
token("demo-doors", "activity", "Opening up the doors"),
token("demo-ground", "activity", "Getting my feet back on the ground"),
token("demo-cooking", "activity", "Cooking"),
token("demo-home", "location", "Home", form: "home", place: home),
- token("demo-park", "location", "Zenpukuji Park", form: "the park", place: park),
+ token("demo-park", "location", "Sefton Park", form: "the park", place: park),
token("demo-alex", "people", "Alex"),
token("demo-paul", "people", "Paul"),
+ // Used only by the history.
+ token("demo-rehearsing", "activity", "Rehearsing"),
+ token("demo-writing", "activity", "Writing songs"),
+ token("demo-recording", "activity", "Recording"),
+ token("demo-reading", "activity", "Reading"),
+ token("demo-walking", "activity", "Walking"),
+ token("demo-cavern", "location", "The Cavern", form: "the Cavern", place: cavern),
+ token(
+ "demo-strawberry", "location", "Strawberry Field", form: "Strawberry Field", place: strawberry),
+ token("demo-john", "people", "John"),
+ token("demo-george", "people", "George"),
+ token("demo-ringo", "people", "Ringo"),
]
func context(_ coordinate: Coordinate, _ temperature: Double, _ condition: String) -> Context {
var placemark = Placemark()
- placemark.locality = "Suginami"
- placemark.administrativeArea = "Tokyo"
- placemark.countryCode = "JP"
- placemark.cityWithContext = "Suginami, Tokyo"
+ placemark.locality = "Liverpool"
+ placemark.administrativeArea = "England"
+ placemark.countryCode = "GB"
+ placemark.cityWithContext = "Liverpool, England"
return Context(
location: LocationContext(coordinate: coordinate, placemark: placemark),
weather: WeatherContext(source: .weatherKit, condition: condition, temperature: temperature))
@@ -108,20 +145,20 @@ enum DemoSeed {
answer("coffee", .number(2)),
answer("learned", .text("Ginkgo trees are older than the dinosaurs")),
],
- context(home, 14, "Clear")),
+ context(home, 10, "Cloudy")),
steps(9_412)
),
(
answered(
at(-1, 18, 21), .random, doing: ["demo-cooking"], at: "demo-home", home, with: ["demo-alex"],
- working: false, mood: "Good", 17, "Mostly Clear"),
+ working: false, mood: "Good", 12, "Mostly Cloudy"),
steps(8_730)
),
- (report(wake, .wake, [answer("sleep-quality", .options(["Well"]))], context(home, 12, "Clear")), night),
+ (report(wake, .wake, [answer("sleep-quality", .options(["Well"]))], context(home, 8, "Drizzle")), night),
(
answered(
at(0, 9, 37), .random, doing: ["demo-doors"], at: "demo-home", home, with: [],
- working: true, mood: "Not so self-assured", 15, "Partly Cloudy"),
+ working: true, mood: "Not so self-assured", 11, "Cloudy"),
steps(2_140)
),
// An Instant Report from a prompt: context and no answers.
@@ -129,21 +166,114 @@ enum DemoSeed {
Report(
id: reportID(), date: at(0, 13, 4), timeZone: TimeZone.current.identifier, kind: .random,
trigger: .notification, state: .passive, promptedAt: at(0, 13, 4),
- context: context(park, 19, "Partly Cloudy"), modifiedAt: now),
+ context: context(park, 14, "Partly Cloudy"), modifiedAt: now),
steps(6_318)
),
+ // The detail screen's report, `detailReportID`.
(
answered(
at(0, 15, 52), .manual, doing: ["demo-ground"], at: "demo-park", park, with: ["demo-paul"],
- working: false, mood: "Appreciative", 18, "Cloudy"),
+ working: false, mood: "Appreciative", 13, "Cloudy"),
steps(7_905)
),
]
- for (index, (report, health)) in reports.enumerated() {
+ let history = Self.history(
+ at: at, coordinates: ["demo-home": home, "demo-park": park, "demo-cavern": cavern,
+ "demo-strawberry": strawberry],
+ report: report, answered: answered, answer: answer, context: context, steps: steps)
+ for (index, (report, health)) in (reports + history).enumerated() {
try await store.insert(report, newTokens: index == 0 ? tokens : [])
// Settled, so the Health filler leaves it as it is.
try await store.setHealth(HealthRecord(health: health, derivedAt: now, isSettled: true), for: report.id)
}
}
+
+ /// Four weeks of reports before yesterday, so the charts have something
+ /// to show: a wake and bedtime report each day and a few prompted ones
+ /// between, working at the Cavern on weekdays. The answers come from a
+ /// generator with a fixed seed, so every launch seeds the same history.
+ private static func history(
+ at: (Int, Int, Int) -> Date,
+ coordinates: [String: Coordinate],
+ report: (Date, ReportKind, [Response], Context) -> Report,
+ answered: (
+ Date, ReportKind, [String], String, Coordinate, [String], Bool, String, Double, String
+ ) -> Report,
+ answer: (String, ResponseValue?) -> Response,
+ context: (Coordinate, Double, String) -> Context,
+ steps: (Int) -> HealthContext
+ ) -> [(Report, HealthContext)] {
+ var generator = SeededGenerator(seed: 1965)
+ func pick<T>(_ items: [T]) -> T { items.randomElement(using: &generator)! }
+ func roll(_ range: ClosedRange<Int>) -> Int { Int.random(in: range, using: &generator) }
+
+ let home = coordinates["demo-home"]!
+ let conditions = ["Cloudy", "Cloudy", "Mostly Cloudy", "Partly Cloudy", "Drizzle", "Rain", "Clear"]
+ // Weighted towards the better moods.
+ let moods = ["Great", "Good", "Good", "Good", "Okay", "Okay", "Bad"]
+ let band = ["demo-john", "demo-george", "demo-ringo", "demo-paul"]
+
+ var history: [(Report, HealthContext)] = []
+ for day in (-29)...(-2) {
+ let weekday = Calendar.current.component(.weekday, from: at(day, 12, 0))
+ let isWorkday = (2...6).contains(weekday)
+ let base = Double(roll(7...13))
+
+ let wake = at(day, roll(6...7), roll(0...59))
+ let asleep = roll(330...500) * 60
+ let quality = asleep >= 7 * 3600 ? "Well" : asleep >= 6 * 3600 ? "Okay" : "Poorly"
+ let night = HealthContext(
+ sleep: SleepHealth(
+ start: wake.addingTimeInterval(-Double(asleep + roll(5...40) * 60)), end: wake,
+ asleep: TimeInterval(asleep)))
+ history.append((
+ report(wake, .wake, [answer("sleep-quality", .options([quality]))], context(home, base - 2, pick(conditions))),
+ night
+ ))
+
+ var hours = Array(Set((0..<roll(2...3)).map { _ in roll(9...21) })).sorted()
+ if hours.isEmpty { hours = [12] }
+ for hour in hours {
+ let isWorking = isWorkday && (10...17).contains(hour)
+ let doing: [String]
+ let place: String
+ let people: [String]
+ if isWorking {
+ doing = [pick(["demo-rehearsing", "demo-rehearsing", "demo-writing", "demo-recording"])]
+ place = "demo-cavern"
+ people = Array(band.shuffled(using: &generator).prefix(roll(1...3)))
+ } else if hour < 10 {
+ doing = [pick(["demo-doors", "demo-reading", "demo-cooking"])]
+ place = "demo-home"
+ people = []
+ } else {
+ let outing = pick(["demo-walking", "demo-ground", "demo-cooking", "demo-reading", "demo-writing"])
+ doing = [outing]
+ switch outing {
+ case "demo-walking": place = pick(["demo-park", "demo-strawberry"])
+ case "demo-ground": place = "demo-park"
+ default: place = "demo-home"
+ }
+ people = roll(0...2) == 0 ? [] : [pick(["demo-alex", "demo-paul", "demo-alex"])]
+ }
+ let date = at(day, hour, roll(0...59))
+ history.append((
+ answered(
+ date, .random, doing, place, coordinates[place]!, people, isWorking, pick(moods),
+ base + Double(min(hour, 15) - 9) / 2, pick(conditions)),
+ steps(hour * roll(450...750))
+ ))
+ }
+
+ let bedtime = at(day, roll(22...23), roll(0...59))
+ history.append((
+ report(
+ bedtime, .bedtime, [answer("coffee", .number(Decimal(isWorkday ? roll(1...4) : roll(0...2))))],
+ context(home, base - 3, pick(conditions))),
+ steps(roll(4_000...13_000))
+ ))
+ }
+ return history
+ }
#endif
}
diff --git a/Reportage/Views/Home/HomeView.swift b/Reportage/Views/Home/HomeView.swift
@@ -11,7 +11,8 @@ struct HomeView: View {
@State private var survey: SurveyRequest?
@State private var describer = ReportDescriber()
/// The reports opened from the timeline.
- @State private var path: [ReportRoute] = []
+ @State private var path: [ReportRoute] =
+ DemoSeed.screen == .detail ? [ReportRoute(id: DemoSeed.detailReportID)] : []
private let logger = Logger(subsystem: "net.inqk.reportage", category: "Home")
@@ -44,6 +45,13 @@ struct HomeView: View {
.task {
for await _ in NotificationCenter.default.notifications(named: .summaryLookupChanged) {
await describer.load(from: store)
+ // The demo's survey opens once its reports are seeded, so
+ // their answers are suggested, at 9:41 to match the status
+ // bar.
+ if DemoSeed.screen == .survey, survey == nil {
+ let date = Calendar.current.date(bySettingHour: 9, minute: 41, second: 0, of: Date()) ?? Date()
+ survey = SurveyRequest(kind: .manual, date: date)
+ }
}
}
}
diff --git a/Reportage/Views/RootView.swift b/Reportage/Views/RootView.swift
@@ -3,7 +3,7 @@ import SwiftUI
/// The app's tabs: the timeline, charts and Settings.
struct RootView: View {
@Environment(PromptInbox.self) private var inbox: PromptInbox?
- @State private var tab = RootTab.timeline
+ @State private var tab = DemoSeed.screen == .charts ? RootTab.charts : .timeline
@State private var isWelcoming = false
var body: some View {
diff --git a/Scripts/demo-simulator.sh b/Scripts/demo-simulator.sh
@@ -64,8 +64,9 @@ demo_install() {
}
# Launches the app with the demo seed, in Australian English so temperatures
-# are in Celsius.
+# are in Celsius. Any arguments are passed to the app as extra launch
+# arguments.
demo_launch() {
xcrun simctl launch --terminate-running-process "$UDID" "$BUNDLE_ID" \
- --reportage-seed-demo -AppleLanguages "(en-AU)" -AppleLocale en_AU
+ --reportage-seed-demo -AppleLanguages "(en-AU)" -AppleLocale en_AU "$@"
}
diff --git a/Scripts/screenshots-iphone-compose.swift b/Scripts/screenshots-iphone-compose.swift
@@ -0,0 +1,114 @@
+#!/usr/bin/env swift
+
+import AppKit
+import CoreGraphics
+import CoreText
+import Foundation
+import ImageIO
+
+guard CommandLine.arguments.count >= 4 else {
+ fputs("Usage: screenshots-iphone-compose.swift <framed.png> <output.png> <caption>\n", stderr)
+ exit(1)
+}
+
+let inputPath = CommandLine.arguments[1]
+let outputPath = CommandLine.arguments[2]
+let text = CommandLine.arguments[3]
+
+// The App Store's 6.9" iPhone size, which also covers the smaller sizes.
+let canvasWidth: CGFloat = 1320
+let canvasHeight: CGFloat = 2868
+
+// Theme.paper and Theme.ink in light mode.
+let backgroundColor = CGColor(red: 0xF5 / 255.0, green: 0xF0 / 255.0, blue: 0xE4 / 255.0, alpha: 1)
+let textColor = NSColor(calibratedRed: 0x1B / 255.0, green: 0x1C / 255.0, blue: 0x1F / 255.0, alpha: 1)
+
+guard let dataProvider = CGDataProvider(filename: inputPath),
+ let deviceImage = CGImage(
+ pngDataProviderSource: dataProvider,
+ decode: nil,
+ shouldInterpolate: true,
+ intent: .defaultIntent
+ )
+else {
+ fputs("Failed to load image: \(inputPath)\n", stderr)
+ exit(1)
+}
+
+let deviceWidth = CGFloat(deviceImage.width)
+let deviceHeight = CGFloat(deviceImage.height)
+
+guard
+ let context = CGContext(
+ data: nil,
+ width: Int(canvasWidth),
+ height: Int(canvasHeight),
+ bitsPerComponent: 8,
+ bytesPerRow: 0,
+ space: CGColorSpaceCreateDeviceRGB(),
+ bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue
+ )
+else {
+ fputs("Failed to create graphics context\n", stderr)
+ exit(1)
+}
+
+context.setFillColor(backgroundColor)
+context.fill(CGRect(x: 0, y: 0, width: canvasWidth, height: canvasHeight))
+
+let sidePadding: CGFloat = 70
+let bottomPadding: CGFloat = 80
+let topReserved: CGFloat = 330
+let maxDeviceWidth = canvasWidth - sidePadding * 2
+let maxDeviceHeight = canvasHeight - bottomPadding - topReserved
+let scale = min(maxDeviceWidth / deviceWidth, maxDeviceHeight / deviceHeight, 1.0)
+let scaledWidth = deviceWidth * scale
+let scaledHeight = deviceHeight * scale
+let deviceX = (canvasWidth - scaledWidth) / 2
+let deviceY = bottomPadding
+
+context.interpolationQuality = .high
+context.draw(
+ deviceImage,
+ in: CGRect(x: deviceX, y: deviceY, width: scaledWidth, height: scaledHeight)
+)
+
+// The serif design matches the app's titles (Theme.serif).
+let fontSize = canvasWidth * 0.066
+let baseFont = NSFont.systemFont(ofSize: fontSize, weight: .medium)
+let font =
+ baseFont.fontDescriptor.withDesign(.serif).flatMap { NSFont(descriptor: $0, size: fontSize) }
+ ?? baseFont
+let attributes: [NSAttributedString.Key: Any] = [
+ .font: font,
+ .foregroundColor: textColor,
+]
+let attrString = NSAttributedString(string: text, attributes: attributes)
+let ctLine = CTLineCreateWithAttributedString(attrString)
+let textBounds = CTLineGetBoundsWithOptions(ctLine, .useOpticalBounds)
+
+let textAreaTop = canvasHeight - 40
+let textAreaBottom = deviceY + scaledHeight
+let textX = (canvasWidth - textBounds.width) / 2 - textBounds.origin.x
+let textY = (textAreaTop + textAreaBottom) / 2 - textBounds.height / 2 - textBounds.origin.y
+
+context.textPosition = CGPoint(x: textX, y: textY)
+CTLineDraw(ctLine, context)
+
+guard let resultImage = context.makeImage(),
+ let destination = CGImageDestinationCreateWithURL(
+ URL(fileURLWithPath: outputPath) as CFURL,
+ "public.png" as CFString,
+ 1,
+ nil
+ )
+else {
+ fputs("Failed to create output\n", stderr)
+ exit(1)
+}
+
+CGImageDestinationAddImage(destination, resultImage, nil)
+guard CGImageDestinationFinalize(destination) else {
+ fputs("Failed to write output\n", stderr)
+ exit(1)
+}
diff --git a/Scripts/screenshots-marketing.sh b/Scripts/screenshots-marketing.sh
@@ -0,0 +1,90 @@
+#!/bin/bash
+# Takes the App Store screenshots on the demo simulator and frames them: each
+# scene is captured with the status bar at 9:41, given a Dynamic Island,
+# framed in a device by the "Frame Screenshots" Shortcut and captioned on a
+# 1320x2868 canvas. -n skips the Dynamic Island; the current frame draws its
+# own, so use -n unless the frame changes to one without it.
+#
+# Usage: bash Scripts/screenshots-marketing.sh [-n] [iOS-major]
+# (default major 27; output Marketing/iphone_<n>.png)
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+REPO_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
+source "${SCRIPT_DIR}/demo-simulator.sh"
+
+ADD_DYNAMIC_ISLAND=true
+while getopts "n" opt; do
+ case $opt in
+ n) ADD_DYNAMIC_ISLAND=false ;;
+ *) exit 1 ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+if ! shortcuts list | grep -qx "Frame Screenshots"; then
+ echo "The 'Frame Screenshots' Shortcut isn't installed." >&2
+ exit 1
+fi
+
+WORK_DIR="/tmp/reportage-marketing"
+MARKETING_DIR="${REPO_DIR}/Marketing"
+
+# Each scene is a screen the demo opens to (DemoSeed.Screen).
+SCENES=(timeline detail charts survey)
+CAPTIONS=(
+ "Record Your Life."
+ "See Every Detail."
+ "Made to Measure."
+ "File in Seconds."
+)
+
+rm -rf "$WORK_DIR"
+mkdir -p "$WORK_DIR" "$MARKETING_DIR"
+
+demo_simulator "${1:-27}"
+xcrun simctl ui "$UDID" appearance light
+xcrun simctl status_bar "$UDID" override \
+ --time "9:41" \
+ --batteryState discharging \
+ --batteryLevel 100 \
+ --wifiBars 3 \
+ --cellularBars 4 \
+ --cellularMode active \
+ --dataNetwork wifi
+echo "Status bar overridden"
+
+demo_install
+
+for index in "${!SCENES[@]}"; do
+ scene="${SCENES[$index]}"
+ caption="${CAPTIONS[$index]}"
+ raw_path="${WORK_DIR}/${scene}.png"
+ island_path="${WORK_DIR}/${scene}-island.png"
+ framed_path="${WORK_DIR}/${scene}-framed.png"
+ output_path="${MARKETING_DIR}/iphone_${index}.png"
+
+ echo ""
+ echo "Capturing iphone_${index}.png - ${caption}"
+ demo_launch --reportage-demo-screen "$scene"
+ # Time for the seed to fill the store and the scene to draw it.
+ sleep 4
+ xcrun simctl io "$UDID" screenshot --mask ignored "$raw_path"
+
+ frame_input="$raw_path"
+ if [ "$ADD_DYNAMIC_ISLAND" = true ]; then
+ swift "${SCRIPT_DIR}/screenshots-iphone-island.swift" "$raw_path" "$island_path"
+ frame_input="$island_path"
+ fi
+
+ shortcuts run "Frame Screenshots" -i "$frame_input" -o "$framed_path"
+ swift "${SCRIPT_DIR}/screenshots-iphone-compose.swift" "$framed_path" "$output_path" "$caption"
+ ls -la "$output_path"
+done
+
+xcrun simctl status_bar "$UDID" clear 2>/dev/null || true
+rm -rf "$WORK_DIR"
+
+echo ""
+echo "Screenshots saved to ${MARKETING_DIR}/"
+ls -la "${MARKETING_DIR}/iphone_"*.png