From 5ccbec99bdd58e5972637c9ea601a89019af5333 Mon Sep 17 00:00:00 2001 From: pacholoamit Date: Tue, 15 Oct 2024 08:43:08 +0800 Subject: [PATCH 1/2] feat: Add uptime and arch fields to SysInfo model --- src-tauri/src/commands.rs | 2 +- src-tauri/src/metrics.rs | 9 ++++ src-tauri/src/models.rs | 2 + src/components/system-information-widget.tsx | 43 +++++++++++++------- src/lib/bindings/SysInfo.ts | 2 +- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 3eceec57..fbec6356 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -181,7 +181,7 @@ pub fn delete_file(path: String) -> Result<(), String> { } #[tauri::command] -pub fn add_pachtop_exclusion(window: tauri::Window) -> Result<(), String> { +pub fn add_pachtop_exclusion(_: tauri::Window) -> Result<(), String> { #[cfg(target_os = "windows")] { let shell = window.app_handle().shell(); diff --git a/src-tauri/src/metrics.rs b/src-tauri/src/metrics.rs index 05aeea34..2608b6fc 100644 --- a/src-tauri/src/metrics.rs +++ b/src-tauri/src/metrics.rs @@ -1,6 +1,7 @@ use crate::models::*; use crate::utils::{current_time, get_percentage}; use base64::prelude::*; +use chrono::prelude::*; use std::cmp::Ordering; use std::collections::HashMap; use std::str::{self}; @@ -29,6 +30,12 @@ impl SystemInformationTrait for Metrics { let hostname = System::host_name().unwrap_or("Unknown".to_string()); let core_count = System::physical_core_count(&self.sys).unwrap_or(0); let os = System::long_os_version().unwrap_or("Unknown".to_string()); + let uptime = Utc + .timestamp(System::uptime() as i64, 0) + .format("%H:%M:%S") + .to_string(); + + let arch = System::cpu_arch().unwrap_or("Unknown".to_string()); SysInfo { kernel_version, @@ -36,6 +43,8 @@ impl SystemInformationTrait for Metrics { os_version, hostname, core_count, + uptime, + arch, } } } diff --git a/src-tauri/src/models.rs b/src-tauri/src/models.rs index 2e676ff8..477121e8 100644 --- a/src-tauri/src/models.rs +++ b/src-tauri/src/models.rs @@ -89,6 +89,8 @@ pub struct SysInfo { pub hostname: String, #[ts(type = "number")] pub core_count: usize, + pub uptime: String, + pub arch: String, } pub trait SystemInformationTrait { diff --git a/src/components/system-information-widget.tsx b/src/components/system-information-widget.tsx index 9c10ff70..590fd004 100644 --- a/src/components/system-information-widget.tsx +++ b/src/components/system-information-widget.tsx @@ -1,12 +1,12 @@ -import { useShallow } from "zustand/react/shallow"; +import { useShallow } from 'zustand/react/shallow'; -import Card from "@/components/card"; -import useGlobalCpuSelectors from "@/features/metrics/stores/global-cpu.store"; -import useMemorySelectors from "@/features/metrics/stores/memory.store"; -import useSwapSelectors from "@/features/metrics/stores/swap.store"; -import useSystemStoreSelectors from "@/features/metrics/stores/system.store"; -import formatBytes from "@/features/metrics/utils/format-bytes"; -import { Grid, Group, Text, Title } from "@mantine/core"; +import Card from '@/components/card'; +import useGlobalCpuSelectors from '@/features/metrics/stores/global-cpu.store'; +import useMemorySelectors from '@/features/metrics/stores/memory.store'; +import useSwapSelectors from '@/features/metrics/stores/swap.store'; +import useSystemStoreSelectors from '@/features/metrics/stores/system.store'; +import formatBytes from '@/features/metrics/utils/format-bytes'; +import { Grid, Group, Text, Title } from '@mantine/core'; const SystemInformationWidget: React.FC = () => { const info = useSystemStoreSelectors(useShallow((state) => state.info)); @@ -17,44 +17,57 @@ const SystemInformationWidget: React.FC = () => { return ( - - + + CPU {cpuBrand} - + OS {info.os} - + + + Arch + + {info.arch} + + CPU cores {info.coreCount} - + Kernel {info.kernelVersion} - + Memory {formatBytes(memory)} - + Swap {formatBytes(swap)} + + + + Uptime + + {info.uptime} + ); diff --git a/src/lib/bindings/SysInfo.ts b/src/lib/bindings/SysInfo.ts index 5e7748c1..08f539d2 100644 --- a/src/lib/bindings/SysInfo.ts +++ b/src/lib/bindings/SysInfo.ts @@ -1,3 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export type SysInfo = { kernelVersion: string, os: string, osVersion: string, hostname: string, coreCount: number, }; \ No newline at end of file +export type SysInfo = { kernelVersion: string, os: string, osVersion: string, hostname: string, coreCount: number, uptime: string, arch: string, }; \ No newline at end of file From da37633b57e293b5dc2808621e65c174cd8bf7f9 Mon Sep 17 00:00:00 2001 From: pacholoamit Date: Tue, 15 Oct 2024 09:17:27 +0800 Subject: [PATCH 2/2] feat: Add DashboardSectionsDivider component --- src/components/dashboard-section-divider.tsx | 25 ++++++++ src/features/metrics/pages/dashboard.page.tsx | 64 ++++++++----------- 2 files changed, 50 insertions(+), 39 deletions(-) create mode 100644 src/components/dashboard-section-divider.tsx diff --git a/src/components/dashboard-section-divider.tsx b/src/components/dashboard-section-divider.tsx new file mode 100644 index 00000000..5738d917 --- /dev/null +++ b/src/components/dashboard-section-divider.tsx @@ -0,0 +1,25 @@ +import { Divider, Grid, Text } from '@mantine/core'; + +interface DashboardSectionsDividerProps { + label: string; +} +const DashboardSectionsDivider = ({ label }: DashboardSectionsDividerProps) => { + return ( + <> + + + + {label} + + + } + /> + + + ); +}; + +export default DashboardSectionsDivider; diff --git a/src/features/metrics/pages/dashboard.page.tsx b/src/features/metrics/pages/dashboard.page.tsx index 2f93e0e4..112ac603 100644 --- a/src/features/metrics/pages/dashboard.page.tsx +++ b/src/features/metrics/pages/dashboard.page.tsx @@ -1,5 +1,6 @@ import { useShallow } from 'zustand/react/shallow'; +import DashboardSectionsDivider from '@/components/dashboard-section-divider'; import PageWrapper from '@/components/page-wrapper'; import SystemInformationWidget from '@/components/system-information-widget'; import CpusBarChart from '@/features/metrics/components/cpus/cpus.bar-charts'; @@ -16,26 +17,7 @@ import SwapStatsRing from '@/features/metrics/components/swap/swap.stats-ring'; import useDisksSelectors from '@/features/metrics/stores/disk.store'; import useSystemStoreSelectors from '@/features/metrics/stores/system.store'; import useRandomGreeting from '@/hooks/useRandomGreeting'; -import { Divider, Grid, Text } from '@mantine/core'; - -// const StatsRings = () => { -// return ( -// <> -// -// -// -// -// -// -// -// -// -// -// -// -// -// ); -// }; +import { Box, Center, Divider, Grid, Text } from '@mantine/core'; const MemorySection = () => { return ( @@ -79,6 +61,10 @@ const NetworksSection = () => { const DiskSection = () => { const disks = useDisksSelectors.use.disks(); + if (disks.length === 0) { + return ; + } + return ( <> {disks.map((disk) => ( @@ -90,25 +76,24 @@ const DiskSection = () => { ); }; -interface DashboardSectionsDividerProps { - label: string; +const TempsSection = () => { + const temps = []; + + if (temps.length === 0) { + return ; + } +}; + +interface DashboardNoDataAvailableProps { + message: string; } -const DashboardSectionsDivider = ({ label }: DashboardSectionsDividerProps) => { +const DashboardNoDataAvailable = ({ message }: DashboardNoDataAvailableProps) => { return ( - <> - - - - {label} - - - } - /> - - +
+ + {message} + +
); }; @@ -126,8 +111,9 @@ const DashboardPage = () => { - - + + + {/* */} );