From 2e0cf5c9465b08d24501f431bd2caf0b6728c117 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Mon, 12 Aug 2024 14:49:14 +0200 Subject: [PATCH 1/6] Implemented display for cpu temperatures --- src-tauri/src/cpu_miner.rs | 27 +++++- src-tauri/src/main.rs | 23 ++++- src/containers/SideBar/components/Heading.tsx | 2 +- .../components/Settings/Card.component.tsx | 25 ++++++ .../components/Settings/Settings.styles.tsx | 14 ++++ .../components/{ => Settings}/Settings.tsx | 83 ++++++++++++++++--- src/store/useAppStatusStore.ts | 1 + src/types/app-status.ts | 7 ++ 8 files changed, 164 insertions(+), 18 deletions(-) create mode 100644 src/containers/SideBar/components/Settings/Card.component.tsx create mode 100644 src/containers/SideBar/components/Settings/Settings.styles.tsx rename src/containers/SideBar/components/{ => Settings}/Settings.tsx (67%) diff --git a/src-tauri/src/cpu_miner.rs b/src-tauri/src/cpu_miner.rs index 4bd333013..f5eaf973b 100644 --- a/src-tauri/src/cpu_miner.rs +++ b/src-tauri/src/cpu_miner.rs @@ -3,11 +3,11 @@ use crate::mm_proxy_manager::MmProxyManager; use crate::xmrig::http_api::XmrigHttpApiClient; use crate::xmrig_adapter::{XmrigAdapter, XmrigNodeConnection}; use crate::{ - CpuMinerConfig, CpuMinerConnection, CpuMinerConnectionStatus, CpuMinerStatus, ProgressTracker, + CpuCoreTemperature, CpuMinerConfig, CpuMinerConnection, CpuMinerConnectionStatus, CpuMinerStatus, ProgressTracker }; use log::warn; use std::path::PathBuf; -use sysinfo::{CpuRefreshKind, RefreshKind, System}; +use sysinfo::{Component, Components, CpuRefreshKind, RefreshKind, System}; use tari_core::transactions::tari_amount::MicroMinotari; use tari_shutdown::{Shutdown, ShutdownSignal}; use tauri::async_runtime::JoinHandle; @@ -26,6 +26,7 @@ pub(crate) struct CpuMiner { watcher_task: Option>>, miner_shutdown: Shutdown, api_client: Option, + cpu_temperature_components: Components } impl CpuMiner { @@ -34,6 +35,7 @@ impl CpuMiner { watcher_task: None, miner_shutdown: Shutdown::new(), api_client: None, + cpu_temperature_components: Components::new_with_refreshed_list() } } @@ -156,10 +158,26 @@ impl CpuMiner { } pub async fn status( - &self, + &mut self, network_hash_rate: u64, block_reward: MicroMinotari, ) -> Result { + + let components = &mut self.cpu_temperature_components; + components.refresh(); + + let cpu_components:Vec<&Component> = components.iter().filter(|component| component.label().contains("Core")).collect(); + let cpu_temperatures: Vec = cpu_components.iter().map(|component| { + CpuCoreTemperature { + id: component.label().split(" ").last().unwrap().parse().unwrap(), + label: component.label().split(" ").skip(1).collect::>().join(" ").to_string(), + temperature: component.temperature(), + max_temperature: component.max(), + } + }).collect(); + + // cpu_temperatures.sort(); + let mut s = System::new_with_specifics(RefreshKind::new().with_cpu(CpuRefreshKind::everything())); @@ -171,6 +189,7 @@ impl CpuMiner { let cpu_brand = s.cpus().get(0).map(|cpu| cpu.brand()).unwrap_or("Unknown"); let cpu_usage = s.global_cpu_usage() as u32; + // let cpu_temperature = s. match &self.api_client { Some(client) => { @@ -192,6 +211,7 @@ impl CpuMiner { && xmrig_status.hashrate.total[0].unwrap() > 0.0, hash_rate, cpu_usage: cpu_usage as u32, + cpu_temperatures, cpu_brand: cpu_brand.to_string(), estimated_earnings: MicroMinotari(estimated_earnings).as_u64(), connection: CpuMinerConnectionStatus { @@ -207,6 +227,7 @@ impl CpuMiner { None => Ok(CpuMinerStatus { is_mining: false, hash_rate: 0.0, + cpu_temperatures, cpu_usage: cpu_usage as u32, cpu_brand: cpu_brand.to_string(), estimated_earnings: 0, diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index cdd8d4170..8318e5180 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -365,7 +365,7 @@ async fn get_applications_versions(app: tauri::AppHandle) -> Result) -> Result { - let cpu_miner = state.cpu_miner.read().await; + let mut cpu_miner = state.cpu_miner.write().await; let (_sha_hash_rate, randomx_hash_rate, block_reward, block_height, block_time, is_synced) = state .node_manager @@ -440,11 +440,32 @@ pub struct BaseNodeStatus { is_synced: bool, } +#[derive(Debug, Serialize, PartialEq, PartialOrd)] +pub struct CpuCoreTemperature { + pub id : u32, + pub label: String, + pub temperature: f32, + pub max_temperature: f32, +} + +impl Ord for CpuCoreTemperature { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.id.cmp(&other.id) + } +} + +impl Eq for CpuCoreTemperature { + fn assert_receiver_is_total_eq(&self) { + self.id.assert_receiver_is_total_eq(); + } +} + #[derive(Debug, Serialize)] pub struct CpuMinerStatus { pub is_mining: bool, pub hash_rate: f64, pub cpu_usage: u32, + pub cpu_temperatures: Vec, pub cpu_brand: String, pub estimated_earnings: u64, pub connection: CpuMinerConnectionStatus, diff --git a/src/containers/SideBar/components/Heading.tsx b/src/containers/SideBar/components/Heading.tsx index 93861447e..5554f8fa2 100644 --- a/src/containers/SideBar/components/Heading.tsx +++ b/src/containers/SideBar/components/Heading.tsx @@ -1,6 +1,6 @@ import { Stack, Typography, IconButton } from '@mui/material'; import { CgArrowsExpandRight, CgCompressRight } from 'react-icons/cg'; -import SettingsDialog from './Settings'; +import SettingsDialog from './Settings/Settings.tsx'; import { useUIStore } from '../../../store/useUIStore.ts'; function Heading() { diff --git a/src/containers/SideBar/components/Settings/Card.component.tsx b/src/containers/SideBar/components/Settings/Card.component.tsx new file mode 100644 index 000000000..4df26f5a1 --- /dev/null +++ b/src/containers/SideBar/components/Settings/Card.component.tsx @@ -0,0 +1,25 @@ +import { Stack, Typography } from '@mui/material'; +import { CardItem } from './Settings.styles'; + +export interface CardComponentProps { + heading: string; + labels: { labelText: string; labelValue: string }[]; +} + +export const CardComponent = ({ heading, labels }: CardComponentProps) => { + return ( + + {heading} + + {labels.map(({ labelText, labelValue }) => ( + + {labelText}: + + {labelValue} + + + ))} + + + ); +}; diff --git a/src/containers/SideBar/components/Settings/Settings.styles.tsx b/src/containers/SideBar/components/Settings/Settings.styles.tsx new file mode 100644 index 000000000..d27417818 --- /dev/null +++ b/src/containers/SideBar/components/Settings/Settings.styles.tsx @@ -0,0 +1,14 @@ +import { Box, Stack, styled } from '@mui/material'; + +export const CardContainer = styled(Box)(({ theme }) => ({ + display: 'grid', + gridTemplateColumns: '1fr 1fr', + gap: theme.spacing(1), +})); + +export const CardItem = styled(Stack)(({ theme }) => ({ + padding: theme.spacing(1, 1.5), + backgroundColor: theme.palette.background.paper, + borderRadius: theme.shape.borderRadius, + boxShadow: '0px 4px 45px 0px rgba(0, 0, 0, 0.08)', +})); diff --git a/src/containers/SideBar/components/Settings.tsx b/src/containers/SideBar/components/Settings/Settings.tsx similarity index 67% rename from src/containers/SideBar/components/Settings.tsx rename to src/containers/SideBar/components/Settings/Settings.tsx index e6dcc78dc..f839e51ae 100644 --- a/src/containers/SideBar/components/Settings.tsx +++ b/src/containers/SideBar/components/Settings/Settings.tsx @@ -15,10 +15,13 @@ import { Tooltip, } from '@mui/material'; import { IoSettingsOutline, IoClose } from 'react-icons/io5'; -import { useGetSeedWords } from '../../../hooks/useGetSeedWords'; -import truncateString from '../../../utils/truncateString'; +import { useGetSeedWords } from '../../../../hooks/useGetSeedWords'; +import truncateString from '../../../../utils/truncateString'; import { invoke } from '@tauri-apps/api/tauri'; -import { useGetApplicatonsVersions } from '../../../hooks/useGetApplicatonsVersions'; +import { useGetApplicatonsVersions } from '../../../../hooks/useGetApplicatonsVersions'; +import { useAppStatusStore } from '../../../../store/useAppStatusStore'; +import { CardContainer } from './Settings.styles'; +import { CardComponent } from './Card.component'; const Settings: React.FC = () => { const { refreshVersions, applicationsVersions, mainAppVersion } = @@ -29,6 +32,9 @@ const Settings: React.FC = () => { const [isCopyTooltipHidden, setIsCopyTooltipHidden] = useState(true); const { seedWords, getSeedWords, seedWordsFetched, seedWordsFetching } = useGetSeedWords(); + const cpuTemperatures = useAppStatusStore( + (state) => state.cpu?.cpu_temperatures + ); const handleClickOpen = () => setOpen(true); const handleClose = () => { @@ -171,9 +177,10 @@ const Settings: React.FC = () => { {applicationsVersions && ( - + Versions @@ -181,17 +188,67 @@ const Settings: React.FC = () => { Refresh Versions - - mainApp: {mainAppVersion} - {Object.entries(applicationsVersions).map( - ([key, value]) => ( - - {key}: {value} - - ) - )} + + + + {Object.entries(applicationsVersions).map( + ([key, value]) => ( + + ) + )} + )} + + + CPU Temperatures + {cpuTemperatures ? ( + + {cpuTemperatures.map((core) => ( + + ))} + + ) : ( + No CPU Temperatures + )} + +