Skip to content

Commit

Permalink
Fix for Issue 153 (#155)
Browse files Browse the repository at this point in the history
* We should check if the graphics device exists in the current layout before removing it and recalculating the heights of the sections. If we do not do this the users who do not have graphics devices will always have their height preferences ignored since an assumption was made that the graphics device existed in the layout.
Closes issue #153

* Some lint fixes

* Migrated from PanicHook to PanicHookInfo

* silenced another lint
  • Loading branch information
bvaisvil authored Nov 25, 2024
1 parent 0dfb334 commit f4ffbf1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ use std::error::Error;
use std::fs;
use std::io::stdout;
use std::panic;
use std::panic::PanicInfo;
use std::panic::PanicHookInfo;
use std::path::Path;
use std::process::exit;
use std::time::Duration;
use std::time::SystemTime;

fn panic_hook(info: &PanicInfo<'_>) {
fn panic_hook(info: &PanicHookInfo<'_>) {
let location = info.location().unwrap(); // The current implementation always returns Some
let msg = match info.payload().downcast_ref::<&'static str>() {
Some(s) => *s,
Expand Down
2 changes: 2 additions & 0 deletions src/metrics/graphics/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

pub trait GraphicsExt {
fn update_gfx_devices(&mut self);
#[allow(dead_code)]
fn update_total(&mut self, total: Option<GraphicsDevice>);
fn update_gpu_utilization(&mut self);
}

#[allow(dead_code)]
#[derive(Clone)]
pub struct GraphicsDeviceProcess {
pub pid: i32,
Expand Down
1 change: 1 addition & 0 deletions src/metrics/graphics/graphics_none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::metrics::CPUTimeApp;

impl GraphicsExt for CPUTimeApp {
fn update_gfx_devices(&mut self) {}
#[allow(unused_variables, unused_mut)]
fn update_total(&mut self, mut total: Option<GraphicsDevice>) {}
fn update_gpu_utilization(&mut self) {}
}
6 changes: 4 additions & 2 deletions src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ pub enum ProcessTableSortOrder {
}

pub trait DiskFreeSpaceExt {
#[allow(dead_code)]
fn get_perc_free_space(&self) -> f32;
}

Expand All @@ -128,13 +129,13 @@ impl DiskFreeSpaceExt for Disk {
percent_of(self.get_available_space(), self.get_total_space())
}
}

#[allow(dead_code)]
pub struct NetworkInterface {
pub name: String,
pub ip: String,
pub dest: String,
}

#[allow(dead_code)]
pub struct Sensor {
pub name: String,
pub current_temp: f32,
Expand Down Expand Up @@ -219,6 +220,7 @@ impl Top {
}
}

#[allow(dead_code)]
pub struct CPUTimeApp {
pub histogram_map: HistogramMap,
pub cpu_utilization: u64,
Expand Down
1 change: 1 addition & 0 deletions src/metrics/zprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ macro_rules! convert_error_to_string {
};
}

#[allow(dead_code)]
#[derive(Clone)]
pub struct ZProcess {
pub pid: i32,
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ impl<'a> TerminalRenderer<'_> {
let mut section_geometry = section_geometry.to_vec();
let mut recompute_constraints_on_start_up = false;
app.update_gfx_devices();
if app.gfx_devices.is_empty() {
if app.gfx_devices.is_empty()
&& section_geometry
.iter()
.any(|(s, _)| *s == Section::Graphics)
{
section_geometry.retain(|(section, _)| *section != Section::Graphics);
recompute_constraints_on_start_up = true;
}
Expand Down

0 comments on commit f4ffbf1

Please # to comment.