Skip to content

Commit

Permalink
modified: src-tauri/src/main.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
death7654 committed Oct 4, 2023
1 parent 501cf37 commit 79e5caf
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use sysinfo::{CpuExt, System, SystemExt};
use tauri::Manager;
use tauri::{CustomMenuItem, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem};
use tauri_plugin_autostart::MacosLauncher;
#[cfg(target_os = "linux")]
use std::fs;

fn main() {
let quit = CustomMenuItem::new("quit".to_string(), "Quit");
Expand Down Expand Up @@ -108,10 +110,28 @@ async fn get_cpu_usage() -> String {
async fn get_cpu_temp() -> Option<String> {
#[cfg(target_os = "linux")]
{
let cmd = std::process::Command::new("ectool")
.args(["temps", "all"])
.output();
return Some(match_result(cmd));
let paths = fs::read_dir("/sys/class/hwmon/").unwrap();
for path in paths {
let name =
fs::read_to_string(format!("{}/name", path.as_ref().unwrap().path().display()))
.unwrap();
if name.contains("k10temp") || name.contains("coretemp") {
return Some(
(fs::read_to_string(format!(
"{}/temp1_input",
path.as_ref().unwrap().path().display()
))
.unwrap()
.split('\n')
.collect::<Vec<_>>()[0]
.parse::<i32>()
.unwrap()
/ 1000)
.to_string(),
);
};
}
return None;
};

#[cfg(windows)]
Expand Down

0 comments on commit 79e5caf

Please sign in to comment.