projects/package-update-indicator
changeset 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.
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 Nov 09 15:06:04 2020 +0100 (18 months ago) |
parents | 4a859595eabd |
children | 0d4bb2f8908a |
files | pui-backend.c |
line diff
1.1 --- a/pui-backend.c Thu Nov 05 11:18:16 2020 +0100 1.2 +++ b/pui-backend.c Mon Nov 09 15:06:04 2020 +0100 1.3 @@ -290,23 +290,33 @@ 1.4 g_debug("perioidic checks inhibited: low battery"); 1.5 } 1.6 } else { 1.7 - /* schedule periodic checks when no longer inhibited */ 1.8 - elapsed_time = (g_get_monotonic_time() - self->last_check) / 1.9 - G_USEC_PER_SEC; 1.10 - /* 1.11 - * if more time that the check interval has passed since the 1.12 - * last check, schedule a check after a short delay, otherwise 1.13 - * wait until the interval has passed 1.14 - */ 1.15 - remaining_time = (elapsed_time < PUI_CHECK_UPDATES_INTERVAL) ? 1.16 - PUI_CHECK_UPDATES_INTERVAL - elapsed_time : 1.17 - PUI_STARTUP_DELAY; 1.18 + if (self->last_check == 0) { 1.19 + /* first check after startup */ 1.20 + remaining_time = PUI_STARTUP_DELAY; 1.21 + 1.22 + g_debug("scheduled first check in: %ds", 1.23 + remaining_time); 1.24 + } else { 1.25 + /* schedule periodic checks when no longer inhibited */ 1.26 + elapsed_time = 1.27 + (g_get_monotonic_time() - self->last_check) / 1.28 + G_USEC_PER_SEC; 1.29 + /* 1.30 + * if more time than the check interval has passed 1.31 + * since the last check, schedule a check after a short 1.32 + * delay, otherwise wait until the interval has passed 1.33 + */ 1.34 + remaining_time = 1.35 + (elapsed_time < PUI_CHECK_UPDATES_INTERVAL) ? 1.36 + PUI_CHECK_UPDATES_INTERVAL - elapsed_time : 1.37 + PUI_STARTUP_DELAY; 1.38 + 1.39 + g_debug("perioidic checks no longer inhibited, " 1.40 + "time since last check: %ds, next check in: %ds", 1.41 + elapsed_time, remaining_time); 1.42 + } 1.43 self->check_id = g_timeout_add_seconds(remaining_time, 1.44 periodic_check, self); 1.45 - 1.46 - g_debug("perioidic checks no longer inhibited, time since " 1.47 - "last check: %ds, next check in: %ds", elapsed_time, 1.48 - remaining_time); 1.49 } 1.50 } 1.51