From 58ee60be9de472ee9d7558e64f23fb53e4d8cb4e Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 29 Dec 2019 17:59:11 +0100 Subject: Starting to look good --- src/jo_lowbat.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/jo_lowbat.cpp') diff --git a/src/jo_lowbat.cpp b/src/jo_lowbat.cpp index 96686e5..f4c3b2e 100644 --- a/src/jo_lowbat.cpp +++ b/src/jo_lowbat.cpp @@ -15,8 +15,17 @@ Lowbat::jo_testAcpi(void) { return 0; } +int +Lowbat::jo_fetchBatlvl(void) { + cout << "Fetching batlvl: "; + m_batlvl = Lowbat::jo_exec("acpi | awk '{print $4}' | rev | cut -c 3- | rev"); + m_batlvl.erase(remove(m_batlvl.begin(), m_batlvl.end(), '\n'), m_batlvl.end()); + cout << m_batlvl << "%" << endl; + return(stoi(m_batlvl)); +} + string -jo_exec(const char* cmd) { +Lowbat::jo_exec(const char* cmd) { array buffer; string result; unique_ptr pipe(popen(cmd, "r"), pclose); @@ -29,15 +38,13 @@ jo_exec(const char* cmd) { return result; } -string -Lowbat::jo_fetchBatlvl(void) { - string batlvl; - uint8_t batlvlint; +int +Lowbat::jo_notify(void) { + string str; - cout << "Fetching batlvl: "; - batlvl = Lowbat::jo_exec("acpi | awk '{print $4}' | rev | cut -c 3- | rev"); - batlvl.erase(remove(batlvl.begin(), batlvl.end(), '\n'), batlvl.end()); - batlvlint = stoi(batlvl); - cout << batlvlint << "%" << endl; - return (batlvl); + str = "notify-send \"Low battery: "; + str += m_batlvl; + str += "%\" \"Please plug in computer\" -u critical -t 15000"; + cout << "Notifying" << endl; + return system(str.c_str()); } -- cgit v1.2.3