@@ -375,6 +375,114 @@ linux_logs() {
375375 fi
376376}
377377
378+ # =============================================================================
379+ # Windows (Git Bash / MINGW) functions
380+ # =============================================================================
381+
382+ windows_pid_file () {
383+ echo " ${DATA_DIR} /${SERVICE_NAME} .pid"
384+ }
385+
386+ windows_start () {
387+ local pid_file=" $( windows_pid_file) "
388+ local node_bin=" $( command -v node 2> /dev/null || echo ' node' ) "
389+
390+ if [ -f " $pid_file " ]; then
391+ local old_pid=$( cat " $pid_file " 2> /dev/null)
392+ if [ -n " $old_pid " ] && kill -0 " $old_pid " 2> /dev/null; then
393+ echo " Already running (PID: $old_pid )"
394+ exit 0
395+ fi
396+ rm -f " $pid_file "
397+ fi
398+
399+ mkdir -p " $DATA_DIR /logs"
400+
401+ echo " Starting wechat-claude-code daemon (Windows)..."
402+ nohup " $node_bin " " ${PROJECT_DIR} /dist/main.js" start \
403+ >> " $DATA_DIR /logs/stdout.log" \
404+ 2>> " $DATA_DIR /logs/stderr.log" &
405+ local pid=$!
406+ echo " $pid " > " $pid_file "
407+ echo " Started (PID: $pid )"
408+ echo " Logs: $DATA_DIR /logs/stdout.log"
409+ }
410+
411+ windows_stop () {
412+ local pid_file=" $( windows_pid_file) "
413+
414+ if [ ! -f " $pid_file " ]; then
415+ echo " Not running (no PID file)"
416+ exit 0
417+ fi
418+
419+ local pid=$( cat " $pid_file " 2> /dev/null)
420+ if [ -z " $pid " ]; then
421+ rm -f " $pid_file "
422+ echo " Stopped"
423+ exit 0
424+ fi
425+
426+ if kill -0 " $pid " 2> /dev/null; then
427+ kill " $pid " 2> /dev/null || true
428+ local count=0
429+ while kill -0 " $pid " 2> /dev/null && [ $count -lt 10 ]; do
430+ sleep 1
431+ count=$(( count + 1 ))
432+ done
433+ # Fallback: use taskkill if process still alive
434+ if kill -0 " $pid " 2> /dev/null; then
435+ taskkill //F //PID " $pid " 2> /dev/null || true
436+ fi
437+ echo " Stopped (PID: $pid )"
438+ else
439+ echo " Process not running (cleaning up PID file)"
440+ fi
441+
442+ rm -f " $pid_file "
443+ }
444+
445+ windows_status () {
446+ local pid_file=" $( windows_pid_file) "
447+
448+ if [ ! -f " $pid_file " ]; then
449+ echo " Not running"
450+ exit 0
451+ fi
452+
453+ local pid=$( cat " $pid_file " 2> /dev/null)
454+ if [ -z " $pid " ]; then
455+ echo " Not running (invalid PID file)"
456+ exit 0
457+ fi
458+
459+ if kill -0 " $pid " 2> /dev/null; then
460+ echo " Running (PID: $pid )"
461+ else
462+ echo " Not running (stale PID file)"
463+ fi
464+ }
465+
466+ windows_logs () {
467+ local log_dir=" ${DATA_DIR} /logs"
468+ if [ -d " $log_dir " ]; then
469+ local latest=$( ls -t " ${log_dir} " /bridge-* .log 2> /dev/null | head -1)
470+ if [ -n " $latest " ]; then
471+ tail -100 " $latest "
472+ else
473+ for f in " ${log_dir} " /stdout.log " ${log_dir} " /stderr.log; do
474+ if [ -f " $f " ]; then
475+ echo " === $( basename " $f " ) ==="
476+ tail -50 " $f "
477+ echo " "
478+ fi
479+ done
480+ fi
481+ else
482+ echo " No logs found"
483+ fi
484+ }
485+
378486# =============================================================================
379487# Main dispatcher
380488# =============================================================================
@@ -411,9 +519,23 @@ main() {
411519 ;;
412520 esac
413521 ;;
522+ MINGW* |MSYS* |CYGWIN* )
523+ case " $command " in
524+ start) windows_start ;;
525+ stop) windows_stop ;;
526+ restart) windows_stop; sleep 1; windows_start ;;
527+ status) windows_status ;;
528+ logs) windows_logs ;;
529+ * )
530+ echo " Usage: daemon.sh {start|stop|restart|status|logs}"
531+ echo " Platform: Windows (Git Bash)"
532+ exit 1
533+ ;;
534+ esac
535+ ;;
414536 * )
415537 echo " Error: Unsupported platform '$OS_TYPE '"
416- echo " Supported platforms: macOS (Darwin), Linux"
538+ echo " Supported platforms: macOS (Darwin), Linux, Windows (MINGW/MSYS) "
417539 exit 1
418540 ;;
419541 esac
0 commit comments