6 Commits
0.1.0 ... 0.1.1

6 changed files with 38 additions and 46 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
/target /target
/pkg/ /pkg/
/src/pumopm-git/ /src/pumopm-git/
/src/pumopm/

2
Cargo.lock generated
View File

@@ -393,7 +393,7 @@ dependencies = [
[[package]] [[package]]
name = "pumopm" name = "pumopm"
version = "0.1.0" version = "0.1.1"
dependencies = [ dependencies = [
"battery", "battery",
"clap", "clap",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "pumopm" name = "pumopm"
version = "0.1.0" version = "0.1.1"
authors = ["Lucien Cartier-Tilet <lucien@phundrak.com>"] authors = ["Lucien Cartier-Tilet <lucien@phundrak.com>"]
edition = "2018" edition = "2018"
description = "Simple power manager for systemd-based Linux" description = "Simple power manager for systemd-based Linux"

View File

@@ -1,7 +1,7 @@
# Maintainer: Lucien Cartier-Tilet <lucien@phundrak.com> # Maintainer: Lucien Cartier-Tilet <lucien@phundrak.com>
pkgname=pumopm-git pkgname=pumopm
pkgver=.r0.4e2acb9 pkgver=0.1.1
pkgrel=1 pkgrel=2
pkgdesc="A tiny power manager written in Rust" pkgdesc="A tiny power manager written in Rust"
arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64') arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')
url="https://labs.phundrak.com/phundrak/pumopm" url="https://labs.phundrak.com/phundrak/pumopm"
@@ -9,15 +9,8 @@ license=('GPL3')
depends=() depends=()
makedepends=('rustup' 'git') makedepends=('rustup' 'git')
options=() options=()
source=("$pkgname::git+https://github.com/phundrak/pumopm") source=("$pkgname::https://labs.phundrak.com/phundrak/pumopm/archive/$pkgver.tar.gz")
md5sums=('SKIP') md5sums=('347a95efacdbf9f8ab3b2da6a7eff6cc')
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)"
}
build() { build() {
cd "$pkgname" cd "$pkgname"

View File

@@ -37,10 +37,13 @@ macro_rules! trigger_warning {
} }
$trigger = true; $trigger = true;
let level = ($battery.state_of_charge().value * 100_f32) as u8; let level = ($battery.state_of_charge().value * 100_f32) as u8;
let message = format!($message, $self.remaining_time($self.battery.time_to_full()), level); let message = format!(
match $verbosity { $message,
VerbosityLevel::None => {} $self.remaining_time($self.battery.time_to_full()),
_ => println!("{}", message), level
);
if $verbosity >= VerbosityLevel::Some {
println!("{}", message);
} }
Notification::new() Notification::new()
.summary("Low battery") .summary("Low battery")
@@ -61,8 +64,8 @@ impl BatteryState {
refresh_rate: u64, refresh_rate: u64,
verbosity: VerbosityLevel, verbosity: VerbosityLevel,
) -> battery::Result<Self> { ) -> battery::Result<Self> {
let manager = battery::Manager::new().unwrap(); let manager = battery::Manager::new()?;
let battery = match manager.batteries().unwrap().next() { let battery = match manager.batteries()?.next() {
Some(Ok(battery)) => battery, Some(Ok(battery)) => battery,
Some(Err(e)) => { Some(Err(e)) => {
eprintln!("An error occured: {}", e); eprintln!("An error occured: {}", e);
@@ -84,18 +87,17 @@ impl BatteryState {
critical_level = u8::max(very_low_level - 1_u8, 5_u8) critical_level = u8::max(very_low_level - 1_u8, 5_u8)
}; };
match verbosity { if verbosity == VerbosityLevel::Some {
VerbosityLevel::None => {} println!("Some verbose info");
_ => { }
if verbosity >= VerbosityLevel::Some {
println!("Low battery: {}%", low_level); println!("Low battery: {}%", low_level);
println!("Very low battery: {}%", very_low_level); println!("Very low battery: {}%", very_low_level);
println!("Critical battery: {}%", critical_level); println!("Critical battery: {}%", critical_level);
println!("Refresh rate: {}s", refresh_rate); println!("Refresh rate: {}s", refresh_rate);
match verbosity {
VerbosityLevel::Some => println!("Some verbose info"),
_ => println!("Lots of verbose info"),
}
} }
if verbosity >= VerbosityLevel::Lots {
println!("Lots of verbose info")
} }
Ok(Self { Ok(Self {
@@ -126,18 +128,14 @@ impl BatteryState {
} }
pub fn remaining_time(&self, time: Option<battery::units::Time>) -> String { pub fn remaining_time(&self, time: Option<battery::units::Time>) -> String {
match time { if let Some(e) = time {
Some(e) => {
let time = e.value as u64; let time = e.value as u64;
let hours = time / 3600; let hours = time / 3600;
let minutes = (time % 3600) / 60; let minutes = (time % 3600) / 60;
let seconds = time % 60; let seconds = time % 60;
format!("{:01}:{:02}:{:02}", hours, minutes, seconds) format!("{:01}:{:02}:{:02}", hours, minutes, seconds)
} } else {
None => { "unknown remaining time".to_owned()
eprintln!("Couldnt read remaining time");
String::from("unknown remaining time")
}
} }
} }
@@ -216,7 +214,7 @@ impl BatteryState {
_ => eprintln!("Error: unknown battery state"), _ => eprintln!("Error: unknown battery state"),
} }
} }
if self.verbosity == VerbosityLevel::Lots { if self.verbosity >= VerbosityLevel::Lots {
eprintln!("====\nDebug self:\n{:?}\n====", self); eprintln!("====\nDebug self:\n{:?}\n====", self);
} }

View File

@@ -6,7 +6,7 @@ use clap::Clap;
#[derive(Clap)] #[derive(Clap)]
#[clap( #[clap(
version = "0.1.0", version = "0.1.1",
author = "Lucien Cartier-Tilet <lucien@phundrak.com>" author = "Lucien Cartier-Tilet <lucien@phundrak.com>"
)] )]
struct Opts { struct Opts {