Make levels safer
It is now impossible to have any level set to something below 5% of the battery and above 50%. If a lower level is set higher than its higher level, the program will attempt to lower the level by 1% without going under 5%.
This commit is contained in:
parent
5065c61e92
commit
7125d483fa
@ -29,8 +29,8 @@ pub const DEFAULT_REFRESH: u64 = 5;
|
|||||||
impl BatteryState {
|
impl BatteryState {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
low_level: f32,
|
low_level: f32,
|
||||||
very_low_level: f32,
|
mut very_low_level: f32,
|
||||||
critical_level: f32,
|
mut critical_level: f32,
|
||||||
refresh_rate: u64,
|
refresh_rate: u64,
|
||||||
verbosity: VerbosityLevel,
|
verbosity: VerbosityLevel,
|
||||||
) -> battery::Result<Self> {
|
) -> battery::Result<Self> {
|
||||||
@ -48,6 +48,14 @@ impl BatteryState {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let low_level = low_level.min(50_f32).max(5_f32);
|
||||||
|
if very_low_level > low_level {
|
||||||
|
very_low_level = f32::max(low_level - 1_f32, 5_f32)
|
||||||
|
};
|
||||||
|
if critical_level > very_low_level {
|
||||||
|
critical_level = f32::max(very_low_level - 1_f32, 5_f32)
|
||||||
|
};
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
manager,
|
manager,
|
||||||
battery,
|
battery,
|
||||||
|
Loading…
Reference in New Issue
Block a user