aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2019-12-04 02:06:56 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2019-12-04 02:06:56 +0100
commit3a781f925c170e56491897752aea448f4ea4bcf8 (patch)
tree845365531a4cbacd27cc61df89568ceb113c19a1
parentQuick update (diff)
downloadlowbat-gnu-3a781f925c170e56491897752aea448f4ea4bcf8.tar.gz
lowbat-gnu-3a781f925c170e56491897752aea448f4ea4bcf8.tar.bz2
lowbat-gnu-3a781f925c170e56491897752aea448f4ea4bcf8.tar.xz
lowbat-gnu-3a781f925c170e56491897752aea448f4ea4bcf8.tar.zst
lowbat-gnu-3a781f925c170e56491897752aea448f4ea4bcf8.zip
Better code, removed some leaks
-rw-r--r--src/jo_notify.cpp1
-rw-r--r--src/main.cpp23
2 files changed, 12 insertions, 12 deletions
diff --git a/src/jo_notify.cpp b/src/jo_notify.cpp
index 9f4c7de..1c54a40 100644
--- a/src/jo_notify.cpp
+++ b/src/jo_notify.cpp
@@ -7,7 +7,6 @@ jo_notify(const string batlvl) {
str = "notify-send \"Low battery: ";
str += batlvl;
str += "%\" \"Please plug in computer\" -u critical -t 15000";
-
return system(str.c_str());
}
diff --git a/src/main.cpp b/src/main.cpp
index 6590ed5..80fe04e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -15,17 +15,9 @@ int main(int argc, const char *argv[]) {
string arg_two;
int batlvlint;
- msg = "beep beep - low battery";
if (argc > 1) {
arg_one = argv[1];
- if (argc > 2)
- {
- arg_two = argv[2];
- if (!strcmp(arg_one.c_str(), "--say"))
- msg = arg_two;
- }
}
-
while (true) {
acstat = jo_exec("acpi | awk '{print $3}' | rev | cut -c 2- | rev");
batlvl = jo_exec("acpi | awk '{print $4}' | rev | cut -c 3- | rev");
@@ -35,9 +27,19 @@ int main(int argc, const char *argv[]) {
if (batlvlint < 90) {
while (!strcmp(acstat.c_str(), "Discharging")) {
jo_notify(batlvl);
- if (strcmp(arg_one.c_str(), "--silent"))
+ if (strcmp(arg_one.c_str(), "--silent")) {
+ if (argc > 2 && !strcmp(arg_one.c_str(), "--say")) {
+ arg_two = argv[2];
+ msg = arg_two;
+ }
+ else {
+ msg = "beep beep - low battery";
+ }
jo_speak(msg);
+ }
sleep_for(seconds(20));
+ acstat.clear();
+ batlvl.clear();
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());
@@ -46,7 +48,6 @@ int main(int argc, const char *argv[]) {
}
sleep_for(seconds(240));
}
- delete batlvl;
- delete acstat;
+
return 0;
}