Scritps for emulationstation events: can we delay launching them?
-
I wrote a plugin for Attract Mode that updates a dynamic marquee, and I'm trying to bring the same functionality to emulationstation. currently I'm using the scripts/system-select and scripts/game-select directories.
My scripts launch an ssh command (that may launch an sftp command) so it can take a second to complete.
running with & at the end of the command takes care of the lag, but causes other problems. Specifically when rapidly going through games, several instances can be running at once and cause a race condition, that can cause the wrong image to be displayed, or several images flash by as it catches up.Is there a way to delay launching the script until the user "settles" on a specific game or system before launching the scripts? 1/2 second to 750ms delay would help a lot.
-
@LeatherWing said in Scritps for emulationstation events: can we delay launching them?:
Is there a way to delay launching the script until the user "settles" on a specific game or system before launching the scripts? 1/2 second to 750ms delay would help a lot.
No, there is no option to add a triggering delay or something similar. Scripts are triggered automatically when the events are fired.
-
@LeatherWing maybe something like this would work?
# avoid multiple starts wait=0 while [[ "$(pgrep -c -f $(basename $0))" -gt 1 ]]; do [[ "$wait" -gt 6 ]] && exit 1 wait="$[$wait +1]" sleep 1 done
Here, I try (up to six times, with a 1-second delay in between) to ensure that this process running is the only one with that name right now. If it ever is (because no other was started, or else because they have all completed already and only this last one remains), then the script continues. If it checks and fails six times (here, long enough for the music "fade-out" to complete -- you probably don't need to wait that long) then it aborts, giving a chance for one of the later ones to take over.
You might want to change the sleep interval to something faster (like
sleep .1
) instead, and/or only do the check a fewer number of times (where it says"$wait" -gt 6
).Or even simpler: a brief pause, check once, and then continue or abort. That would look something like:
# avoid multiple starts wait .75 [[ "$(pgrep -c -f $(basename $0))" -gt 1 ]] && exit 1
-
@sleve_mcdichael I like the idea, for what I'm doing I think I want to kill any previously running processes vs letting them continue. Only the newest process will be the relevant process
I might make the script kill any previous processes
then wait
then either be killed by a newer process or update the marqueeI'll give this a try tonight and see how it works. I just home emulationstation doesn't hang waiting for sleep to finish.
process=$(pgrep -f $(basename $0)) for i in $process do if i!=$$ then sudo kill $i fi done sleep .5 ...do stuff
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.