Skip to content

Commit

Permalink
feat: Add uptime and arch fields to SysInfo model
Browse files Browse the repository at this point in the history
  • Loading branch information
pacholoamit committed Oct 15, 2024
1 parent 0ed8a0d commit 5ccbec9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions src-tauri/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -29,13 +30,21 @@ 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,
os,
os_version,
hostname,
core_count,
uptime,
arch,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
43 changes: 28 additions & 15 deletions src/components/system-information-widget.tsx
Original file line number Diff line number Diff line change
@@ -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));
Expand All @@ -17,44 +17,57 @@ const SystemInformationWidget: React.FC = () => {

return (
<Card height="">
<Grid>
<Grid.Col md={2} sm={6}>
<Grid align="center" justify="center">
<Grid.Col md={1.5} sm={6}>
<Text c="dimmed" size="sm" tt="uppercase" fw={700}>
CPU
</Text>
<Text size={"sm"}>{cpuBrand}</Text>
</Grid.Col>
<Grid.Col md={2} sm={6}>
<Grid.Col md={1.5} sm={6}>
<Text c="dimmed" size="sm" tt="uppercase" fw={700}>
OS
</Text>
<Text size={"sm"}>{info.os}</Text>
</Grid.Col>
<Grid.Col md={2} sm={6}>
<Grid.Col md={1.5} sm={6}>
<Text c="dimmed" size="sm" tt="uppercase" fw={700}>
Arch
</Text>
<Text size={"sm"}>{info.arch}</Text>
</Grid.Col>
<Grid.Col md={1.5} sm={6}>
<Text c="dimmed" size="sm" tt="uppercase" fw={700}>
CPU cores
</Text>
<Text size={"sm"}>{info.coreCount}</Text>
</Grid.Col>

<Grid.Col md={2} sm={6}>
<Grid.Col md={1.5} sm={6}>
<Text c="dimmed" size="sm" tt="uppercase" fw={700}>
Kernel
</Text>
<Text size={"sm"}>{info.kernelVersion}</Text>
</Grid.Col>
<Grid.Col md={2} sm={6}>
<Grid.Col md={1.5} sm={6}>
<Text c="dimmed" size="sm" tt="uppercase" fw={700}>
Memory
</Text>
<Text size={"sm"}>{formatBytes(memory)}</Text>
</Grid.Col>
<Grid.Col md={2} sm={6}>
<Grid.Col md={1.5} sm={6}>
<Text c="dimmed" size="sm" tt="uppercase" fw={700}>
Swap
</Text>
<Text size={"sm"}>{formatBytes(swap)}</Text>
</Grid.Col>

<Grid.Col md={1.5} sm={6}>
<Text c="dimmed" size="sm" tt="uppercase" fw={700}>
Uptime
</Text>
<Text size={"sm"}>{info.uptime}</Text>
</Grid.Col>
</Grid>
</Card>
);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bindings/SysInfo.ts
Original file line number Diff line number Diff line change
@@ -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, };
export type SysInfo = { kernelVersion: string, os: string, osVersion: string, hostname: string, coreCount: number, uptime: string, arch: string, };

0 comments on commit 5ccbec9

Please sign in to comment.