fix: lint

This commit is contained in:
Alex 2022-10-17 09:19:00 +02:00
parent 58362abfaf
commit 8551c4bbe3
5 changed files with 110 additions and 55 deletions

57
ext4fuse.rb Normal file
View File

@ -0,0 +1,57 @@
class MacFuseRequirement < Requirement
fatal true
satisfy(build_env: false) { self.class.binary_mac_fuse_installed? }
def self.binary_mac_fuse_installed?
File.exist?("/usr/local/include/fuse/fuse.h") &&
!File.symlink?("/usr/local/include/fuse")
end
env do
ENV.append_path "PKG_CONFIG_PATH", HOMEBREW_LIBRARY/"Homebrew/os/mac/pkgconfig/fuse"
ENV.append_path "PKG_CONFIG_PATH", "/usr/local/lib/pkgconfig"
unless HOMEBREW_PREFIX.to_s == "/usr/local"
ENV.append_path "HOMEBREW_LIBRARY_PATHS", "/usr/local/lib"
ENV.append_path "HOMEBREW_INCLUDE_PATHS", "/usr/local/include/fuse"
end
end
def message
"macFUSE is required. Please run `brew install --cask macfuse` first."
end
end
class Ext4fuse < Formula
desc "Read-only implementation of ext4 for FUSE"
homepage "https://github.com/gerard/ext4fuse"
url "https://github.com/gerard/ext4fuse/archive/v0.1.3.tar.gz"
sha256 "550f1e152c4de7d4ea517ee1c708f57bfebb0856281c508511419db45aa3ca9f"
license "GPL-2.0"
head "https://github.com/gerard/ext4fuse.git"
bottle do
sha256 cellar: :any, catalina: "446dde5e84b058966ead0cde5e38e9411f465732527f6decfa1c0dcdbd4abbef"
sha256 cellar: :any, mojave: "88c4918bf5218f99295e539fe4499152edb3b60b6659e44ddd68b22359f512ae"
sha256 cellar: :any, high_sierra: "fc69c8993afd0ffc16a73c9c036ca8f83c77ac2a19b3237f76f9ccee8b30bbc9"
sha256 cellar: :any, sierra: "fe8bbe7cd5362f00ff06ef750926bf349d60563c20b0ecf212778631c8912ba2"
sha256 cellar: :any, el_capitan: "291047c821b7b205d85be853fb005510c6ab01bd4c2a2193c192299b6f049d35"
sha256 cellar: :any, yosemite: "b11f564b7e7c08af0b0a3e9854973d39809bf2d8a56014f4882772b2f7307ac1"
end
depends_on "pkg-config" => :build
on_macos do
depends_on MacFuseRequirement => :build
end
on_linux do
depends_on "libfuse"
end
def install
system "make"
bin.install "ext4fuse"
end
end

View File

@ -56,11 +56,10 @@ struct formatter<pow_format> {
fraction /= base;
}
auto number_width = 5 // coeff in {:.1f} format
+ s.binary_; // potential 4th digit before the decimal point
auto max_width = number_width
+ 1 // prefix from units array
+ s.binary_ // for the 'i' in GiB.
auto number_width = 5 // coeff in {:.1f} format
+ s.binary_; // potential 4th digit before the decimal point
auto max_width = number_width + 1 // prefix from units array
+ s.binary_ // for the 'i' in GiB.
+ s.unit_.length();
const char* format;

View File

@ -156,7 +156,7 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
std::lock_guard<std::mutex> guard(battery_list_mutex_);
try {
uint32_t total_power = 0; // μW
uint32_t total_power = 0; // μW
bool total_power_exists = false;
uint32_t total_energy = 0; // μWh
bool total_energy_exists = false;
@ -179,28 +179,28 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
uint32_t capacity = 0;
bool capacity_exists = false;
if (fs::exists(bat / "capacity")) {
capacity_exists = true;
std::ifstream(bat / "capacity") >> capacity;
capacity_exists = true;
std::ifstream(bat / "capacity") >> capacity;
}
uint32_t current_now = 0;
bool current_now_exists = false;
if (fs::exists(bat / "current_now")) {
current_now_exists = true;
std::ifstream(bat / "current_now") >> current_now;
current_now_exists = true;
std::ifstream(bat / "current_now") >> current_now;
} else if (fs::exists(bat / "current_avg")) {
current_now_exists = true;
std::ifstream(bat / "current_avg") >> current_now;
current_now_exists = true;
std::ifstream(bat / "current_avg") >> current_now;
}
uint32_t voltage_now = 0;
bool voltage_now_exists = false;
if (fs::exists(bat / "voltage_now")) {
voltage_now_exists = true;
std::ifstream(bat / "voltage_now") >> voltage_now;
voltage_now_exists = true;
std::ifstream(bat / "voltage_now") >> voltage_now;
} else if (fs::exists(bat / "voltage_avg")) {
voltage_now_exists = true;
std::ifstream(bat / "voltage_avg") >> voltage_now;
voltage_now_exists = true;
std::ifstream(bat / "voltage_avg") >> voltage_now;
}
uint32_t charge_full = 0;
@ -229,14 +229,14 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
if (fs::exists(bat / "power_now")) {
power_now_exists = true;
std::ifstream(bat / "power_now") >> power_now;
}
}
uint32_t energy_now = 0;
bool energy_now_exists = false;
if (fs::exists(bat / "energy_now")) {
energy_now_exists = true;
std::ifstream(bat / "energy_now") >> energy_now;
}
}
uint32_t energy_full = 0;
bool energy_full_exists = false;
@ -256,7 +256,8 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
if (power_now_exists && current_now_exists && current_now != 0) {
voltage_now_exists = true;
voltage_now = 1000000 * (uint64_t)power_now / (uint64_t)current_now;
} else if (energy_full_design_exists && charge_full_design_exists && charge_full_design != 0) {
} else if (energy_full_design_exists && charge_full_design_exists &&
charge_full_design != 0) {
voltage_now_exists = true;
voltage_now = 1000000 * (uint64_t)energy_full_design / (uint64_t)charge_full_design;
} else if (energy_now_exists) {
@ -268,9 +269,10 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
charge_now = (uint64_t)charge_full * (uint64_t)capacity / 100;
if (charge_full != 0 && capacity != 0) {
voltage_now_exists = true;
voltage_now = 1000000 * (uint64_t)energy_now * 100 / (uint64_t)charge_full / (uint64_t)capacity;
voltage_now =
1000000 * (uint64_t)energy_now * 100 / (uint64_t)charge_full / (uint64_t)capacity;
}
}
}
} else if (energy_full_exists) {
if (charge_full_exists && charge_full != 0) {
voltage_now_exists = true;
@ -282,7 +284,8 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
}
if (charge_now != 0) {
voltage_now_exists = true;
voltage_now = 10000 * (uint64_t)energy_full * (uint64_t)capacity / (uint64_t)charge_now;
voltage_now =
10000 * (uint64_t)energy_full * (uint64_t)capacity / (uint64_t)charge_now;
}
}
}
@ -311,7 +314,8 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
}
if (voltage_now != 0 && charge_full != 0) {
capacity_exists = true;
capacity = 100 * 1000000 * (uint64_t)energy_now / (uint64_t)voltage_now / (uint64_t)charge_full;
capacity = 100 * 1000000 * (uint64_t)energy_now / (uint64_t)voltage_now /
(uint64_t)charge_full;
}
}
}
@ -324,7 +328,8 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
charge_now_exists = true;
charge_now = (uint64_t)capacity * (uint64_t)charge_full / 100;
energy_now_exists = true;
energy_now = (uint64_t)voltage_now * (uint64_t)capacity * (uint64_t)charge_full / 1000000 / 100;
energy_now =
(uint64_t)voltage_now * (uint64_t)capacity * (uint64_t)charge_full / 1000000 / 100;
} else if (capacity_exists && energy_full) {
if (voltage_now != 0) {
charge_full_exists = true;
@ -334,7 +339,7 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
}
energy_now_exists = true;
energy_now = (uint64_t)capacity * (uint64_t)energy_full / 100;
}
}
}
if (!energy_full_exists && voltage_now_exists) {
@ -356,7 +361,8 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
energy_full = 100 * (uint64_t)energy_now / (uint64_t)capacity;
if (voltage_now != 0) {
charge_full_exists = true;
charge_full = 100 * 1000000 * (uint64_t)energy_now / (uint64_t)voltage_now / (uint64_t)capacity;
charge_full =
100 * 1000000 * (uint64_t)energy_now / (uint64_t)voltage_now / (uint64_t)capacity;
}
}
}
@ -373,8 +379,7 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
}
// Show the "smallest" status among all batteries
if (status_gt(status, _status))
status = _status;
if (status_gt(status, _status)) status = _status;
if (power_now_exists) {
total_power_exists = true;
@ -403,20 +408,19 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
std::string current_status;
std::ifstream(adapter_ / "online") >> online;
std::getline(std::ifstream(adapter_ / "status"), current_status);
if (online && current_status != "Discharging")
status = "Plugged";
if (online && current_status != "Discharging") status = "Plugged";
}
float time_remaining{0.0f};
if (status == "Discharging" && total_power_exists && total_energy_exists) {
if (total_power != 0)
time_remaining = (float)total_energy / total_power;
} else if (status == "Charging" && total_energy_exists && total_energy_full_exists && total_power_exists) {
if (total_power != 0) time_remaining = (float)total_energy / total_power;
} else if (status == "Charging" && total_energy_exists && total_energy_full_exists &&
total_power_exists) {
if (total_power != 0)
time_remaining = -(float)(total_energy_full - total_energy) / total_power;
// If we've turned positive it means the battery is past 100% and so just report that as no time remaining
if (time_remaining > 0.0f)
time_remaining = 0.0f;
// If we've turned positive it means the battery is past 100% and so just report that as no
// time remaining
if (time_remaining > 0.0f) time_remaining = 0.0f;
}
float calculated_capacity{0.0f};
@ -428,9 +432,10 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
calculated_capacity = ((float)total_energy * 100.0f / (float)total_energy_full);
}
}
// Handle design-capacity
if ((config_["design-capacity"].isBool() ? config_["design-capacity"].asBool() : false) && total_energy_exists && total_energy_full_design_exists) {
if ((config_["design-capacity"].isBool() ? config_["design-capacity"].asBool() : false) &&
total_energy_exists && total_energy_full_design_exists) {
if (total_energy_full_design > 0.0f)
calculated_capacity = ((float)total_energy * 100.0f / (float)total_energy_full_design);
}
@ -438,19 +443,17 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
// Handle full-at
if (config_["full-at"].isUInt()) {
auto full_at = config_["full-at"].asUInt();
if (full_at < 100)
calculated_capacity = 100.f * calculated_capacity / full_at;
if (full_at < 100) calculated_capacity = 100.f * calculated_capacity / full_at;
}
// Handle it gracefully by clamping at 100%
// This can happen when the battery is calibrating and goes above 100%
if (calculated_capacity > 100.f)
calculated_capacity = 100.f;
if (calculated_capacity > 100.f) calculated_capacity = 100.f;
uint8_t cap = round(calculated_capacity);
// If we've reached 100% just mark as full as some batteries can stay stuck reporting they're still charging but not yet done
if (cap == 100 && status == "Charging")
status = "Full";
// If we've reached 100% just mark as full as some batteries can stay stuck reporting they're
// still charging but not yet done
if (cap == 100 && status == "Charging") status = "Full";
return {cap, time_remaining, status, total_power / 1e6};
} catch (const std::exception& e) {

View File

@ -16,10 +16,8 @@ waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar&
throw std::runtime_error("idle-inhibit not available");
}
if (waybar::modules::IdleInhibitor::modules.empty()
&& config_["start-activated"].isBool()
&& config_["start-activated"].asBool() != status
) {
if (waybar::modules::IdleInhibitor::modules.empty() && config_["start-activated"].isBool() &&
config_["start-activated"].asBool() != status) {
toggleStatus();
}

View File

@ -104,8 +104,7 @@ bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll *e) {
if (volume_ < max_volume) {
if (volume_ + step > max_volume) {
change = round((max_volume - volume_) * volume_tick);
}
else {
} else {
change = round(step * volume_tick);
}
pa_cvolume_inc(&pa_volume, change);
@ -114,8 +113,7 @@ bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll *e) {
if (volume_ > 0) {
if (volume_ - step < 0) {
change = round(volume_ * volume_tick);
}
else {
} else {
change = round(step * volume_tick);
}
pa_cvolume_dec(&pa_volume, change);
@ -186,7 +184,7 @@ void waybar::modules::Pulseaudio::sinkInfoCb(pa_context * /*context*/, const pa_
auto pa = static_cast<waybar::modules::Pulseaudio *>(data);
if (pa->config_["ignored-sinks"].isArray()) {
for (const auto& ignored_sink : pa->config_["ignored-sinks"]) {
for (const auto &ignored_sink : pa->config_["ignored-sinks"]) {
if (ignored_sink.asString() == i->description) {
return;
}