Skip to content

fix(capture): self-re-exec detached to survive eww 200ms timeout#92

Merged
VictorGSchneider merged 1 commit into
mainfrom
claude/fix-screenshot-widget-Wiz6D
May 11, 2026
Merged

fix(capture): self-re-exec detached to survive eww 200ms timeout#92
VictorGSchneider merged 1 commit into
mainfrom
claude/fix-screenshot-widget-Wiz6D

Conversation

@VictorGSchneider
Copy link
Copy Markdown
Owner

@VictorGSchneider VictorGSchneider commented May 11, 2026

Causa raiz revisada

A tentativa anterior ((cmd </dev/null >/dev/null 2>&1 &) inline no onclick) quebrou completamente o caminho do onclick — o log de debug não mostra nenhuma invocação do script depois daquele merge. Por isso a gravação parou de funcionar também: o /bin/sh -c do eww não engoliu aquela sintaxe.

Fix

  1. eww.yuck: onclick volta ao mínimo — stoa-capture ${capture-mode} ${capture-type} ${capture-delay}. Sintaxe trivial que o sh do eww processa sem problema.

  2. stoa-capture.sh: dentro do case selection|screen|window, antes de fazer qualquer trabalho real, o script se re-executa em background detachado via nohup ... & e sai imediatamente. Uma env var de guarda (_STOA_CAPTURE_DETACHED) impede recursão infinita.

    if [ -z "${_STOA_CAPTURE_DETACHED:-}" ]; then
        _STOA_CAPTURE_DETACHED=1 nohup "$0" "$@" </dev/null >>/tmp/stoa-capture-debug.log 2>&1 &
        disown 2>/dev/null || true
        exit 0
    fi

A primeira invocação (a que o eww spawned) retorna em ms — bem antes dos 200ms. O filho detached faz eww close, sleep 0.5, e grim (ou wf-recorder) em paz.

Test plan

  • git pull && eww reload
  • 📷 Screen + disparo → arquivo em ~/Pictures/screenshots/
  • 📷 Selection → slurp abre e salva
  • 🎥 + disparo → gravação inicia; Print pra parar
  • /tmp/stoa-capture-debug.log mostra Re-execing detached, Running in detached mode, _screenshot called, Running grim ..., File exists? yes

Generated by Claude Code

Previous attempt wrapped the onclick in "(cmd </dev/null >/dev/null 2>&1 &)"
to background within the eww-spawned sh, but that syntax broke the eww
onclick path entirely — the script was never invoked, breaking both
screenshot and recording (the debug log shows no script calls at all
after that change).

Move the detach logic into the script itself: when called for a capture
action (selection/screen/window), re-exec via `nohup ... &` with a
guard env var (_STOA_CAPTURE_DETACHED) to prevent infinite recursion.
The first invocation returns almost instantly — well within eww's
200ms timeout — and the detached child runs the actual sleep + grim
(or wf-recorder) without being killed.

The eww onclick goes back to a plain "stoa-capture <mode> <type> <delay>"
which is a syntactically trivial command the eww sh has no trouble with.
@VictorGSchneider VictorGSchneider merged commit c175138 into main May 11, 2026
1 check passed
@VictorGSchneider VictorGSchneider deleted the claude/fix-screenshot-widget-Wiz6D branch May 11, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants