Replace system info dependency

This commit is contained in:
Jeff 2023-08-28 14:07:46 -04:00
parent 3481551926
commit c85d807942
5 changed files with 12 additions and 28 deletions

12
Cargo.lock generated
View File

@ -936,7 +936,6 @@ dependencies = [
"egui_extras",
"git2",
"json",
"lazy_static",
"nu-ansi-term",
"rand",
"rayon",
@ -944,7 +943,6 @@ dependencies = [
"reqwest",
"serde",
"serde_json",
"sys-info",
"sysinfo",
"toml",
"toml_edit",
@ -2906,16 +2904,6 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "sys-info"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b3a0d0aba8bf96a0e1ddfdc352fc53b3df7f39318c71854910c3c4b024ae52c"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "sysinfo"
version = "0.29.7"

View File

@ -21,10 +21,8 @@ rand = "0.8.5"
chrono = "0.4.26"
eframe = "0.22.0"
trash = "3.0.3"
lazy_static = "1.4.0"
rayon = "1.7.0"
serde = { version = "1.0.171", features = ["derive"] }
sys-info = "0.9.1"
sysinfo = "0.29.6"
toml = "0.7.6"
toml_edit = "0.19.14"

View File

@ -281,12 +281,6 @@ impl From<serde_json::Error> for Error {
}
}
impl From<sys_info::Error> for Error {
fn from(value: sys_info::Error) -> Self {
Error::MacroFailure(value.to_string())
}
}
impl From<SystemTimeError> for Error {
fn from(value: SystemTimeError) -> Self {
Error::MacroFailure(value.to_string())

View File

@ -97,7 +97,7 @@ pub const TOOL_LIST: [&'static dyn Tool; 51] = [
&random::RandomFloat,
&random::RandomInteger,
&random::RandomString,
&system::CpuSpeed,
&system::Users,
&logic::Assert,
&logic::AssertEqual,
&time::Local,

View File

@ -1,14 +1,14 @@
use sys_info::cpu_speed;
use sysinfo::{RefreshKind, System, SystemExt, UserExt};
use crate::{Result, Tool, ToolInfo, Value, ValueType};
pub struct CpuSpeed;
pub struct Users;
impl Tool for CpuSpeed {
impl Tool for Users {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "cpu_speed",
description: "Return the current processor speed in megahertz.",
identifier: "users",
description: "Get a list of the system's users.",
group: "system",
inputs: vec![ValueType::Empty],
}
@ -17,8 +17,12 @@ impl Tool for CpuSpeed {
fn run(&self, argument: &Value) -> Result<Value> {
argument.as_empty()?;
let speed = cpu_speed().unwrap_or_default() as i64;
let users = System::new_with_specifics(RefreshKind::new().with_users_list())
.users()
.iter()
.map(|user| Value::String(user.name().to_string()))
.collect();
Ok(Value::Integer(speed))
Ok(Value::List(users))
}
}