{"action":"created","issue":{"url":"https://api.github.com/repos/brndnmtthws/conky/issues/538","repository_url":"https://api.github.com/repos/brndnmtthws/conky","labels_url":"https://api.github.com/repos/brndnmtthws/conky/issues/538/labels{/name}","comments_url":"https://api.github.com/repos/brndnmtthws/conky/issues/538/comments","events_url":"https://api.github.com/repos/brndnmtthws/conky/issues/538/events","html_url":"https://github.com/brndnmtthws/conky/issues/538","id":343387299,"node_id":"MDU6SXNzdWUzNDMzODcyOTk=","number":538,"title":"is_on_battery not working correctly when laptop has 2 batteries","user":{"login":"intra-au","id":29102525,"node_id":"MDQ6VXNlcjI5MTAyNTI1","avatar_url":"https://avatars1.githubusercontent.com/u/29102525?v=4","gravatar_id":"","url":"https://api.github.com/users/intra-au","html_url":"https://github.com/intra-au","followers_url":"https://api.github.com/users/intra-au/followers","following_url":"https://api.github.com/users/intra-au/following{/other_user}","gists_url":"https://api.github.com/users/intra-au/gists{/gist_id}","starred_url":"https://api.github.com/users/intra-au/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/intra-au/subscriptions","organizations_url":"https://api.github.com/users/intra-au/orgs","repos_url":"https://api.github.com/users/intra-au/repos","events_url":"https://api.github.com/users/intra-au/events{/privacy}","received_events_url":"https://api.github.com/users/intra-au/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-22T08:14:48Z","updated_at":"2018-07-24T15:16:38Z","closed_at":null,"author_association":"NONE","body":"Hi, \r\n\r\nMy laptop has two batteries, I've wanted to use update_interval_on_battery and tried below config \r\n```\r\ndetect_battery = \"BAT0,BAT1\",\r\nupdate_interval_on_battery = 5.0,\r\n```\r\nWhat I found is Ubuntu's conky-all 1.10.8-1 doesn't have detect_battery yet so I've compiled latest code from git.\r\nI found that as soon as I try to use update_interval_on_battery conky quits with  conky: std::bad_alloc.\r\nAfter quick troubleshooting I found that existing is_on_battery function did not check the state of the second battery correctly and caused issues. I've updated the function to use slightly different approach to test each battery status and it works correctly for me. I've included it below:\r\n\r\n```\r\ntemplate<typename Out>\r\nvoid split(const std::string &s, char delim, Out result) {\r\n    std::stringstream ss(s);\r\n    std::string item;\r\n    while (std::getline(ss, item, delim)) {\r\n        *(result++) = item;\r\n    }\r\n}\r\n\r\nstd::vector<std::string> split(const std::string &s, char delim) {\r\n    std::vector<std::string> elems;\r\n    split(s, delim, std::back_inserter(elems));\r\n    return elems;\r\n}\r\n\r\nbool is_on_battery() {  // checks if at least one battery specified in\r\n                        // \"detect_battery\" is discharging\r\n  char buf[64];\r\n  std::vector<std::string> b_items = split(detect_battery.get(*state), ',');\r\n\r\n  for(auto const& value: b_items) {\r\n    get_battery_short_status(buf, 64, value.c_str());\r\n    if (buf[0] == 'D') { return true; }\r\n  }\r\n\r\n  return false;\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/brndnmtthws/conky/issues/comments/407444192","html_url":"https://github.com/brndnmtthws/conky/issues/538#issuecomment-407444192","issue_url":"https://api.github.com/repos/brndnmtthws/conky/issues/538","id":407444192,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNzQ0NDE5Mg==","user":{"login":"brndnmtthws","id":3129093,"node_id":"MDQ6VXNlcjMxMjkwOTM=","avatar_url":"https://avatars1.githubusercontent.com/u/3129093?v=4","gravatar_id":"","url":"https://api.github.com/users/brndnmtthws","html_url":"https://github.com/brndnmtthws","followers_url":"https://api.github.com/users/brndnmtthws/followers","following_url":"https://api.github.com/users/brndnmtthws/following{/other_user}","gists_url":"https://api.github.com/users/brndnmtthws/gists{/gist_id}","starred_url":"https://api.github.com/users/brndnmtthws/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brndnmtthws/subscriptions","organizations_url":"https://api.github.com/users/brndnmtthws/orgs","repos_url":"https://api.github.com/users/brndnmtthws/repos","events_url":"https://api.github.com/users/brndnmtthws/events{/privacy}","received_events_url":"https://api.github.com/users/brndnmtthws/received_events","type":"User","site_admin":false},"created_at":"2018-07-24T15:16:38Z","updated_at":"2018-07-24T15:16:38Z","author_association":"OWNER","body":"Would you like to open a PR with your change?"}}
{"actor":{"display_login":"brndnmtthws"}}