commit c73ad2240a5d8dd12ef2fe4d0c34e59b3636a346
parent 81eff77b47a006cee731d20991e4dcd5949dde9e
Author: Michael Camilleri <[email protected]>
Date: Tue, 20 Oct 2026 12:15:35 +0900
Provide feedback during OTA deployment
Diffstat
| M | Reportage/Info.plist | | | 11 | +++++++++++ |
| M | Scripts/deploy-ota.sh | | | 58 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- |
| M | Scripts/ota-server.swift | | | 49 | +++++++++++++++++++++++++++++++++++++++++++++---- |
| M | project.yml | | | 5 | +++++ |
4 files changed, 117 insertions(+), 6 deletions(-)
diff --git a/Reportage/Info.plist b/Reportage/Info.plist
@@ -22,6 +22,17 @@ <string>APPL</string> <key>CFBundleShortVersionString</key> <string>1.0.0</string> + <key>CFBundleURLTypes</key> + <array> + <dict> + <key>CFBundleURLName</key> + <string>net.inqk.reportage</string> + <key>CFBundleURLSchemes</key> + <array> + <string>reportage</string> + </array> + </dict> + </array> <key>CFBundleVersion</key> <string>$(CURRENT_PROJECT_VERSION)</string> <key>ITSAppUsesNonExemptEncryption</key>
diff --git a/Scripts/deploy-ota.sh b/Scripts/deploy-ota.sh
@@ -136,12 +136,66 @@ cat > "${SITE}/index.html" <<EOF
body { font: -apple-system-body; font-family: -apple-system, sans-serif; margin: 3em 1.5em; text-align: center; }
a { display: inline-block; padding: 0.8em 1.6em; border-radius: 0.6em; background: #007aff; color: #fff; text-decoration: none; font-weight: 600; }
p { color: #888; }
+ [hidden] { display: none !important; }
+ #progress { display: flex; align-items: center; justify-content: center; gap: 0.6em; margin-top: 1.5em; color: #888; }
+ .spinner { width: 1em; height: 1em; border: 2px solid #ccc; border-top-color: #007aff; border-radius: 50%; animation: spin 0.8s linear infinite; }
+ @keyframes spin { to { transform: rotate(360deg); } }
</style>
</head>
<body>
<h1>Reportage</h1>
<p>${VERSION} (${BUILD})</p>
-<a href="${INSTALL_URL}">Install</a>
+<a id="install" href="${INSTALL_URL}">Install</a>
+<div id="progress" hidden><span class="spinner"></span><span id="message"></span></div>
+<a id="open" href="reportage://" hidden>Open Reportage</a>
+<p id="note" hidden>If Reportage doesn't open, wait for its Home Screen icon to finish installing.</p>
+<script>
+ // ota-server.swift reports how far the install has got; iOS doesn't say
+ // when installing finishes, so the Open link appears after a delay.
+ const messages = {
+ confirming: "Confirm the install in the alert",
+ downloading: "Downloading…",
+ installing: "Installing…",
+ };
+ const element = (id) => document.getElementById(id);
+ let tapped = false;
+
+ function show(stage) {
+ // The alert might have been cancelled, so Install stays until the
+ // download starts.
+ element("install").hidden = stage !== "confirming";
+ element("progress").hidden = false;
+ element("message").textContent = messages[stage];
+ }
+
+ function reveal() {
+ element("progress").hidden = true;
+ element("open").hidden = false;
+ element("note").hidden = false;
+ }
+
+ element("install").addEventListener("click", () => {
+ tapped = true;
+ show("confirming");
+ });
+
+ async function poll() {
+ try {
+ const response = await fetch("/status", { cache: "no-store" });
+ const { stage } = await response.json();
+ if (stage === "installing") {
+ // The server shuts down soon after this, so polling stops here.
+ show(stage);
+ setTimeout(reveal, 8000);
+ return;
+ }
+ if (stage !== "waiting") show(stage);
+ else if (tapped) show("confirming");
+ } catch {}
+ setTimeout(poll, 1000);
+ }
+ poll();
+</script>
</body>
</html>
EOF
@@ -156,7 +210,7 @@ trap cleanup EXIT
echo
echo "==> Reportage ${VERSION} (${BUILD})"
echo " Open ${BASE_URL}/ in Safari on the iPhone and tap Install."
-echo " Serving stops once the IPA has been downloaded (or on Ctrl-C)."
+echo " Serving stops shortly after the IPA has been downloaded (or on Ctrl-C)."
echo
xcrun swift Scripts/ota-server.swift "$SITE" "$PORT"
diff --git a/Scripts/ota-server.swift b/Scripts/ota-server.swift
@@ -1,5 +1,5 @@
// Serves the OTA install site on 127.0.0.1 for deploy-ota.sh and exits once
-// the IPA has been sent in full.
+// the IPA has been sent in full and the page has been told so.
//
// Usage: swift Scripts/ota-server.swift <site-dir> <port>
import Foundation
@@ -20,6 +20,24 @@ let contentTypes = [
"Reportage.ipa": "application/octet-stream",
]
+// Install progress, reported to the page through /status. The phone fetches
+// the manifest when Install is tapped and the IPA once the alert is
+// confirmed; iOS installs the app after the IPA has been sent, but nothing
+// reports when that finishes.
+enum Stage: String {
+ case waiting, confirming, downloading, installing
+}
+nonisolated(unsafe) var stage = Stage.waiting
+
+// Exit once Tailscale has had time to relay the IPA and the page has seen the
+// installing stage, so it doesn't lose /status partway through.
+nonisolated(unsafe) var relayed = false
+nonisolated(unsafe) var reported = false
+
+func exitIfDone() {
+ if relayed && reported { exit(0) }
+}
+
func log(_ message: String) {
let time = Date.now.formatted(.dateTime.hour(.twoDigits(amPM: .omitted)).minute().second())
print(" \(time) \(message)")
@@ -43,6 +61,10 @@ func respond(on connection: NWConnection, to request: String) {
if method != "GET" && method != "HEAD" {
status = "405 Method Not Allowed"
body = Data("Method not allowed\n".utf8)
+ } else if name == "status" {
+ status = "200 OK"
+ contentType = "application/json"
+ body = Data(#"{"stage":"\#(stage.rawValue)"}"#.utf8)
} else if let type = contentTypes[name],
let data = try? Data(contentsOf: site.appendingPathComponent(name)) {
status = "200 OK"
@@ -50,21 +72,40 @@ func respond(on connection: NWConnection, to request: String) {
body = data
}
+ if method == "GET" && status.hasPrefix("200") {
+ if name == "manifest.plist" && stage == .waiting { stage = .confirming }
+ if name == "Reportage.ipa" { stage = .downloading }
+ }
+
let head = "HTTP/1.1 \(status)\r\n"
+ "Content-Type: \(contentType)\r\n"
+ + "Cache-Control: no-store\r\n"
+ "Content-Length: \(body.count)\r\n"
+ "Connection: close\r\n\r\n"
var payload = Data(head.utf8)
if method != "HEAD" { payload.append(body) }
- log("\(method) \(path) \(status.prefix(3))")
+ // The page polls /status every second; logging each poll is noise.
+ if name != "status" { log("\(method) \(path) \(status.prefix(3))") }
+ let reportedStage = stage
connection.send(content: payload, completion: .contentProcessed { error in
connection.cancel()
- guard error == nil, method == "GET", name == "Reportage.ipa", status.hasPrefix("200") else { return }
+ guard error == nil, method == "GET", status.hasPrefix("200") else { return }
+ if name == "status" && reportedStage == .installing {
+ reported = true
+ exitIfDone()
+ }
+ guard name == "Reportage.ipa" else { return }
+ stage = .installing
print("==> IPA downloaded; shutting down")
fflush(stdout)
// Give Tailscale a moment to finish relaying the IPA to the phone.
- DispatchQueue.main.asyncAfter(deadline: .now() + 5) { exit(0) }
+ DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
+ relayed = true
+ exitIfDone()
+ }
+ // Don't wait on a page that has stopped polling.
+ DispatchQueue.main.asyncAfter(deadline: .now() + 60) { exit(0) }
})
}
diff --git a/project.yml b/project.yml
@@ -35,6 +35,11 @@ targets:
- net.inqk.reportage.prompts
CFBundleDisplayName: Reportage
CFBundleShortVersionString: "1.0.0"
+ # Lets the OTA install page open the app once it is installed.
+ CFBundleURLTypes:
+ - CFBundleURLName: net.inqk.reportage
+ CFBundleURLSchemes:
+ - reportage
CFBundleVersion: $(CURRENT_PROJECT_VERSION)
ITSAppUsesNonExemptEncryption: false
LSRequiresIPhoneOS: true