diff --git a/include/toniesJson.h b/include/toniesJson.h index 3060fdee..2ccb09c3 100644 --- a/include/toniesJson.h +++ b/include/toniesJson.h @@ -2,6 +2,11 @@ #include #include +#if !defined(__WINDOWS__) +#include +#else +#include +#endif #include "error.h" #define TEDDY_BENCH_AUDIO_ID_DEDUCT 0x50000000 @@ -27,6 +32,7 @@ typedef struct } toniesJson_item_t; void tonies_init(); +void tonies_updatePeriodically(); error_t tonies_update(); void tonies_readJson(char *source, toniesJson_item_t **toniesCache, size_t *toniesCount); toniesJson_item_t *tonies_byAudioId(uint32_t audio_id); diff --git a/src/server.c b/src/server.c index 33937297..b436b889 100644 --- a/src/server.c +++ b/src/server.c @@ -524,6 +524,7 @@ void server_init(bool test) { tonies_update(); } + osCreateTask("Update tonies.json", &tonies_updatePeriodically, NULL, 1024, 0); systime_t last = osGetSystemTime(); size_t openConnectionsLast = 0; diff --git a/src/toniesJson.c b/src/toniesJson.c index aefe025c..c0a477b2 100644 --- a/src/toniesJson.c +++ b/src/toniesJson.c @@ -34,6 +34,22 @@ void tonies_init() } } +void tonies_updatePeriodically() +{ + while (true) + { +#if !defined(__WINDOWS__) + sleep(60 * 60 * 6); +#else + Sleep(60 * 60 * 6 * 1000); // Windows Sleep() is in ms +#endif + if (get_settings()->core.tonies_json_auto_update) + { + tonies_update(); + } + } +} + void tonies_downloadBody(void *src_ctx, HttpClientContext *cloud_ctx, const char *payload, size_t length, error_t error) { cbr_ctx_t *ctx = (cbr_ctx_t *)src_ctx;