-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: simplify system status management with SysinfoInstance (#525)
- Loading branch information
Showing
4 changed files
with
49 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use sysinfo::{CpuRefreshKind, Disks, MemoryRefreshKind, RefreshKind, System}; | ||
|
||
pub struct SysinfoInstance { | ||
pub system: System, | ||
pub disks: Disks, | ||
} | ||
|
||
impl SysinfoInstance { | ||
pub fn new() -> SysinfoInstance { | ||
let system = System::new_with_specifics( | ||
RefreshKind::new() | ||
.with_cpu(CpuRefreshKind::new().with_cpu_usage()) | ||
.with_memory(MemoryRefreshKind::everything()), | ||
); | ||
let disks = Disks::new_with_refreshed_list(); | ||
|
||
SysinfoInstance { system, disks } | ||
} | ||
pub fn refresh(&mut self) { | ||
self.system.refresh_specifics( | ||
RefreshKind::new() | ||
.with_cpu(CpuRefreshKind::new().with_cpu_usage()) | ||
.with_memory(MemoryRefreshKind::everything()), | ||
); | ||
self.disks.refresh_list(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters