Skip to content

Commit

Permalink
REF: Make is_on_ac_power() less verbose
Browse files Browse the repository at this point in the history
The status is already reported by `on_check_battery_powered()`.
Should be ok for newer kernels and should avoid scaring users.
Closes #14
  • Loading branch information
kernc committed May 10, 2020
1 parent 4e44970 commit b73f837
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,16 @@ is_on_ac_power ()
g_autoptr (GDir) dir = g_dir_open (DIRNAME, 0, &err);

if (err) {
g_warning ("Cannot read battery status: %s", err->message);
g_warning ("Cannot read battery/AC status: %s", err->message);
return FALSE;
}

while ((basename = g_dir_read_name (dir))) {
g_autofree char *filename = g_build_filename (DIRNAME, basename, "online", NULL);
g_autofree char *contents = NULL;

g_debug ("Reading '%s'", filename);
if (! g_file_get_contents (filename, &contents, NULL, &err)) {
g_debug ("Cannot read '%s': %s", filename, err->message);
if (! g_file_get_contents (filename, &contents, NULL, NULL))
continue;
}

if (g_strcmp0 (g_strstrip (contents), "1") == 0)
return TRUE;
Expand Down

0 comments on commit b73f837

Please sign in to comment.