@@ -55,18 +55,6 @@ __lp_prepend_path() {
55
55
# Ensure Launchpad global bin is on PATH early (for globally installed tools)
56
56
__lp_prepend_path "$HOME/.local/share/launchpad/global/bin"
57
57
58
- # Portable timeout helper: uses timeout, gtimeout (macOS), or no-timeout fallback
59
- lp_timeout() {
60
- local duration="$1"; shift
61
- if command -v timeout >/dev/null 2>&1; then
62
- timeout "$duration" "$@"
63
- elif command -v gtimeout >/dev/null 2>&1; then
64
- gtimeout "$duration" "$@"
65
- else
66
- "$@"
67
- fi
68
- }
69
-
70
58
# Portable current time in milliseconds
71
59
lp_now_ms() {
72
60
if [[ -n "$ZSH_VERSION" && -n "$EPOCHREALTIME" ]]; then
@@ -188,10 +176,10 @@ __launchpad_switch_environment() {
188
176
printf "⏱️ [0ms] Shell integration started for PWD=%s\\n" "$PWD" >&2
189
177
fi
190
178
191
- # Step 1: Find project directory using our fast binary (with portable timeout)
179
+ # Step 1: Find project directory using our fast binary (no artificial timeout)
192
180
local project_dir=""
193
- if lp_timeout 1s ${ launchpadBinary } dev:find-project-root "$PWD" >/dev/null 2>&1; then
194
- project_dir=$(LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 lp_timeout 1s ${ launchpadBinary } dev:find-project-root "$PWD" 2>/dev/null || echo "")
181
+ if ${ launchpadBinary } dev:find-project-root "$PWD" >/dev/null 2>&1; then
182
+ project_dir=$(LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 ${ launchpadBinary } dev:find-project-root "$PWD" 2>/dev/null || echo "")
195
183
fi
196
184
197
185
# Verbose: show project detection result
@@ -278,7 +266,7 @@ __launchpad_switch_environment() {
278
266
if [[ -n "$project_dir" ]]; then
279
267
local project_basename=$(basename "$project_dir")
280
268
# Use proper MD5 hash to match existing environments
281
- local md5hash=$(printf "%s" "$project_dir" | LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 lp_timeout 2s ${ launchpadBinary } dev:md5 /dev/stdin 2>/dev/null || echo "00000000")
269
+ local md5hash=$(printf "%s" "$project_dir" | LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 ${ launchpadBinary } dev:md5 /dev/stdin 2>/dev/null || echo "00000000")
282
270
local project_hash="\${project_basename}_$(echo "$md5hash" | cut -c1-8)"
283
271
284
272
# Check for dependency file to add dependency hash
@@ -292,10 +280,10 @@ __launchpad_switch_environment() {
292
280
293
281
local env_dir="$HOME/.local/share/launchpad/envs/$project_hash"
294
282
if [[ -n "$dep_file" ]]; then
295
- local dep_short=$(LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 lp_timeout 2s ${ launchpadBinary } dev:md5 "$dep_file" 2>/dev/null | cut -c1-8 || echo "")
296
- if [[ -n "$dep_short" ]]; then
297
- env_dir="\${env_dir}-d\${dep_short}"
298
- fi
283
+ local dep_short=$(LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 ${ launchpadBinary } dev:md5 "$dep_file" 2>/dev/null | cut -c1-8 || echo "")
284
+ if [[ -n "$dep_short" ]]; then
285
+ env_dir="\${env_dir}-d\${dep_short}"
286
+ fi
299
287
fi
300
288
301
289
# Check if we're switching projects
@@ -330,28 +318,44 @@ __launchpad_switch_environment() {
330
318
printf "✅ Activated environment: %s\n" "$env_dir" >&2
331
319
fi
332
320
else
333
- # Install dependencies synchronously but with timeout to avoid hanging
334
- # Use LAUNCHPAD_SHELL_INTEGRATION=1 to enable proper progress display
335
- if LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 LAUNCHPAD_SHELL_INTEGRATION=1 lp_timeout 30s ${ launchpadBinary } install "$project_dir"; then
336
- if [[ "$verbose_mode" == "true" ]]; then
337
- printf "📦 Installed project dependencies (on-demand)\n" >&2
321
+ # Non-blocking on-demand install with retry backoff (no artificial timeout)
322
+ local cache_dir="$HOME/.cache/launchpad/shell_cache"
323
+ mkdir -p "$cache_dir" 2>/dev/null || true
324
+ local backoff_marker="$cache_dir/install_backoff_$(echo "$env_dir" | sed 's/\//_/g')"
325
+
326
+ local now_s=$(date +%s 2>/dev/null || echo 0)
327
+ local retry_after=600 # 10 minutes
328
+ local should_attempt=1
329
+ if [[ -f "$backoff_marker" ]]; then
330
+ local mtime=$(date -r "$backoff_marker" +%s 2>/dev/null || echo 0)
331
+ if [[ $(( now_s - mtime )) -lt $retry_after ]]; then
332
+ should_attempt=0
338
333
fi
339
- # If install succeeded, try to activate the environment
340
- if [[ -d "$env_dir/bin" ]]; then
341
- export LAUNCHPAD_CURRENT_PROJECT="$project_dir"
342
- export LAUNCHPAD_ENV_BIN_PATH="$env_dir/bin"
343
- export PATH="$env_dir/bin:$PATH"
334
+ fi
344
335
345
- # Show activation message if enabled
346
- if [[ "${ showMessages } " == "true" ]]; then
347
- printf "${ activationMessage } \\n" >&2
336
+ if [[ "$should_attempt" -eq 1 ]]; then
337
+ : > "$backoff_marker" 2>/dev/null || true
338
+ if LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 LAUNCHPAD_SHELL_INTEGRATION=1 ${ launchpadBinary } install "$project_dir"; then
339
+ if [[ -d "$env_dir/bin" ]]; then
340
+ export LAUNCHPAD_CURRENT_PROJECT="$project_dir"
341
+ export LAUNCHPAD_ENV_BIN_PATH="$env_dir/bin"
342
+ export PATH="$env_dir/bin:$PATH"
343
+ if [[ "${ showMessages } " == "true" ]]; then
344
+ printf "${ activationMessage } \\n" >&2
345
+ fi
346
+ if [[ "$verbose_mode" == "true" && "$__lp_should_verbose_print" == "1" ]]; then
347
+ printf "✅ Activated environment after install: %s\n" "$env_dir" >&2
348
+ fi
348
349
fi
349
-
350
- # Verbose: show activated env path after install
350
+ else
351
351
if [[ "$verbose_mode" == "true" && "$__lp_should_verbose_print" == "1" ]]; then
352
- printf "✅ Activated environment after install: %s \n" "$env_dir " >&2
352
+ printf "⏭️ Deferred on-demand install. Run 'launchpad install %q' manually. \n" "$project_dir " >&2
353
353
fi
354
354
fi
355
+ else
356
+ if [[ "$verbose_mode" == "true" && "$__lp_should_verbose_print" == "1" ]]; then
357
+ printf "⏳ Install backoff active; not attempting on-demand install.\n" >&2
358
+ fi
355
359
fi
356
360
fi
357
361
fi
0 commit comments