From 3085012ab1fe870e1e35e80f6693cd3716b16200 Mon Sep 17 00:00:00 2001 From: Alvin-Zilverstand <524715@vistacollege.nl> Date: Wed, 9 Sep 2026 10:45:52 +0200 Subject: [PATCH] Add live process game detection --- src-tauri/src/main.rs | 23 +++++++++++++++++++++++ src/game_watcher.rs | 31 +++++++++++++++++++++++++++++++ src/lib.rs | 1 + ui/src/main.ts | 17 +++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 src/game_watcher.rs diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index c376a82..6104d3d 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -4,6 +4,7 @@ use clipforge::capture::{ }; use clipforge::database::ClipDatabase; use clipforge::game_detection::{default_profiles, detect_game}; +use clipforge::game_watcher::running_processes; use clipforge::media::{ collect_segments, concat_segments, generate_thumbnail, prune_old_segments, recent_segments, trim_clip as ffmpeg_trim_clip, @@ -75,6 +76,27 @@ fn get_status(runtime: State<'_, AppRuntime>) -> Result { Ok(status_from_recorder(&recorder, capture.as_ref())) } +#[tauri::command] +fn refresh_detected_game(runtime: State<'_, AppRuntime>) -> Result { + let mut recorder = runtime.recorder.lock().map_err(|error| error.to_string())?; + let capture = runtime.capture.lock().map_err(|error| error.to_string())?; + let detected = detect_game(&running_processes(), &default_profiles()); + + match detected { + Some(game) => { + if recorder.state.detected_game_id.as_deref() != Some(&game.game_id) { + recorder.start_for_game(game.game_id, SystemTime::now()); + } + } + None if capture.is_none() => { + let _ = recorder.stop(); + } + None => {} + } + + Ok(status_from_recorder(&recorder, capture.as_ref())) +} + #[tauri::command] fn list_clips(runtime: State<'_, AppRuntime>) -> Result, String> { let recorder = runtime.recorder.lock().map_err(|error| error.to_string())?; @@ -387,6 +409,7 @@ fn main() { }) .invoke_handler(tauri::generate_handler![ get_status, + refresh_detected_game, list_clips, save_manual_clip, start_capture, diff --git a/src/game_watcher.rs b/src/game_watcher.rs new file mode 100644 index 0000000..1bdd707 --- /dev/null +++ b/src/game_watcher.rs @@ -0,0 +1,31 @@ +use crate::game_detection::RunningProcess; +use sysinfo::System; + +pub fn running_processes() -> Vec { + let mut system = System::new_all(); + system.refresh_all(); + system + .processes() + .iter() + .map(|(pid, process)| RunningProcess { + pid: pid.as_u32(), + process_name: process.name().to_string_lossy().to_string(), + executable_path: process + .exe() + .map(|path| path.display().to_string()) + .unwrap_or_default(), + window_title: None, + }) + .collect() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn process_snapshot_is_available() { + let processes = running_processes(); + assert!(!processes.is_empty()); + } +} diff --git a/src/lib.rs b/src/lib.rs index 6f1cc07..08dd642 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ pub mod capture; pub mod database; pub mod game_detection; +pub mod game_watcher; pub mod hotkeys; pub mod integrations; pub mod jobs; diff --git a/ui/src/main.ts b/ui/src/main.ts index a749770..1a2c822 100644 --- a/ui/src/main.ts +++ b/ui/src/main.ts @@ -655,6 +655,20 @@ async function refreshClips() { } } +async function refreshStatus() { + if (!tauriInvoke) { + return; + } + + try { + const status = await tauriInvoke("refresh_detected_game"); + applyDesktopStatus(status); + render(); + } catch (error) { + console.warn("Could not refresh detected game", error); + } +} + function parseTimestamp(value: string) { const parts = value.trim().split(":").map(Number); if (parts.some((part) => Number.isNaN(part))) { @@ -687,6 +701,9 @@ async function loadDesktopBridge() { state.clips = clips.map(clipFromDto); state.selectedClipId = state.clips[0]?.id ?? ""; render(); + window.setInterval(() => { + void refreshStatus(); + }, 3_000); } catch (error) { console.warn("Tauri bridge unavailable", error); }