▍ humdrum codex / soft
1.9 KB raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# make-app.sh — build a double-clickable "Personal Dashboard.app" (no Terminal
# window) that starts the dashboard in the background and opens the browser.
# Run once: bash scripts/make-app.sh   →   creates ./Personal Dashboard.app

set -euo pipefail

REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
APP="$REPO/Personal Dashboard.app"
LAUNCH="$REPO/scripts/launch.command"

chmod +x "$LAUNCH"

# AppleScript: run the launcher detached (survives the .app exiting), then open
# the browser once the server answers. nohup + disown keeps the server alive.
read -r -d '' SCRIPT <<APPLESCRIPT || true
on run
  set repoPath to "$REPO"
  set launcher to quoted form of (repoPath & "/scripts/launch.command")
  do shell script "cd " & quoted form of repoPath & " && nohup " & launcher & " >/tmp/personal-dashboard.log 2>&1 & disown"
  -- give the server a moment, then open (launcher also opens on ready)
  repeat 30 times
    try
      do shell script "curl -sf http://localhost:4317/api/health >/dev/null"
      exit repeat
    on error
      delay 1
    end try
  end repeat
  open location "http://localhost:4317"
end run
APPLESCRIPT

rm -rf "$APP"
osacompile -o "$APP" -e "$SCRIPT"

# Use the generated PWA icon for the app, if available.
ICON_SRC="$REPO/public/icons/icon-512.png"
if [ -f "$ICON_SRC" ] && command -v sips >/dev/null 2>&1; then
  TMP_ICONSET="$(mktemp -d)/icon.iconset"
  mkdir -p "$TMP_ICONSET"
  for s in 16 32 64 128 256 512; do
    sips -z $s $s "$ICON_SRC" --out "$TMP_ICONSET/icon_${s}x${s}.png" >/dev/null 2>&1 || true
    d=$((s*2)); sips -z $d $d "$ICON_SRC" --out "$TMP_ICONSET/icon_${s}x${s}@2x.png" >/dev/null 2>&1 || true
  done
  if command -v iconutil >/dev/null 2>&1; then
    iconutil -c icns "$TMP_ICONSET" -o "$APP/Contents/Resources/applet.icns" 2>/dev/null || true
  fi
fi

echo "Created: $APP"
echo "Double-click it (or drag to the Dock). First launch builds, then opens the browser."