kablan 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/install-app.js +41 -4
- package/package.json +1 -1
package/bin/install-app.js
CHANGED
|
@@ -28,13 +28,20 @@ function appDir() {
|
|
|
28
28
|
* login shell what PATH really is, the same thing a terminal would have.
|
|
29
29
|
*/
|
|
30
30
|
function launcherScript() {
|
|
31
|
+
const bin = APP_NAME.toLowerCase();
|
|
31
32
|
return `#!/bin/bash
|
|
32
|
-
# Generated by \`npx kablan --install\`. Re-run that to update.
|
|
33
|
+
# Generated by \`npx kablan --install\`. Re-run that to update this launcher.
|
|
34
|
+
#
|
|
35
|
+
# This script starts Kablan and then exits. It must exit: a .app whose executable never returns
|
|
36
|
+
# is one macOS is still waiting to see register with the window server, so the Dock icon bounces
|
|
37
|
+
# and the app is eventually reported as not responding — which is what happens if you exec the
|
|
38
|
+
# server here instead of detaching it.
|
|
33
39
|
set -u
|
|
34
40
|
|
|
35
41
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
36
42
|
|
|
37
|
-
#
|
|
43
|
+
# A GUI launch inherits almost no PATH, so node, pnpm and the coding agents are all missing.
|
|
44
|
+
# Take the login shell's PATH, which is what a terminal would have.
|
|
38
45
|
SHELL_BIN="\${SHELL:-/bin/zsh}"
|
|
39
46
|
RESOLVED="$("$SHELL_BIN" -ilc 'printf %s "$PATH"' 2>/dev/null || true)"
|
|
40
47
|
if [ -n "$RESOLVED" ]; then
|
|
@@ -45,11 +52,41 @@ for dir in /opt/homebrew/bin /usr/local/bin /usr/bin /bin; do
|
|
|
45
52
|
done
|
|
46
53
|
export PATH
|
|
47
54
|
|
|
48
|
-
# There is no terminal attached, so keep output where it can be read after the fact.
|
|
49
55
|
LOG_DIR="$HOME/Library/Logs/${APP_NAME}"
|
|
50
56
|
mkdir -p "$LOG_DIR"
|
|
57
|
+
LOG="$LOG_DIR/${bin}.log"
|
|
51
58
|
|
|
52
|
-
|
|
59
|
+
# Where the server publishes the port it bound, so a second launch can find the first.
|
|
60
|
+
TMP="\${TMPDIR:-/tmp}"
|
|
61
|
+
PORT_FILE="\${TMP%/}/${bin}/${bin}.port"
|
|
62
|
+
|
|
63
|
+
# Already running? Bring it up rather than starting a second copy on another port.
|
|
64
|
+
PORT="$(cat "$PORT_FILE" 2>/dev/null || true)"
|
|
65
|
+
if [ -n "$PORT" ] && curl -fsS -o /dev/null --max-time 2 "http://127.0.0.1:$PORT/api/info"; then
|
|
66
|
+
open "http://127.0.0.1:$PORT"
|
|
67
|
+
exit 0
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
# Prefer the published wrapper so opening the icon runs the newest release rather than whatever
|
|
71
|
+
# was current on the day this was installed. The copy inside the bundle is the fallback for a
|
|
72
|
+
# machine without node, or one that cannot reach the registry.
|
|
73
|
+
{
|
|
74
|
+
echo "--- $(date '+%Y-%m-%d %H:%M:%S') launching"
|
|
75
|
+
if command -v npx >/dev/null 2>&1; then
|
|
76
|
+
echo "using npx kablan@latest"
|
|
77
|
+
else
|
|
78
|
+
echo "npx not found; using the bundled ${bin}-server"
|
|
79
|
+
fi
|
|
80
|
+
} >>"$LOG" 2>&1
|
|
81
|
+
|
|
82
|
+
if command -v npx >/dev/null 2>&1; then
|
|
83
|
+
nohup npx -y ${bin}@latest >>"$LOG" 2>&1 &
|
|
84
|
+
else
|
|
85
|
+
nohup "$HERE/${bin}-server" >>"$LOG" 2>&1 &
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
# The server opens the browser itself once it is listening, so there is nothing left to wait for.
|
|
89
|
+
exit 0
|
|
53
90
|
`;
|
|
54
91
|
}
|
|
55
92
|
|