-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathnotify.c
124 lines (108 loc) · 4.28 KB
/
notify.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
// . . .
// | | | .
// ,-. ,-. |-. ,-. . ,-. | ,_, ,-. ,-. |-. ,-,-. . |- ,_,
// | | ,-| | | | | |-' | / `-. | | | | | | | | /
// `-| `-^ ^-' ' ' `-' `' '"' `-' `-' ' ' ' ' ' ' `' '"'
// ,|
// `'
// notify.c
*/
#include "notify.h"
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
/* Send a notification with sound */
void notify(const char *message) {
/* Autostart work notification */
if (strcmp(message, "autostartwork") == 0) {
if (strcmp(ICONS, "nerdicons") == 0 && WSL == 0)
send_notification(" A pomodoro has ended!",
"Unpause to start the pause");
else if (strcmp(ICONS, "iconson") == 0 && WSL == 0)
send_notification("🔄 A pomodoro has ended!",
"Unpause to start the pause");
else
send_notification("A pomodoro has ended!", "Unpause to start the pause");
play_audio("/usr/local/share/tomato/sounds/dfltnotify.mp3");
}
/* Autostart pause notification */
else if (strcmp(message, "autostartpause") == 0) {
if (strcmp(ICONS, "nerdicons") == 0 && WSL == 0)
send_notification(" A pause has ended!", "Unpause to continue");
else if (strcmp(ICONS, "iconson") == 0 && WSL == 0)
send_notification("🔄 A pause has ended!", "Unpause to continue");
else
send_notification("A pause has ended!", "Unpause to continue");
play_audio("/usr/local/share/tomato/sounds/pausenotify.mp3");
}
/* Work notification */
else if (strcmp(message, "worktime") == 0) {
if (strcmp(ICONS, "nerdicons") == 0 && WSL == 0)
send_notification(" Work!", "You need to focus");
else if (strcmp(ICONS, "iconson") == 0 && WSL == 0)
send_notification("👷 Work!", "You need to focus");
else
send_notification("Work!", "You need to focus!");
play_audio("/usr/local/share/tomato/sounds/dfltnotify.mp3");
}
/* Short Pause notification */
else if (strcmp(message, "shortpause") == 0) {
if (strcmp(ICONS, "nerdicons") == 0)
send_notification(" Pause Break", "You have some time to chill");
else if (strcmp(ICONS, "iconson") == 0)
send_notification("☕ Pause Break", "You have some time to chill");
else
send_notification("Pause Break", "You have some time to chill");
play_audio("/usr/local/share/tomato/sounds/pausenotify.mp3");
}
/* Long Pause notification */
else if (strcmp(message, "longpause") == 0) {
if (strcmp(ICONS, "nerdicons") == 0 && WSL == 0)
send_notification(" Long Pause Break", "You have some time to chill");
else if (strcmp(ICONS, "iconson") == 0 && WSL == 0)
send_notification("🌴 Long Pause Break", "You have some time to chill");
else
send_notification("Long Pause Break", "You have some time to chill");
play_audio("/usr/local/share/tomato/sounds/pausenotify.mp3");
}
/* End of cycle notification */
else {
if (strcmp(ICONS, "nerdicons") == 0 && WSL == 0)
send_notification(" End of Pomodoro Cycle",
"Feel free to start another!");
else if (strcmp(ICONS, "iconson") == 0 && WSL == 0)
send_notification("🍅 End of Pomodoro Cycle",
"Feel free to start another!");
else
send_notification("End of Pomodoro Cycle", "Feel free to start another!");
play_audio("/usr/local/share/tomato/sounds/endnotify.mp3");
}
}
void send_notification(char *title, char *description) {
if (NOTIFY == 0) return;
int max_command_length = 256;
const char *command[max_command_length];
#ifdef __APPLE__
snprintf((char *)command, max_command_length,
"osascript -e \'display notification \"%s\" with title \"%s\"\'",
title, description);
#else
snprintf((char *)command, max_command_length,
"notify-send -t 5000 -a Tomato.C \"%s\" \"%s\" ", title,
description);
#endif
(void)system((char *)command);
}
void play_audio(char *record_path) {
if (SOUND == 1 && WSL == 0) {
int max_audio_cmd_length = 256;
char *command[max_audio_cmd_length];
snprintf((char *)command, max_audio_cmd_length,
"mpv --no-vid --no-input-terminal --volume=50 %s --really-quiet &",
record_path);
(void)system((char *)command);
}
}