-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotify.cpp
57 lines (51 loc) · 1.31 KB
/
notify.cpp
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
// NOTIFYH20
//
// THIS IS A SIMPLE COMMAND LINE APPLICATION WHICH REMINDS THE USER TO DRINK WATER FREQUENTLY
//
// DEVELOPED BY: VIGNESHWAR K R
//
// FILE NAME: NOTIFY.CPP
// IMPORTING REQUIRED LIBRARIES
#include<libnotify/notify.h>
#include<iostream>
#include <string>
#include <chrono>
#include <thread>
#include <functional>
using namespace std;
// PLACE FOR USER CONFIGURABLE VARIABLES
//
// MESSAGE VARIABLE: THE MESSAGE CONTENT TO BE DISPLAYED
char message[] = "Drink some water now !!";
//
// INTERVAL VARIABLE: THE FREQUENCY OF THE NOTIFICATION (IN MINUTES)
int interval = 60;
// FUNCTION FOR HANDLING THE TIMER
void timer_start(std::function<void(void)> func, unsigned int interval)
{
std::thread([func, interval]() {
while (true)
{
func();
std::this_thread::sleep_for(std::chrono::milliseconds(interval));
}
}).detach();
}
// FUNCTION TO NOTIFY THE USER
void action()
{
notify_init("Message");
NotifyNotification* n = notify_notification_new("NotifyH2O",message,0);
notify_notification_set_timeout(n,0);
if(!notify_notification_show(n,0))
{
cerr<<"Show failed"<<endl;
}
}
// MAIN FUNCTION
int main(int argc, char * argv[])
{
interval = interval*60*1000;
timer_start(action, interval);
while(true);
}