diff --git a/Sources/Shotdeck/main.swift b/Sources/Shotdeck/main.swift index d8231f2..3d8dcb6 100644 --- a/Sources/Shotdeck/main.swift +++ b/Sources/Shotdeck/main.swift @@ -81,6 +81,25 @@ final class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ notification: Notification) { Task { await model.bootstrap() } + // `--window` opens the session window at launch (scripts and demos); a normal + // launch stays quiet in the menu bar. + if CommandLine.arguments.contains("--window") { + presentSessionsWindow() + } + } + + /// Clicking the app in Finder, or `open -a Redline`, while it runs shows the + /// window instead of doing nothing — standard macOS behaviour for a menu-bar app + /// with a main window. + func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows: Bool) -> Bool { + if !hasVisibleWindows { + presentSessionsWindow() + } + return true + } + + private func presentSessionsWindow() { + (model as SessionsWindowPresenting).presentSessionsWindow(focusLane: false) } /// Builds the model exactly the way the real app launches: paths come from diff --git a/scripts/install-local.sh b/scripts/install-local.sh new file mode 100755 index 0000000..795453f --- /dev/null +++ b/scripts/install-local.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Installs the locally built Redline into /Applications and launches it with its +# session window open, so the current build is what is on screen. +# +# ./scripts/install-local.sh +# +# The previously installed copy is kept at .build/Redline-.app so the change +# is reversible. + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +BUILT="${ROOT}/.build/Redline.app" +TARGET="/Applications/Redline.app" +BUNDLE_ID="ai.flowmaster.shotdeck" + +if [[ ! -d "${BUILT}" ]]; then + echo "No ${BUILT}. Run ./scripts/build-app.sh first." >&2 + exit 1 +fi + +if [[ -d "${TARGET}" ]]; then + OLD_VERSION="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "${TARGET}/Contents/Info.plist")" + BACKUP="${ROOT}/.build/Redline-${OLD_VERSION}.app" + if [[ ! -d "${BACKUP}" ]]; then + echo "==> Keeping the installed ${OLD_VERSION} at ${BACKUP}" + ditto "${TARGET}" "${BACKUP}" + fi +fi + +echo "==> Quitting the running Redline" +osascript -e 'quit app "Redline"' >/dev/null 2>&1 || true +for _ in $(seq 1 40); do + if ! pgrep -f "${TARGET}/Contents/MacOS/Shotdeck" >/dev/null 2>&1; then + break + fi + sleep 0.25 +done +pkill -f "${TARGET}/Contents/MacOS/Shotdeck" >/dev/null 2>&1 || true +sleep 0.5 + +echo "==> Installing ${BUILT} to ${TARGET}" +ditto "${BUILT}" "${TARGET}" + +NEW_VERSION="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "${TARGET}/Contents/Info.plist")" +echo "==> Launching Redline ${NEW_VERSION} with its window open" +open -n "${TARGET}" --args --window + +sleep 2 +if pgrep -f "${TARGET}/Contents/MacOS/Shotdeck" >/dev/null 2>&1; then + echo "Redline ${NEW_VERSION} is running from ${TARGET}" +else + echo "Redline did not start" >&2 + exit 1 +fi