Skip to content

The agent that grows with you

feat(desktop-update): native status panel when no Chromium renderer exists

ethernet2f0ed3780be7
diff --git a/scripts/desktop-update/posix.sh b/scripts/desktop-update/posix.sh
index b1028c82835..a96078977fb 100755
--- a/scripts/desktop-update/posix.sh
+++ b/scripts/desktop-update/posix.sh
@@ -83,7 +83,7 @@ RESULT="$HERMES_HOME/.hermes-update-result.json"
STATUS="${TMPDIR:-/tmp}/hermes-update-status.$$"
STARTED_AT="$(date +%s)" # the shim's elapsed clock; see serve-ui.py
-UI_SERVER_PID="" UI_BROWSER_PID="" UI_PROFILE_DIR="" FINAL_CODE=1
+UI_SERVER_PID="" UI_BROWSER_PID="" UI_PANEL_PID="" UI_PROFILE_DIR="" FINAL_CODE=1
FINAL_MSG="update did not complete"
DONE_NOTE="" # set when the update succeeded but the app will NOT reopen itself
@@ -244,6 +244,21 @@ for entry in data.get("LSHandlers", []):
esac
}
+start_status_panel() { # the macOS no-browser shim: osascript AppKit panel.
+ # Best-effort by design: osascript missing or the panel exiting instantly
+ # (syntax, headless session) just means no UI, exactly as before. The panel
+ # polls $STATUS itself and self-exits after a terminal state, so this pid
+ # only needs killing on OUR early teardown paths.
+ local py="$1" panel="$SCRIPT_DIR/update-panel.applescript"
+ [ -n "$py" ] || py="/usr/bin/python3" # unused by osascript; keeps the wrapper shape
+ "$py" -c 'import os, signal, sys; os.setsid(); signal.signal(signal.SIGTERM, signal.SIG_IGN); os.execv(sys.argv[1], sys.argv[1:])' \
+ /usr/bin/osascript "$panel" "$STATUS" >>"$LOG" 2>&1 &
+ UI_PANEL_PID=$!
+ sleep 1
+ kill -0 "$UI_PANEL_PID" 2>/dev/null || { UI_PANEL_PID=""; return; }
+ log "shim: status panel pid=$UI_PANEL_PID"
+}
+
start_ui() {
[ "$NO_UI" -eq 1 ] && return
local html="$SCRIPT_DIR/ui.html" py browser port="" i
@@ -254,6 +269,14 @@ start_ui() {
log "shim: default browser is not Chromium-family; skipping UI window"
browser=""
fi
+ if [ "$(uname)" = "Darwin" ] && [ -z "$browser" ] && [ -x "$SCRIPT_DIR/update-panel.applescript" ]; then
+ # No Chromium renderer may host ui.html (Safari/Firefox default, or no
+ # Chrome): draw the same progress as a native panel instead. Reads the
+ # same $STATUS JSON — no server, no browser, no other-app scripting.
+ start_status_panel "$py"
+ [ -n "$UI_PANEL_PID" ] && return
+ log "shim: status panel did not start; continuing without UI"
+ fi
{ [ -f "$html" ] && [ -n "$py" ] && [ -n "$browser" ]; } || { log "shim: no renderer; skipping UI"; return; }
UI_PROFILE_DIR="$(mktemp -d "${TMPDIR:-/tmp}/hermes-update-ui-XXXXXXXX")" || {
@@ -306,6 +329,12 @@ stop_ui() { # error/manual outcomes keep the window up briefly so a watching
if [ -n "$UI_BROWSER_PID" ]; then
{ kill "$UI_BROWSER_PID" && wait "$UI_BROWSER_PID"; } 2>/dev/null
fi
+ if [ -n "$UI_PANEL_PID" ]; then
+ # The panel ignores TERM (SIG_IGN survives execv, same contract as the
+ # HTTP server) — KILL is its off switch. leave-window grace is the panel's
+ # own delay terminal-state sleep, so we just end it.
+ { kill -9 "$UI_PANEL_PID" && wait "$UI_PANEL_PID"; } 2>/dev/null
+ fi
if [ -n "$UI_PROFILE_DIR" ]; then
rm -rf "$UI_PROFILE_DIR" 2>/dev/null || true
UI_PROFILE_DIR=""
diff --git a/scripts/desktop-update/update-panel.applescript b/scripts/desktop-update/update-panel.applescript
new file mode 100644
index 00000000000..8aefcdd5050
--- /dev/null
+++ b/scripts/desktop-update/update-panel.applescript
@@ -0,0 +1,102 @@
+# update-panel.applescript — the renderer-free macOS shim.
+#
+# When no Chromium-family browser may host ui.html (Safari/Firefox default, or
+# no Chrome installed), this draws the same progress as a tiny native panel:
+# an AppKit window whose label polls the SAME status file serve-ui.py's HTTP
+# page reads (write_status JSON: {"status":..,"message":..}). No network, no
+# browser, and no scripting of other apps, so no TCC automation prompt —
+# AppKit is driven in-process under /usr/bin/osascript.
+#
+# Lifecycle mirrors the browser shim: poll until a terminal status, then linger
+# (stop_ui leave-window sleeps 15s before killing us on manual/error; "done"
+# tears down immediately, so exit on our own shortly after). A closed window
+# ends the process — the user is allowed to dismiss us.
+#
+# /usr/bin/osascript update-panel.applescript <status-file>
+#
+# Must remain here, next to posix.sh: the desktop spawns this directory as-is
+# (see resolvePosixScriptHandoff) and the script references it via $SCRIPT_DIR.
+
+use framework "Foundation"
+use framework "AppKit"
+use scripting additions
+
+on run argv
+ if (count of argv) < 1 then error "usage: osascript update-panel.applescript <status-file>"
+ set statusFile to (item 1 of argv as text)
+
+ set nsapp to current application's NSApplication's sharedApplication()
+ # Accessory: no Dock icon — this is a status panel, not an app.
+ nsapp's setActivationPolicy:(current application's NSApplicationActivationPolicyAccessory)
+
+ set win to current application's NSWindow's alloc()'s initWithContentRect:(current application's NSMakeRect(0, 0, 340, 110)) styleMask:3 backing:(current application's NSBackingStoreBuffered) defer:(current application's NSNumber's numberWithBool:true)
+ win's setTitle:"Hermes update"
+ win's |center|()
+ win's setReleasedWhenClosed:(current application's NSNumber's numberWithBool:false)
+
+ set label to current application's NSTextField's wrappingLabelWithString:"Preparing update…"
+ label's setFrameSize:(current application's NSMakeSize(316, 50))
+ label's setFrameOrigin:(current application's NSMakePoint(12, 46))
+ label's setEditable:(current application's NSNumber's numberWithBool:false)
+ label's setBordered:(current application's NSNumber's numberWithBool:false)
+ label's setDrawsBackground:(current application's NSNumber's numberWithBool:false)
+ label's setFont:(current application's NSFont's systemFontOfSize:(13))
+
+ set bar to current application's NSProgressIndicator's alloc()'s initWithFrame:(current application's NSMakeRect(12, 14, 316, 16))
+ bar's setIndeterminate:(current application's NSNumber's numberWithBool:true)
+ bar's startAnimation:(missing value)
+
+ set content to win's contentView()
+ content's addSubview:label
+ content's addSubview:bar
+ win's makeKeyAndOrderFront:(missing value)
+ nsapp's activateIgnoringOtherApps:(true)
+
+ set state to "running"
+ repeat
+ set stPair to my readStatus(statusFile)
+ if stPair is not missing value then
+ set state to item 1 of stPair
+ set message to item 2 of stPair
+ if message is not "" then label's setStringValue:message
+ if state is in {"done", "manual", "error"} then
+ bar's stopAnimation:(missing value)
+ exit repeat
+ end if
+ end if
+ delay 0.5
+ end repeat
+ if state is "done" then
+ # The app is coming back; the shim's job is over.
+ delay 1.5
+ else
+ # manual/error: mirror stop_ui leave-window so the message is readable
+ # even without it (the durable result dialog covers the rest).
+ delay 15
+ end if
+end run
+
+on readStatus(statusFile)
+ # write_status emits a flat, one-line JSON pair we control, so field
+ # extraction beats NSJSONSerialization here (whose |error|: label this
+ # osascript rejects in by-ref position). Values are json_escaped by the
+ # writer; only \" can appear inside them and it carries no delimiter risk
+ # for the "..."-capturing pattern below. A missing/unreadable status file
+ # just yields no update this tick — the writer's atomic mv guarantees we
+ # never see a partial file.
+ set raw to ""
+ try
+ set raw to do shell script "/usr/bin/grep -o '\\\"status\\\":\\\"[^\\\"]*\\\"' " & quoted form of statusFile & " | /usr/bin/head -1"
+ end try
+ if raw is "" then return missing value
+ set AppleScript's text item delimiters to "\""
+ set state to text item 4 of raw
+ set rawMsg to ""
+ try
+ set rawMsg to do shell script "/usr/bin/grep -o '\\\"message\\\":\\\"[^\\\"]*\\\"' " & quoted form of statusFile & " | /usr/bin/head -1"
+ end try
+ set msg to ""
+ if rawMsg is not "" then set msg to text item 4 of rawMsg
+ set AppleScript's text item delimiters to ""
+ return {state, msg}
+end readStatus