Skip to content

feat(dashboard): 以 inotify 取代固定間隔輪詢,降低 CPU 使用率 #9

@MuLinForest

Description

@MuLinForest

Dashboard 目前以固定 2 秒間隔強制刷新(dashboard.sh 第 7 行),即使沒有任何 session 狀態變動也會重繪。

建議將 main loop 改為:

mkdir -p "$SESSIONS_DIR"
trap 'printf "\n"; exit 0' INT TERM

if command -v inotifywait > /dev/null 2>&1; then
    # Linux: 事件驅動,只有 session 檔案變動時才重繪
    render
    while inotifywait -q -e modify,create,delete "$SESSIONS_DIR" > /dev/null 2>&1; do
        render
    done
else
    # fallback: 原有輪詢機制(macOS 或未安裝 inotify-tools)
    while true; do
        render
        sleep "$INTERVAL"
    done
fi

好處:

  • Claude 回應時 dashboard 幾乎即時更新
  • 無變動時零 CPU 消耗,不做無謂重繪
  • macOS 和未安裝 inotify-tools 的環境自動降級,不影響現有使用者

如果方向可行,可以接著送 PR。

Drafted with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions