Getting uptime programmatically (#55)

* added limits 30 chars foreach the title and artist in spotify block, closes: #53

* Getting uptime programmatically
This commit is contained in:
Mustafa Salih 2021-05-11 19:07:01 +03:00 committed by GitHub
parent c2a1be9cd3
commit 96b47f1999
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,17 +1,14 @@
use crate::config::CONFIG; use crate::config::CONFIG;
use crate::types::ThreadsData; use crate::types::ThreadsData;
use std::fs::read_to_string; use chrono::Duration;
use nix::sys::sysinfo;
pub fn get_uptime() -> ThreadsData { pub fn get_uptime() -> ThreadsData {
let buf = match read_to_string("/proc/uptime") { let duration = sysinfo::sysinfo().unwrap().uptime();
Ok(data) => data, let uptime_sec = Duration::from_std(duration).unwrap().num_seconds();
_ => return ThreadsData::Uptime("cant find uptime file!".to_string()),
};
let buf: f32 = buf.split(' ').collect::<Vec<&str>>()[0].parse().unwrap(); let hour = uptime_sec / 3600;
let rem = uptime_sec - hour * 3600;
let hour = buf.round() as u32 / 3600;
let rem = buf as u32 - hour * 3600;
let minutes = rem / 60; let minutes = rem / 60;
let uptime = if hour > 0 { let uptime = if hour > 0 {