@@ -416,11 +416,87 @@ _ap_resolve_cli() {
416416 return 1
417417}
418418
419+ _ap_is_wsl () {
420+ grep -qi microsoft /proc/version 2> /dev/null || grep -qi wsl /proc/sys/kernel/osrelease 2> /dev/null
421+ }
422+
423+ _ap_dashboard_url () {
424+ local openclaw_cli=" $1 "
425+ local out line url
426+
427+ out=" $( " $openclaw_cli " dashboard --no-open 2> /dev/null || true) "
428+ while IFS= read -r line; do
429+ case " $line " in
430+ Dashboard\ URL:* )
431+ url=" ${line# Dashboard URL: } "
432+ printf ' %s\n' " $url "
433+ return 0
434+ ;;
435+ esac
436+ done <<< " $out"
437+
438+ return 1
439+ }
440+
441+ _ap_dashboard_url_with_session () {
442+ local url=" $1 "
443+ if [ -z " $url " ]; then
444+ return 1
445+ fi
446+ case " $url " in
447+ * session=* )
448+ printf ' %s\n' " $url "
449+ ;;
450+ * #* )
451+ printf ' %s&session=main\n' " $url "
452+ ;;
453+ * )
454+ printf ' %s#session=main\n' " $url "
455+ ;;
456+ esac
457+ }
458+
459+ _ap_open_dashboard_url () {
460+ local url=" $1 "
461+ local ps_url
462+
463+ if command -v wslview > /dev/null 2>&1 ; then
464+ wslview " $url " > /dev/null 2>&1
465+ return $?
466+ fi
467+
468+ if _ap_is_wsl && command -v powershell.exe > /dev/null 2>&1 ; then
469+ ps_url=" ${url// \' / \'\' } "
470+ powershell.exe -NoProfile -WindowStyle Hidden -Command " Start-Process '$ps_url '" > /dev/null 2>&1
471+ return $?
472+ fi
473+
474+ if command -v xdg-open > /dev/null 2>&1 && { [ -n " ${DISPLAY:- } " ] || [ -n " ${WAYLAND_DISPLAY:- } " ]; }; then
475+ xdg-open " $url " > /dev/null 2>&1
476+ return $?
477+ fi
478+
479+ return 1
480+ }
481+
419482_ap_schedule_dashboard () {
420483 local openclaw_cli=" $1 "
421- # Give the gateway a few seconds to bind before opening the browser
422- # (dashboard itself doesn't probe, so we sleep for the user's sake).
423- ( sleep 3 && " $openclaw_cli " dashboard > /dev/null 2>&1 ) &
484+ local dashboard_url=" "
485+
486+ dashboard_url=" $( _ap_dashboard_url " $openclaw_cli " || true) "
487+ if [ -z " $dashboard_url " ]; then
488+ echo " [!] Could not resolve the OpenClaw dashboard URL automatically."
489+ echo " [!] After startup, run: openclaw dashboard"
490+ return 1
491+ fi
492+
493+ dashboard_url=" $( _ap_dashboard_url_with_session " $dashboard_url " ) "
494+ echo " [*] OpenClaw dashboard URL: $dashboard_url "
495+
496+ (
497+ sleep 3
498+ _ap_open_dashboard_url " $dashboard_url " || true
499+ ) > /dev/null 2>&1 &
424500 disown 2> /dev/null || true
425501}
426502
@@ -448,16 +524,18 @@ if _ap_has openclaw && _ap_has hermes; then
448524 echo " [*] Starting openclaw gateway in the background (log: $_openclaw_log )..."
449525 nohup " $_OPENCLAW_CLI " gateway --verbose > " $_openclaw_log " 2>&1 &
450526 disown 2> /dev/null || true
451- _ap_schedule_dashboard " $_OPENCLAW_CLI "
452- echo " [*] Opening OpenClaw dashboard in your browser shortly..."
527+ if _ap_schedule_dashboard " $_OPENCLAW_CLI " ; then
528+ echo " [*] Attempting to open OpenClaw dashboard in your browser..."
529+ fi
453530 echo " [*] Starting hermes in this window..."
454531 exec " $_HERMES_CLI "
455532elif _ap_has hermes; then
456533 echo " [*] Starting hermes in this window..."
457534 exec " $_HERMES_CLI "
458535elif _ap_has openclaw; then
459- _ap_schedule_dashboard " $_OPENCLAW_CLI "
460- echo " [*] Opening OpenClaw dashboard in your browser shortly..."
536+ if _ap_schedule_dashboard " $_OPENCLAW_CLI " ; then
537+ echo " [*] Attempting to open OpenClaw dashboard in your browser..."
538+ fi
461539 echo " [*] Starting openclaw gateway in this window..."
462540 exec " $_OPENCLAW_CLI " gateway --verbose
463541fi
0 commit comments