diff pui-backend.c @ 46:8ed91c5e0116

Explicitly schedule the initial check for updates after a fixed short delay Explicitly schedule the first check after startup to run after a short delay defined in PUI_STARTUP_DELAY. This was always intended but not correctly handled before, the first check could thus take up to the number of seconds defined in PUI_CHECK_UPDATES_INTERVAL.
author Guido Berhoerster <guido+pui@berhoerster.name>
date Mon, 09 Nov 2020 15:06:04 +0100
parents 4a859595eabd
children a5ed1047ce14
line wrap: on
line diff
--- a/pui-backend.c	Thu Nov 05 11:18:16 2020 +0100
+++ b/pui-backend.c	Mon Nov 09 15:06:04 2020 +0100
@@ -290,23 +290,33 @@
 			g_debug("perioidic checks inhibited: low battery");
 		}
 	} else {
-		/* schedule periodic checks when no longer inhibited */
-		elapsed_time = (g_get_monotonic_time() - self->last_check) /
-		    G_USEC_PER_SEC;
-		/*
-		 * if more time that the check interval has passed since the
-		 * last check, schedule a check after a short delay, otherwise
-		 * wait until the interval has passed
-		 */
-		remaining_time = (elapsed_time < PUI_CHECK_UPDATES_INTERVAL) ?
-		    PUI_CHECK_UPDATES_INTERVAL - elapsed_time :
-		    PUI_STARTUP_DELAY;
+		if (self->last_check == 0) {
+			/* first check after startup */
+			remaining_time = PUI_STARTUP_DELAY;
+
+			g_debug("scheduled first check in: %ds",
+			    remaining_time);
+		} else {
+			/* schedule periodic checks when no longer inhibited */
+			elapsed_time =
+			    (g_get_monotonic_time() - self->last_check) /
+			    G_USEC_PER_SEC;
+			/*
+			 * if more time than the check interval has passed
+			 * since the last check, schedule a check after a short
+			 * delay, otherwise wait until the interval has passed
+			 */
+			remaining_time =
+			    (elapsed_time < PUI_CHECK_UPDATES_INTERVAL) ?
+			    PUI_CHECK_UPDATES_INTERVAL - elapsed_time :
+			    PUI_STARTUP_DELAY;
+
+			g_debug("perioidic checks no longer inhibited, "
+			    "time since last check: %ds, next check in: %ds",
+			    elapsed_time, remaining_time);
+		}
 		self->check_id = g_timeout_add_seconds(remaining_time,
 		    periodic_check, self);
-
-		g_debug("perioidic checks no longer inhibited, time since "
-		    "last check: %ds, next check in: %ds", elapsed_time,
-		    remaining_time);
 	}
 }