Closed sboysel closed 2 years ago
Ah. Need to check length of argument list in onEvent
array
This looks wonderful @sboysel and it's exactly what I had in mind! There is one tiny issue which is that if the script that is called blocks for any reason it will break the UI and cause it to become unresponsive. You can replicate this by changing your example script to something like sleep inf
and observe that the UI is no longer responsive.
You can resolve this by simply running the script in a Go routine:
diff --git a/pkg/internal/runner.go b/pkg/internal/runner.go
index ea9fe17..46a802c 100644
--- a/pkg/internal/runner.go
+++ b/pkg/internal/runner.go
@@ -80,7 +80,7 @@ func (t *TaskRunner) SetState(state State) {
t.state = state
// execute onEvent command if variable is set
if t.onEvent != nil {
- t.runOnEvent()
+ go t.runOnEvent()
}
}
We can also consider adding a directory called contrib
where we put community contributed scripts that extend the functionality of pomo. For example on my system I just added one called pomonag
which produces a notification as part of the Sway window manager on my system.
#!/bin/sh
if [ "$POMO_STATE" == "BREAKING" ] ; then
swaynag -m "It's time to take a break!"
fi
Just a suggestion, happy to approve this right away after fixing the Go routine issue. Thanks again so much, this is wonderful!
Got it. Thanks for the tip! I'll make the change shortly.
I like the contrib directory idea. I can add this to the PR and include a sample script.
A more general solution that supersedes #60
onEvent
to specify command to be run after every state change (i.e.RUNNING
,PAUSED
,BREAKING
, orCOMPLETE
)POMO_STATE