aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jo_notify.cpp2
-rw-r--r--src/main.cpp30
2 files changed, 21 insertions, 11 deletions
diff --git a/src/jo_notify.cpp b/src/jo_notify.cpp
index 154b0b7..9f4c7de 100644
--- a/src/jo_notify.cpp
+++ b/src/jo_notify.cpp
@@ -4,7 +4,7 @@ int
jo_notify(const string batlvl) {
string str;
- str = "notify-send \"";
+ str = "notify-send \"Low battery: ";
str += batlvl;
str += "%\" \"Please plug in computer\" -u critical -t 15000";
diff --git a/src/main.cpp b/src/main.cpp
index 71f7147..69d4ef5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -8,13 +8,25 @@ using namespace this_thread;
using namespace chrono;
int main(int argc, const char *argv[]) {
- string msg;
- string acstat;
- string batlvl;
- int batlvlint;
+ string msg;
+ string acstat;
+ string batlvl;
+ string arg_one;
+ string arg_two;
+ int batlvlint;
- if (argc > 1 && !memcmp(argv[1], "--say", strlen(argv[1])))
- msg = argv[2];
+ if (argc > 1) {
+ arg_one = argv[1];
+ if (argc > 2)
+ {
+ arg_two = argv[2];
+ if (!memcmp(arg_one.c_str(), "--say", strlen("--say")))
+ msg = arg_two;
+ }
+ }
+ else {
+ msg = "Beep beep - low battery";
+ }
while (true) {
acstat = jo_exec("acpi | awk '{print $3}' | rev | cut -c 2- | rev");
@@ -23,17 +35,15 @@ int main(int argc, const char *argv[]) {
batlvl.erase(remove(batlvl.begin(), batlvl.end(), '\n'), batlvl.end());
batlvlint = stoi(batlvl);
if (batlvlint < 90) {
- while (!memcmp(acstat.c_str(), "Discharging", strlen(acstat.c_str()))) {
+ while (!memcmp(acstat.c_str(), "Discharging", strlen("Discharging"))) {
jo_notify(batlvl);
- if (memcmp(argv[1], "--silent", strlen(argv[1])))
+ if (memcmp(arg_one.c_str(), "--silent", strlen("--silent")))
jo_speak(msg);
sleep_for(seconds(20));
acstat = jo_exec("acpi | awk '{print $3}' | rev | cut -c 2- | rev");
batlvl = jo_exec("acpi | awk '{print $4}' | rev | cut -c 3- | rev");
acstat.erase(remove(acstat.begin(), acstat.end(), '\n'), acstat.end());
batlvl.erase(remove(batlvl.begin(), batlvl.end(), '\n'), batlvl.end());
- if (!memcmp(acstat.c_str(), "Charging", strlen(acstat.c_str())))
- break ;
}
}
sleep_for(seconds(240));