Skip to content

Commit 3a321d9

Browse files
authored
Merge pull request #4982 from Mrpaoo/bug-fix
fix the io failure for hotplug-in device
2 parents 202ae4b + ac62754 commit 3a321d9

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/modules/battery.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,14 @@ void waybar::modules::Battery::refreshBatteries() {
126126
// Ignore non-system power supplies unless explicitly requested
127127
if (!bat_defined && fs::exists(node.path() / "scope")) {
128128
std::string scope;
129-
std::ifstream(node.path() / "scope") >> scope;
129+
try {
130+
// for hotplug-in device, access it is always unstable because you may remove the
131+
// device anytime so just allow failure happen and do nothing
132+
std::ifstream(node.path() / "scope") >> scope;
133+
} catch (const std::ifstream::failure& e) {
134+
scope.clear();
135+
continue;
136+
}
130137
if (g_ascii_strcasecmp(scope.data(), "device") == 0) {
131138
continue;
132139
}

0 commit comments

Comments
 (0)