2020-12-10 18:06:24 +01:00
|
|
|
|
#include "notify.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define LOG_MODULE "notify"
|
|
|
|
|
|
#define LOG_ENABLE_DBG 0
|
|
|
|
|
|
#include "log.h"
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
#include "spawn.h"
|
|
|
|
|
|
#include "xmalloc.h"
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
notify_notify(const struct terminal *term, const char *title, const char *body)
|
|
|
|
|
|
{
|
2021-01-31 10:26:36 +01:00
|
|
|
|
LOG_DBG("notify: title=\"%s\", msg=\"%s\"", title, body);
|
2020-12-10 18:06:24 +01:00
|
|
|
|
|
2020-12-10 18:07:50 +01:00
|
|
|
|
if (term->kbd_focus) {
|
|
|
|
|
|
/* No notifications while we’re focused */
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-10 18:06:24 +01:00
|
|
|
|
if (title == NULL || body == NULL)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (term->conf->notify.argv == NULL)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2021-01-31 14:40:27 +01:00
|
|
|
|
char **argv = NULL;
|
|
|
|
|
|
size_t argc = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (!spawn_expand_template(
|
2021-05-27 11:41:57 +02:00
|
|
|
|
&term->conf->notify, 3,
|
|
|
|
|
|
(const char *[]){"app-id", "title", "body"},
|
|
|
|
|
|
(const char *[]){term->conf->app_id, title, body},
|
2021-01-31 14:40:27 +01:00
|
|
|
|
&argc, &argv))
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
2020-12-10 18:06:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LOG_DBG("notify command:");
|
2021-01-31 14:40:27 +01:00
|
|
|
|
for (size_t i = 0; i < argc; i++)
|
2020-12-10 18:06:24 +01:00
|
|
|
|
LOG_DBG(" argv[%zu] = \"%s\"", i, argv[i]);
|
|
|
|
|
|
|
|
|
|
|
|
/* Redirect stdin to /dev/null, but ignore failure to open */
|
|
|
|
|
|
int devnull = open("/dev/null", O_RDONLY);
|
|
|
|
|
|
spawn(term->reaper, NULL, argv, devnull, -1, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (devnull >= 0)
|
|
|
|
|
|
close(devnull);
|
|
|
|
|
|
|
2021-01-31 14:40:27 +01:00
|
|
|
|
for (size_t i = 0; i < argc; i++)
|
2020-12-10 18:06:24 +01:00
|
|
|
|
free(argv[i]);
|
|
|
|
|
|
free(argv);
|
|
|
|
|
|
}
|