Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove startup delay #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Remove startup delay #3

wants to merge 1 commit into from

Conversation

amarz45
Copy link

@amarz45 amarz45 commented Aug 5, 2022

By default, the status bar first appears one second after running the command. With this pull request, the status bar will appear instantly and then update appropriately.

@AustralEpitech
Copy link

AustralEpitech commented Apr 2, 2024

This doesn't work because wait is killed when you send a signal, triggering the reload of every command and not just the trap, you would need something like this:

	wait && {
		# to update item ever n seconds with a offset of m
		## [ $((sec % n)) -eq m ] && update_item
		[ $((sec % 5 )) -eq 0 ] && update_time 	# update time every 5 seconds
		[ $((sec % 15)) -eq 0 ] && update_cpu 	# update cpu every 15 seconds
		[ $((sec % 15)) -eq 0 ] && update_memory
		[ $((sec % 60)) -eq 0 ] && update_bat
		[ $((sec % 3600)) -eq 2 ] && update_weather
		#[ $((sec % 300)) -eq 1 ] && update_event

		# how often the display updates (5 seconds)
		[ $((sec % 5 )) -eq 0 ] && display
		sec=$((sec + 1))
	}
	sleep 1 &

This works because wait doesn't do anything if there is nothing in the bg (the first iteration), then it waits for the sleep and if you send a signal, it exits with 128.
The only problem is that it resets the sleep timer every time, so if you send more than one signal every second, you could prevent the bar to update completely, you would need a variable to store the expected end time of the sleep

One hacky work around is this:

awk '@load "time"; BEGIN {d=10; s=system("date \"+%S.%N\""); sleep(d - s % d)}' &

It sleeps until the next second instead of for one full second (you can change the d variable to sleep for more or less).
Not perfect, but the probability that you send a signal at the exact same time is much slimmer, at the cost of a bit of extra processing.

@AustralEpitech
Copy link

Actually, I just noticed that this causes a lot of sleep to spawn because the wait process is killed, not the sleep, the solution to this (and to the timer reset) is simply to modify the trap command like this:

# trap  '<function>;display;wait'             'RTMIN+n'

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