Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
7d77b2d401 | |||
d0478ba7c8 | |||
4b327cab48 | |||
4fd33bfe66 | |||
259afcf567 | |||
903b6f61da | |||
76764a88ce | |||
4cf1ae41b7 | |||
96db20aebc | |||
45b153e5ce |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1 @@
|
||||
/target
|
||||
/pkg/
|
||||
/src/pumopm-git/
|
||||
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -393,7 +393,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pumopm"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"battery",
|
||||
"clap",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "pumopm"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
authors = ["Lucien Cartier-Tilet <lucien@phundrak.com>"]
|
||||
edition = "2018"
|
||||
description = "Simple power manager for systemd-based Linux"
|
||||
|
3
arch-pkg/.gitignore
vendored
Normal file
3
arch-pkg/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
*
|
||||
.gitignore
|
||||
!PKGBUILD
|
@ -1,6 +1,6 @@
|
||||
# Maintainer: Lucien Cartier-Tilet <lucien@phundrak.com>
|
||||
pkgname=pumopm-git
|
||||
pkgver=.r0.4e2acb9
|
||||
pkgver=0.1.1.r1.g4fd33bf
|
||||
pkgrel=1
|
||||
pkgdesc="A tiny power manager written in Rust"
|
||||
arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')
|
||||
@ -8,15 +8,16 @@ url="https://labs.phundrak.com/phundrak/pumopm"
|
||||
license=('GPL3')
|
||||
depends=()
|
||||
makedepends=('rustup' 'git')
|
||||
options=()
|
||||
source=("$pkgname::git+https://github.com/phundrak/pumopm")
|
||||
options=('strip' 'zipman')
|
||||
source=("$pkgname::git+https://labs.phundrak.com/phundrak/pumopm.git")
|
||||
md5sums=('SKIP')
|
||||
# If Phundrak’s Gitea takes too long to answer, or if it is down, use the
|
||||
# Github mirror
|
||||
# source=("$pkgname}::git+https://github.com/Phundrak/pumopm.git")
|
||||
|
||||
pkgver() {
|
||||
cd "$pkgname"
|
||||
local tag=$(git tag --sort=-v:refname | grep '^[0-9]' | head -1)
|
||||
local commits_since=$(git rev-list $tag..HEAD --count)
|
||||
echo "$tag.r$commits_since.$(git log --pretty=format:'%h' -n 1)"
|
||||
cd "$pkgname"
|
||||
git describe --tags --long | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
|
||||
}
|
||||
|
||||
build() {
|
||||
@ -32,9 +33,10 @@ build() {
|
||||
|
||||
package() {
|
||||
cd "$pkgname"
|
||||
|
||||
install -Dm755 "target/release/pumopm" "$pkgdir/usr/bin/pumopm"
|
||||
install -Dm644 "LICENSE" "$pkgdir/usr/share/licenses/${pkgname}/LICENSE"
|
||||
install -Dm644 "pumopm.1" "$pkgdir/usr/share/man/man1/pumopm.1"
|
||||
install -Dm644 "pumopm.service" "$pkgdir/usr/lib/systemd/system/pumopm.service"
|
||||
}
|
||||
|
||||
# vim:set ts=2 sw=2 et:
|
49
pumopm.1
Normal file
49
pumopm.1
Normal file
@ -0,0 +1,49 @@
|
||||
\" -*- mode: nroff; -*-
|
||||
.TH PUMOPM 1 pumopm
|
||||
.SH NAME
|
||||
pumopm \- simple, small, no bloat power manager
|
||||
.SH SYNOPSIS
|
||||
.B pumopm
|
||||
.RB [-h\ --help]
|
||||
.RB [-V\ --version]
|
||||
.RB [-l\ --low\ 5-95]
|
||||
.RB [-L\ --very-low\ 5-95]
|
||||
.RB [-c\ --critical\ 5-95]
|
||||
.RB [-r\ --refresh-rate\ <seconds>]
|
||||
.RB [-v\ --verbose]
|
||||
.SH DESCRIPTIOR
|
||||
pumopm is a simple, small, no bloat power manager written by Phundrak in
|
||||
an attempt to create a power manager that is small, simple, and does
|
||||
exactly what he wants to do: warn about low, very low, and critical
|
||||
battery levels before suspending the computer.
|
||||
.SH FLAGS
|
||||
.TP
|
||||
.B \-h \-\-help
|
||||
Prints help information
|
||||
.TP
|
||||
.B \-v \-\-verbose
|
||||
Prints verbose information
|
||||
.TP
|
||||
.B \-V \-\-version
|
||||
Prints version information
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-l \-\-low <value>
|
||||
Level at which the battery is considered to be low. Value between 5 and
|
||||
95. Default 25
|
||||
.TP
|
||||
.B \-L \-\-very-low <value>
|
||||
level at which the battery is considered to be very low. Value between 5
|
||||
and 95. Default 15
|
||||
.TP
|
||||
.B \-c \-\-critical <value>
|
||||
level at which the battery is considered to be critical. Value between 5
|
||||
and 95. Default 10
|
||||
.TP
|
||||
.B \-r \-\-refresh-rate <value>
|
||||
refresh rate of the battery’s reads in seconds. Default 5
|
||||
.SH BUGS
|
||||
Although I try to hunt for bugs, but if you ever find one, please do not
|
||||
hesitate reporting it at lucien@phundrak.com or on
|
||||
https://labs.phundrak.com/phundrak/pumopm or
|
||||
https://github.com/Phundrak/pumopm/
|
17
pumopm.service
Normal file
17
pumopm.service
Normal file
@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=A small, simple, no bloat power manager.
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
ExecStart=/usr/bin/pumopm
|
||||
Restart=on-failure
|
||||
|
||||
# Disalow writing to /usr, /bin, /usr/bin... It shouldn’t, but just in case
|
||||
ProtectSystem=yes
|
||||
# I swear I’m not paranoid about my own program
|
||||
NoNewPrivileges=yes
|
||||
ProtectKernelTunables=yes
|
||||
ProtectControlGroups=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
@ -37,10 +37,13 @@ macro_rules! trigger_warning {
|
||||
}
|
||||
$trigger = true;
|
||||
let level = ($battery.state_of_charge().value * 100_f32) as u8;
|
||||
let message = format!($message, $self.remaining_time($self.battery.time_to_full()), level);
|
||||
match $verbosity {
|
||||
VerbosityLevel::None => {}
|
||||
_ => println!("{}", message),
|
||||
let message = format!(
|
||||
$message,
|
||||
$self.remaining_time($self.battery.time_to_full()),
|
||||
level
|
||||
);
|
||||
if $verbosity >= VerbosityLevel::Some {
|
||||
println!("{}", message);
|
||||
}
|
||||
Notification::new()
|
||||
.summary("Low battery")
|
||||
@ -61,8 +64,8 @@ impl BatteryState {
|
||||
refresh_rate: u64,
|
||||
verbosity: VerbosityLevel,
|
||||
) -> battery::Result<Self> {
|
||||
let manager = battery::Manager::new().unwrap();
|
||||
let battery = match manager.batteries().unwrap().next() {
|
||||
let manager = battery::Manager::new()?;
|
||||
let battery = match manager.batteries()?.next() {
|
||||
Some(Ok(battery)) => battery,
|
||||
Some(Err(e)) => {
|
||||
eprintln!("An error occured: {}", e);
|
||||
@ -84,18 +87,17 @@ impl BatteryState {
|
||||
critical_level = u8::max(very_low_level - 1_u8, 5_u8)
|
||||
};
|
||||
|
||||
match verbosity {
|
||||
VerbosityLevel::None => {}
|
||||
_ => {
|
||||
println!("Low battery: {}%", low_level);
|
||||
println!("Very low battery: {}%", very_low_level);
|
||||
println!("Critical battery: {}%", critical_level);
|
||||
println!("Refresh rate: {}s", refresh_rate);
|
||||
match verbosity {
|
||||
VerbosityLevel::Some => println!("Some verbose info"),
|
||||
_ => println!("Lots of verbose info"),
|
||||
}
|
||||
}
|
||||
if verbosity == VerbosityLevel::Some {
|
||||
println!("Some verbose info");
|
||||
}
|
||||
if verbosity >= VerbosityLevel::Some {
|
||||
println!("Low battery: {}%", low_level);
|
||||
println!("Very low battery: {}%", very_low_level);
|
||||
println!("Critical battery: {}%", critical_level);
|
||||
println!("Refresh rate: {}s", refresh_rate);
|
||||
}
|
||||
if verbosity >= VerbosityLevel::Lots {
|
||||
println!("Lots of verbose info")
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
@ -126,18 +128,14 @@ impl BatteryState {
|
||||
}
|
||||
|
||||
pub fn remaining_time(&self, time: Option<battery::units::Time>) -> String {
|
||||
match time {
|
||||
Some(e) => {
|
||||
let time = e.value as u64;
|
||||
let hours = time / 3600;
|
||||
let minutes = (time % 3600) / 60;
|
||||
let seconds = time % 60;
|
||||
format!("{:01}:{:02}:{:02}", hours, minutes, seconds)
|
||||
}
|
||||
None => {
|
||||
eprintln!("Couldn’t read remaining time");
|
||||
String::from("unknown remaining time")
|
||||
}
|
||||
if let Some(e) = time {
|
||||
let time = e.value as u64;
|
||||
let hours = time / 3600;
|
||||
let minutes = (time % 3600) / 60;
|
||||
let seconds = time % 60;
|
||||
format!("{:01}:{:02}:{:02}", hours, minutes, seconds)
|
||||
} else {
|
||||
"unknown remaining time".to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,7 +214,7 @@ impl BatteryState {
|
||||
_ => eprintln!("Error: unknown battery state"),
|
||||
}
|
||||
}
|
||||
if self.verbosity == VerbosityLevel::Lots {
|
||||
if self.verbosity >= VerbosityLevel::Lots {
|
||||
eprintln!("====\nDebug self:\n{:?}\n====", self);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ use clap::Clap;
|
||||
|
||||
#[derive(Clap)]
|
||||
#[clap(
|
||||
version = "0.1.0",
|
||||
version = "0.1.1",
|
||||
author = "Lucien Cartier-Tilet <lucien@phundrak.com>"
|
||||
)]
|
||||
struct Opts {
|
||||
|
Loading…
x
Reference in New Issue
Block a user