2023-07-16 10:19:36 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2023-07-16 11:07:04 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
2023-07-16 10:19:36 +02:00
|
|
|
|
|
|
|
#include "main/include/colors.h"
|
|
|
|
#include "main/include/config.h"
|
2023-07-16 11:07:04 +02:00
|
|
|
#include "main/include/tasks.h"
|
2023-07-16 10:19:36 +02:00
|
|
|
#include "main/include/db.h"
|
|
|
|
|
|
|
|
#include "log/log.h"
|
|
|
|
|
2023-07-16 11:07:04 +02:00
|
|
|
task_t next_task(task_list_t* tasks) {
|
|
|
|
time_t now = time(0);
|
|
|
|
|
|
|
|
task_t next;
|
|
|
|
next.due_to = 0;
|
|
|
|
|
|
|
|
task_list_t* cur = tasks;
|
|
|
|
|
|
|
|
while (cur) {
|
|
|
|
task_t t = cur->task;
|
|
|
|
|
|
|
|
if (!t.done && (difftime(now, t.due_to) <= 0 || t.due_to == 0)) { // La tâche a une échéance, qui n'est pas passée
|
|
|
|
if (next.due_to == 0 || difftime(next.due_to, t.due_to) >= 0) {
|
|
|
|
next = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
2023-07-16 10:19:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
log_info("TaKl " VERSION " -- Daemon started");
|
2023-07-16 11:07:04 +02:00
|
|
|
|
|
|
|
task_list_t* tasks = get_task_list(false);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
task_t next = next_task(tasks);
|
|
|
|
|
|
|
|
if (next.due_to == 0) {
|
|
|
|
log_fatal("Plus de tâches avec échéance dans la liste");
|
|
|
|
free_task_list(tasks);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
time_t now = time(0);
|
|
|
|
double wait = difftime(next.due_to, now) + 5;
|
|
|
|
log_debug("Attente de %0.1lfs", wait);
|
|
|
|
sleep(wait);
|
|
|
|
|
|
|
|
log_debug("Envoi de la notification tâche [%d]", next.id);
|
|
|
|
desktop_notification(next);
|
|
|
|
//! si deux tâches sont à la même date à moins de 0.1s près,
|
|
|
|
//! l'une des deux seulement sera affichée
|
|
|
|
}
|
2023-07-16 10:19:36 +02:00
|
|
|
|
2023-07-16 11:07:04 +02:00
|
|
|
free_task_list(tasks);
|
2023-07-16 10:19:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|