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

Implement auto-update mechanism #120 #136

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/toniesJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

#include <stdint.h>
#include <stddef.h>
#if !defined(__WINDOWS__)
#include <unistd.h>
#else
#include <windows.h>
#endif
#include "error.h"

#define TEDDY_BENCH_AUDIO_ID_DEDUCT 0x50000000
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions src/toniesJson.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading