← back to Desktop Dotbar

start-bar.command

38 lines

#!/usr/bin/env bash
# Double-click (or: bash start-bar.command) to launch the always-on-top desktop dot bar.
# Starts the node server, then floats a frameless Electron strip across the top of the
# desktop, above every window. Quit with the ✕ on the bar (or: pkill -f desktop-dotbar).
set -u
DIR="$HOME/Projects/desktop-dotbar"
cd "$DIR" || exit 1
# launchd has a minimal PATH; Electron's launcher uses /usr/bin/env node.
export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:$PATH"

# Jev paid classification: ARMED (Steve, 2026-09-23, TK-12078). Disarm: set default below to :-0 + kickstart.
export DOTBAR_JEV_PAID="${DOTBAR_JEV_PAID:-1}"
export DOTBAR_JEV_CAP_USD="${DOTBAR_JEV_CAP_USD:-2}"
export DOTBAR_JEV_MAX_CALLS="${DOTBAR_JEV_MAX_CALLS:-800}"

# tear down any previous instance (electron + this app's node server)
pkill -f "desktop-dotbar/electron-main.js" 2>/dev/null
pkill -f "Electron.*desktop-dotbar" 2>/dev/null
pkill -f "desktop-dotbar/server.js" 2>/dev/null
sleep 0.4

# 1) start the server with real node (absolute path so pkill can find it later).
# launchd's PATH lacks homebrew, so `command -v node` is empty under `launchctl kickstart` —
# fall back to the known homebrew/usr locations so a launchd restart actually starts the server.
NODE="$(command -v node || true)"
[ -x "$NODE" ] || NODE="$(for n in /opt/homebrew/bin/node /usr/local/bin/node /usr/bin/node; do [ -x "$n" ] && echo "$n" && break; done)"
nohup "$NODE" "$DIR/server.js" >"$DIR/server.log" 2>&1 &
for i in $(seq 1 40); do
  [ -f "$DIR/.port" ] && curl -sf "http://127.0.0.1:$(cat "$DIR/.port")/health" >/dev/null 2>&1 && break
  sleep 0.2
done
echo "server on :$(cat "$DIR/.port" 2>/dev/null)"

# 2) float the Electron strip. Keep this launcher attached to Electron so
# launchd can supervise the bar instead of treating the script as finished.
echo "dot bar launching… (close this window)"
exec "$DIR/node_modules/.bin/electron" "$DIR" >>"$DIR/bar.log" 2>&1