comparison 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
comparison
equal deleted inserted replaced
45:4a859595eabd 46:8ed91c5e0116
288 } 288 }
289 if (self->is_battery_low) { 289 if (self->is_battery_low) {
290 g_debug("perioidic checks inhibited: low battery"); 290 g_debug("perioidic checks inhibited: low battery");
291 } 291 }
292 } else { 292 } else {
293 /* schedule periodic checks when no longer inhibited */ 293 if (self->last_check == 0) {
294 elapsed_time = (g_get_monotonic_time() - self->last_check) / 294 /* first check after startup */
295 G_USEC_PER_SEC; 295 remaining_time = PUI_STARTUP_DELAY;
296 /* 296
297 * if more time that the check interval has passed since the 297 g_debug("scheduled first check in: %ds",
298 * last check, schedule a check after a short delay, otherwise 298 remaining_time);
299 * wait until the interval has passed 299 } else {
300 */ 300 /* schedule periodic checks when no longer inhibited */
301 remaining_time = (elapsed_time < PUI_CHECK_UPDATES_INTERVAL) ? 301 elapsed_time =
302 PUI_CHECK_UPDATES_INTERVAL - elapsed_time : 302 (g_get_monotonic_time() - self->last_check) /
303 PUI_STARTUP_DELAY; 303 G_USEC_PER_SEC;
304 /*
305 * if more time than the check interval has passed
306 * since the last check, schedule a check after a short
307 * delay, otherwise wait until the interval has passed
308 */
309 remaining_time =
310 (elapsed_time < PUI_CHECK_UPDATES_INTERVAL) ?
311 PUI_CHECK_UPDATES_INTERVAL - elapsed_time :
312 PUI_STARTUP_DELAY;
313
314 g_debug("perioidic checks no longer inhibited, "
315 "time since last check: %ds, next check in: %ds",
316 elapsed_time, remaining_time);
317 }
304 self->check_id = g_timeout_add_seconds(remaining_time, 318 self->check_id = g_timeout_add_seconds(remaining_time,
305 periodic_check, self); 319 periodic_check, self);
306
307 g_debug("perioidic checks no longer inhibited, time since "
308 "last check: %ds, next check in: %ds", elapsed_time,
309 remaining_time);
310 } 320 }
311 } 321 }
312 322
313 static void 323 static void
314 pui_backend_set_property(GObject *object, guint property_id, 324 pui_backend_set_property(GObject *object, guint property_id,