chore: make pre-commit resilient when cargo absent

This commit is contained in:
jasonwitty 2025-08-26 00:18:10 -07:00
parent c9ebea92f5
commit 3394beab67
2 changed files with 17 additions and 6 deletions

15
.githooks/pre-commit Normal file → Executable file
View File

@ -1,11 +1,22 @@
#!/usr/bin/env bash
# This repository uses a custom hooks directory (.githooks). To enable this pre-commit hook run:
# git config core.hooksPath .githooks
# Ensure this file is executable: chmod +x .githooks/pre-commit
set -euo pipefail
echo "[pre-commit] Running cargo fmt --all" >&2
if ! command -v cargo >/dev/null 2>&1; then
echo "[pre-commit] cargo not found in PATH" >&2
exit 1
# Try loading rustup environment (common install path)
if [ -f "$HOME/.cargo/env" ]; then
# shellcheck source=/dev/null
. "$HOME/.cargo/env"
fi
fi
if ! command -v cargo >/dev/null 2>&1; then
echo "[pre-commit] cargo not found in PATH; skipping fmt (install Rust or adjust PATH)." >&2
exit 0
fi
cargo fmt --all

View File

@ -476,8 +476,8 @@ pub async fn collect_processes_all(state: &AppState) -> ProcessesPayload {
}
})
.collect();
// Automatic scaling (enabled by default): if sum of per-process CPU exceeds global
// CPU by >5%, scale all process CPU values proportionally so the sum matches global.
// Automatic scaling (enabled by default): if sum of per-process CPU exceeds global
// CPU by >5%, scale all process CPU values proportionally so the sum matches global.
if std::env::var("SOCKTOP_AGENT_SCALE_PROC_CPU")
.map(|v| v != "0")
.unwrap_or(true)
@ -486,8 +486,8 @@ pub async fn collect_processes_all(state: &AppState) -> ProcessesPayload {
let global = sys.global_cpu_usage();
if sum > 0.0 && global > 0.0 {
let scale = global / sum;
if scale < 0.95 {
// only scale if we're at least 5% over
if scale < 0.95 {
// only scale if we're at least 5% over
for p in &mut list {
p.cpu_usage = (p.cpu_usage * scale).clamp(0.0, 100.0);
}