Skip to content

Commit

Permalink
Update sysinfo version to 0.32
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Nov 10, 2024
1 parent 0c088b2 commit bca7994
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 39 deletions.
65 changes: 43 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ keywords = ["GUI", "process", "viewer", "gtk"]

[dependencies]
gtk = { version = "0.8", package = "gtk4" }
sysinfo = "0.30"
sysinfo = "0.32"
libc = "0.2"
serde = "1.0"
serde_derive = "1.0"
Expand Down
22 changes: 16 additions & 6 deletions src/display_procs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::utils::format_number;

use std::cell::Cell;
use std::collections::HashMap;
use std::ffi::{OsStr, OsString};
use std::rc::Rc;

#[allow(dead_code)]
Expand Down Expand Up @@ -81,7 +82,7 @@ impl Procs {
for pro in proc_list.values() {
if let Some(exe) = pro
.exe()
.and_then(|exe| exe.file_name().and_then(|f| f.to_str()))
.and_then(|exe| exe.file_name())
.or_else(|| Some(pro.name()))
{
create_and_fill_model(
Expand Down Expand Up @@ -241,14 +242,23 @@ fn append_column(
pub fn create_and_fill_model(
list_store: &gtk::ListStore,
pid: u32,
cmdline: &[String],
name: &str,
cmdline: &[OsString],
name: &OsStr,
cpu: f32,
memory: u64,
) {
if cmdline.is_empty() || name.is_empty() {
return;
}
let name = if name.is_empty() {
let Some(cmd) = cmdline
.iter()
.map(|c| c.to_string_lossy().to_string())
.next()
else {
return;
};
cmd
} else {
name.to_string_lossy().to_string()
};
list_store.insert_with_values(
None,
&[
Expand Down
11 changes: 6 additions & 5 deletions src/display_sysinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ impl DisplaySysInfo {
p.set_margin_end(5);
p.set_margin_start(5);
p.set_show_text(true);
let processor = sys.global_cpu_info();
p.set_text(Some(&format!("{:.1} %", processor.cpu_usage())));
p.set_fraction(f64::from(processor.cpu_usage() / 100.));
let cpu_usage = sys.global_cpu_usage();
p.set_text(Some(&format!("{:.1} %", cpu_usage)));
p.set_fraction(f64::from(cpu_usage / 100.));
vertical_layout.append(p);
}
let check_box = create_header("Processors usage", &vertical_layout, settings.display_graph);
Expand Down Expand Up @@ -368,9 +368,10 @@ impl DisplaySysInfo {
let v = &*self.procs.borrow_mut();
let h = &mut *self.cpu_usage_history.borrow_mut();

v[0].set_text(Some(&format!("{:.1} %", sys.global_cpu_info().cpu_usage())));
let cpu_usage = sys.global_cpu_usage();
v[0].set_text(Some(&format!("{:.1} %", cpu_usage)));
v[0].set_show_text(true);
v[0].set_fraction(f64::from(sys.global_cpu_info().cpu_usage() / 100.));
v[0].set_fraction(f64::from(cpu_usage / 100.));
for (i, pro) in sys.cpus().iter().enumerate() {
let i = i + 1;
v[i].set_text(Some(&format!("{:.1} %", pro.cpu_usage())));
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use gtk::prelude::*;
use gtk::{gdk, gdk_pixbuf, gio, glib};
use gtk::{AboutDialog, Dialog, Entry, MessageDialog};

use sysinfo::{Networks, Pid, RefreshKind};
use sysinfo::{Networks, Pid, ProcessesToUpdate, RefreshKind};

use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -243,7 +243,7 @@ fn setup_timeout(rfs: &RequiredForSettings) {
let sleep_dur = Duration::from_millis(
*process_refresh_timeout.lock().expect("failed to lock process refresh mutex") as _);
thread::sleep(sleep_dur);
sys.lock().expect("failed to lock to refresh processes").refresh_processes();
sys.lock().expect("failed to lock to refresh processes").refresh_processes(ProcessesToUpdate::All, false);
sender.send_blocking(()).expect("failed to send data through process refresh channel");
}
}),
Expand Down
8 changes: 5 additions & 3 deletions src/process_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ pub fn create_process_dialog(process: &sysinfo::Process, total_memory: u64) -> P

let popup = gtk::Window::new();

popup.set_title(Some(&format!("Information about {}", process.name())));
let name = process.name().to_string_lossy();
popup.set_title(Some(&format!("Information about {name}")));
popup.set_transient_for(get_main_window().as_ref());
popup.set_destroy_with_parent(true);

Expand All @@ -197,7 +198,7 @@ pub fn create_process_dialog(process: &sysinfo::Process, total_memory: u64) -> P

let labels = gtk::Box::new(gtk::Orientation::Vertical, 0);

create_and_add_new_label(&labels, "name", process.name());
create_and_add_new_label(&labels, "name", &name);
create_and_add_new_label(&labels, "pid", &process.pid().to_string());
let memory_peak = process.memory();
let memory_usage =
Expand Down Expand Up @@ -232,7 +233,7 @@ pub fn create_process_dialog(process: &sysinfo::Process, total_memory: u64) -> P
process
.cmd()
.iter()
.map(|x| format!("\"{}\"", x))
.map(|x| format!("\"{}\"", x.to_string_lossy()))
.collect::<Vec<_>>()
.join(", ")
),
Expand Down Expand Up @@ -272,6 +273,7 @@ pub fn create_process_dialog(process: &sysinfo::Process, total_memory: u64) -> P
append_text_column(&env_tree, 1);

for env in process.environ() {
let env = env.to_string_lossy();
let mut parts = env.splitn(2, '=');
let name = match parts.next() {
Some(n) => n,
Expand Down

0 comments on commit bca7994

Please sign in to comment.