Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
c5b1789
feat: implement hardware monitoring updates with event listener and r…
shm11C3 Mar 7, 2026
4da4e6e
fix: round GPU usage value in hardware update emission
shm11C3 Mar 7, 2026
f931703
refactor: simplify type definitions for process history in archive se…
shm11C3 Mar 7, 2026
e209126
refactor: clean up formatting and improve readability in monitoring s…
shm11C3 Mar 7, 2026
942e856
refactor: streamline import statements in useHardwareData test file
shm11C3 Mar 7, 2026
8900b5e
refactor: standardize comment language in useHardwareEventListener te…
shm11C3 Mar 8, 2026
2397094
refactor: update pad function to handle nullable number arrays in use…
shm11C3 Mar 8, 2026
994ab5f
refactor: improve error handling in emit_hardware_update function
shm11C3 Mar 8, 2026
3cc069a
refactor: simplify gpuUsageSource assignment in useHardwareEventListener
shm11C3 Mar 8, 2026
89ddece
Update src-tauri/src/services/monitoring_service.rs
shm11C3 Mar 8, 2026
6520b70
refactor: extract padHistory function and simplify hardware update ha…
shm11C3 Mar 8, 2026
f29f106
refactor: enhance HardwareMonitorUpdate with GPU details and update r…
shm11C3 Mar 8, 2026
13c85ff
refactor: enhance GPU monitoring with cooler level and dedicated memo…
shm11C3 Mar 8, 2026
2250db1
refactor: remove unused GPU cooler functions and related tests
shm11C3 Mar 8, 2026
c4900c2
refactor: remove GPU memory usage command and related logic
shm11C3 Mar 8, 2026
cd85397
refactor: implement get_gpu_memory_usage method for WindowsPlatform a…
shm11C3 Mar 8, 2026
ed938e9
refactor: add get_gpu_memory_usage command and update related documen…
shm11C3 Mar 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions src-tauri/src/commands/hardware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@ pub async fn get_gpu_temperature(
}

///
/// ## Get realtime GPU memory usage (best-effort)
///
/// This command attempts to retrieve current GPU memory usage information
/// on a best-effort, platform-dependent basis.
/// ## Get CPU usage history
///
/// - param state: `tauri::State<AppState>` Application state
/// - param seconds: `u32` Number of seconds to retrieve
/// - **Platform support**: Currently implemented only on macOS. On other
/// platforms, or where the underlying APIs are not available, this will
/// return `Ok(None)` instead of failing.
Expand All @@ -143,21 +142,10 @@ pub async fn get_gpu_memory_usage()
}

///
/// ## Get GPU fan speed
///
#[command]
#[specta::specta]
pub async fn get_nvidia_gpu_cooler() -> Result<Vec<models::hardware::NameValue>, String> {
use crate::services::gpu_service;

gpu_service::fetch_nvidia_gpu_cooler().await
}

///
/// ## Get CPU usage history
/// ## Get realtime GPU memory usage (best-effort)
///
/// - param state: `tauri::State<AppState>` Application state
/// - param seconds: `u32` Number of seconds to retrieve
/// This command attempts to retrieve current GPU memory usage information
/// on a best-effort, platform-dependent basis.
Comment on lines 144 to +148

Copilot AI Mar 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc comment above get_cpu_usage_history describes “realtime GPU memory usage” (best-effort), but this function returns CPU usage history. Please correct the doc comment (and then regenerate src/rspc/bindings.ts) to avoid misleading API docs for frontend callers.

Copilot uses AI. Check for mistakes.
///
#[command]
#[specta::specta]
Expand Down
17 changes: 17 additions & 0 deletions src-tauri/src/infrastructure/providers/windows/nvapi_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,23 @@ pub fn get_gpu_temperature_from_physical_gpu(gpu: &nvapi::PhysicalGpu) -> i32 {
0
}

///
/// Get GPU cooler level (fan speed %) from `PhysicalGpu`
///
pub fn get_gpu_cooler_level_from_physical_gpu(gpu: &nvapi::PhysicalGpu) -> Option<u32> {
match gpu.cooler_settings(None) {
Ok(coolers) => coolers.first().map(|c| c.current_level.0),
Err(e) => {
log_debug!(
"cooler_settings_failed",
"get_gpu_cooler_level",
Some(&format!("{e:?}"))
);
None
}
}
}

///
/// Get GPU memory usage from `PhysicalGpu`
///
Expand Down
106 changes: 54 additions & 52 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use commands::updater::app_updates;
use tauri::Manager;
use tauri::Wry;
use tauri_plugin_autostart::MacosLauncher;
use tauri_specta::{Builder, collect_commands};
use tauri_specta::{Builder, collect_commands, collect_events};

use std::collections::{HashMap, VecDeque};
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -61,57 +61,58 @@ pub fn run() {

let migrations = infrastructure::database::migration::get_migrations();

let builder = Builder::<tauri::Wry>::new().commands(collect_commands![
app_updates::fetch_update,
app_updates::install_update,
hardware::get_process_list,
hardware::get_cpu_usage,
hardware::get_hardware_info,
hardware::get_memory_info_detail,
hardware::get_memory_usage,
hardware::get_gpu_usage,
hardware::get_processors_usage,
hardware::get_gpu_temperature,
hardware::get_nvidia_gpu_cooler,
hardware::get_cpu_usage_history,
hardware::get_memory_usage_history,
hardware::get_gpu_usage_history,
hardware::get_network_info,
hardware::get_gpu_memory_usage,
settings::commands::get_settings,
settings::commands::set_language,
settings::commands::set_theme,
settings::commands::set_display_targets,
settings::commands::set_graph_size,
settings::commands::set_line_graph_type,
settings::commands::set_line_graph_border,
settings::commands::set_line_graph_fill,
settings::commands::set_line_graph_color,
settings::commands::set_line_graph_mix,
settings::commands::set_line_graph_show_legend,
settings::commands::set_line_graph_show_scale,
settings::commands::set_line_graph_show_tooltip,
settings::commands::set_background_img_opacity,
settings::commands::set_selected_background_img,
settings::commands::set_temperature_unit,
settings::commands::set_hardware_archive_enabled,
settings::commands::set_hardware_archive_interval,
settings::commands::set_hardware_archive_scheduled_data_deletion,
settings::commands::set_burn_in_shift,
settings::commands::set_burn_in_shift_mode,
settings::commands::set_burn_in_shift_preset,
settings::commands::set_burn_in_shift_idle_only,
settings::commands::set_burn_in_shift_options,
settings::commands::read_license_file,
settings::commands::read_third_party_notices_file,
settings::commands::open_license_file_path,
background_image::get_background_image,
background_image::get_background_images,
background_image::save_background_image,
background_image::delete_background_image,
ui::set_decoration,
system::restart_app,
]);
let builder = Builder::<tauri::Wry>::new()
.events(collect_events![models::hardware::HardwareMonitorUpdate,])
.commands(collect_commands![
app_updates::fetch_update,
app_updates::install_update,
hardware::get_process_list,
hardware::get_cpu_usage,
hardware::get_hardware_info,
hardware::get_memory_info_detail,
hardware::get_memory_usage,
hardware::get_gpu_usage,
hardware::get_processors_usage,
hardware::get_gpu_temperature,
hardware::get_cpu_usage_history,
hardware::get_memory_usage_history,
hardware::get_gpu_usage_history,
hardware::get_network_info,
hardware::get_gpu_memory_usage,
settings::commands::get_settings,
settings::commands::set_language,
settings::commands::set_theme,
settings::commands::set_display_targets,
settings::commands::set_graph_size,
settings::commands::set_line_graph_type,
settings::commands::set_line_graph_border,
settings::commands::set_line_graph_fill,
settings::commands::set_line_graph_color,
settings::commands::set_line_graph_mix,
settings::commands::set_line_graph_show_legend,
settings::commands::set_line_graph_show_scale,
settings::commands::set_line_graph_show_tooltip,
settings::commands::set_background_img_opacity,
settings::commands::set_selected_background_img,
settings::commands::set_temperature_unit,
settings::commands::set_hardware_archive_enabled,
settings::commands::set_hardware_archive_interval,
settings::commands::set_hardware_archive_scheduled_data_deletion,
settings::commands::set_burn_in_shift,
settings::commands::set_burn_in_shift_mode,
settings::commands::set_burn_in_shift_preset,
settings::commands::set_burn_in_shift_idle_only,
settings::commands::set_burn_in_shift_options,
settings::commands::read_license_file,
settings::commands::read_third_party_notices_file,
settings::commands::open_license_file_path,
background_image::get_background_image,
background_image::get_background_images,
background_image::save_background_image,
background_image::delete_background_image,
ui::set_decoration,
system::restart_app,
]);

// TS bindings
#[cfg(debug_assertions)]
Expand Down Expand Up @@ -147,6 +148,7 @@ pub fn run() {
gpu_temperature_histories: Arc::clone(&gpu_temperature_histories),
gpu_dedicated_memory_histories: Arc::clone(&gpu_dedicated_memory_histories),
},
app.handle().clone(),
);
{
let ws = app.state::<workers::WorkersState>();
Expand Down
14 changes: 14 additions & 0 deletions src-tauri/src/models/hardware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ use std::collections::{HashMap, VecDeque};
use std::sync::{Arc, Mutex};
use sysinfo;

#[derive(Debug, Clone, serde::Serialize, specta::Type, tauri_specta::Event)]
#[serde(rename_all = "camelCase")]
pub struct HardwareMonitorUpdate {
pub cpu_usage: f32,
pub memory_usage: f32,
pub gpu_usage: Option<f32>,
pub gpu_name: Option<String>,
pub gpu_temperature: Option<f32>,
pub gpu_source: Option<String>,
pub processors_usage: Vec<f32>,
pub gpu_dedicated_memory_usage_kb: Option<f32>,
pub gpu_cooler_level: Option<u32>,
}

pub struct HardwareMonitorState {
pub system: Arc<Mutex<sysinfo::System>>,
pub cpu_history: Arc<Mutex<VecDeque<f32>>>,
Expand Down
15 changes: 7 additions & 8 deletions src-tauri/src/services/archive_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::{

const PROCESS_RECORD_LIMIT: usize = 5;

type ProcessHistory = Arc<Mutex<HashMap<sysinfo::Pid, VecDeque<f32>>>>;

#[derive(Debug, Clone, Copy)]
enum ProcessRankingMetric {
Cpu,
Expand All @@ -32,8 +34,8 @@ struct GpuMetricsCollector<'a> {

/// Process statistics collector and ranker
struct ProcessStatsCollector<'a> {
cpu_histories: &'a Arc<Mutex<HashMap<sysinfo::Pid, VecDeque<f32>>>>,
memory_histories: &'a Arc<Mutex<HashMap<sysinfo::Pid, VecDeque<f32>>>>,
cpu_histories: &'a ProcessHistory,
memory_histories: &'a ProcessHistory,
}

impl ArchiveService {
Expand Down Expand Up @@ -302,8 +304,8 @@ impl<'a> GpuMetricsCollector<'a> {

impl<'a> ProcessStatsCollector<'a> {
fn new(
cpu_histories: &'a Arc<Mutex<HashMap<sysinfo::Pid, VecDeque<f32>>>>,
memory_histories: &'a Arc<Mutex<HashMap<sysinfo::Pid, VecDeque<f32>>>>,
cpu_histories: &'a ProcessHistory,
memory_histories: &'a ProcessHistory,
) -> Self {
Self {
cpu_histories,
Expand Down Expand Up @@ -459,10 +461,7 @@ mod tests {
}
}

fn dummy_process_collector() -> (
Arc<Mutex<HashMap<sysinfo::Pid, VecDeque<f32>>>>,
Arc<Mutex<HashMap<sysinfo::Pid, VecDeque<f32>>>>,
) {
fn dummy_process_collector() -> (ProcessHistory, ProcessHistory) {
(
Arc::new(Mutex::new(HashMap::new())),
Arc::new(Mutex::new(HashMap::new())),
Expand Down
8 changes: 0 additions & 8 deletions src-tauri/src/services/gpu_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ pub async fn fetch_gpu_temperature(
.map_err(|e| format!("Failed to get GPU temperature: {e:?}"))
}

///
/// Get NVIDIA GPU fan speed (not implemented)
/// Always returns Err as planned for future implementation
///
pub async fn fetch_nvidia_gpu_cooler() -> Result<Vec<NameValue>, String> {
Err("Failed to get GPU cooler status: This function is not implemented".to_string())
}

///
/// Get realtime GPU memory usage (best-effort).
///
Expand Down
Loading
Loading