fixing ui stuff

This commit is contained in:
Joren de Graaf
2026-10-09 19:10:42 +02:00
parent dad0001df1
commit 2b0bbdd201
12 changed files with 175 additions and 27 deletions
+50 -3
View File
@@ -25,6 +25,18 @@ static uint32_t metaChecksum(const BoomEventMeta& meta) {
return hash;
}
static bool queuedToday(const BoomEventMeta& meta) {
// queuedMs records when the clip was saved and the "today" count increased.
// Older recordings without a valid clock cannot be dated reliably; the
// owner can use the explicit counter reset for those legacy clips.
if (!meta.queuedMs) return false;
time_t recordedAt = meta.queuedMs / 1000;
time_t now = time(nullptr);
struct tm recorded = {}, current = {};
return localtime_r(&recordedAt, &recorded) && localtime_r(&now, &current) &&
recorded.tm_year == current.tm_year && recorded.tm_yday == current.tm_yday;
}
static bool writeAll(FILE* f, const void* data, size_t bytes) {
return fwrite(data, 1, bytes, f) == bytes;
}
@@ -199,13 +211,48 @@ size_t BoomQueue::fileSize(const String& filename) const {
bool BoomQueue::remove(const String& filename) {
if (!ready_ || !exists(filename)) return false;
String meta = absolutePath(filename); meta.remove(meta.length() - 4); meta += ".meta";
if (unlink(meta.c_str()) != 0) return false;
bool ok = unlink(absolutePath(filename).c_str()) == 0;
bool ok = removeFiles(filename);
refreshCount();
return ok;
}
bool BoomQueue::discard(const String& filename) {
BoomEventMeta meta;
if (!ready_ || !readMeta(filename, meta)) return false;
bool today = queuedToday(meta);
bool ok = removeFiles(filename);
refreshCount();
if (ok && today) boomState.discardTodayEvents(1);
return ok;
}
bool BoomQueue::removeFiles(const String& filename) {
String meta = absolutePath(filename); meta.remove(meta.length() - 4); meta += ".meta";
if (unlink(meta.c_str()) != 0) return false;
return unlink(absolutePath(filename).c_str()) == 0;
}
int BoomQueue::clearAll() {
if (!ready_) return -1;
int removed = 0;
int todayRemoved = 0;
String batch[MAX_QUEUE_ITEMS_SHOWN];
size_t found;
while ((found = listNames(batch, MAX_QUEUE_ITEMS_SHOWN)) != 0) {
for (size_t i = 0; i < found; ++i) {
BoomEventMeta meta;
if (!readMeta(batch[i], meta)) { refreshCount(); boomState.discardTodayEvents(todayRemoved); return -1; }
bool today = queuedToday(meta);
if (!removeFiles(batch[i])) { refreshCount(); boomState.discardTodayEvents(todayRemoved); return -1; }
++removed;
if (today) ++todayRemoved;
}
}
refreshCount();
boomState.discardTodayEvents(todayRemoved);
return removed;
}
size_t BoomQueue::listNames(String* out, size_t maxItems) {
if (!ready_ || !out || !maxItems) return 0;
DIR* dir = opendir(QUEUE_DIR); if (!dir) return 0;