aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMustafa Salih <37256744+MustafaSalih1993@users.noreply.github.com>2021-05-11 19:07:01 +0300
committerGitHub <noreply@github.com>2021-05-11 19:07:01 +0300
commit96b47f199991657c23865b583155f110500070b4 (patch)
tree02caca6efaf83fb0f107421034931a0e4267d894
parentc2a1be9cd35c044a63fcf546ffd0a41fff5e9044 (diff)
Getting uptime programmatically (#55)
* added limits 30 chars foreach the title and artist in spotify block, closes: #53 * Getting uptime programmatically
-rw-r--r--src/utils/uptime.rs15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/utils/uptime.rs b/src/utils/uptime.rs
index 140c4c4..4bb06cc 100644
--- a/src/utils/uptime.rs
+++ b/src/utils/uptime.rs
@@ -1,17 +1,14 @@
use crate::config::CONFIG;
use crate::types::ThreadsData;
-use std::fs::read_to_string;
+use chrono::Duration;
+use nix::sys::sysinfo;
pub fn get_uptime() -> ThreadsData {
- let buf = match read_to_string("/proc/uptime") {
- Ok(data) => data,
- _ => return ThreadsData::Uptime("cant find uptime file!".to_string()),
- };
-
- let buf: f32 = buf.split(' ').collect::<Vec<&str>>()[0].parse().unwrap();
+ let duration = sysinfo::sysinfo().unwrap().uptime();
+ let uptime_sec = Duration::from_std(duration).unwrap().num_seconds();
- let hour = buf.round() as u32 / 3600;
- let rem = buf as u32 - hour * 3600;
+ let hour = uptime_sec / 3600;
+ let rem = uptime_sec - hour * 3600;
let minutes = rem / 60;
let uptime = if hour > 0 {