Add live process game detection

This commit is contained in:
Alvin-Zilverstand committed 2026-09-09 10:45:52 +02:00
1 parent af3e6c28e5
commit 3085012ab1
4 files changed
+72

No files matched your search

+23
View File
@@ -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<DesktopStatus, String> {
Ok(status_from_recorder(&recorder, capture.as_ref()))
}
#[tauri::command]
fn refresh_detected_game(runtime: State<'_, AppRuntime>) -> Result<DesktopStatus, String> {
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<Vec<ClipDto>, 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,
+31
View File
@@ -0,0 +1,31 @@
use crate::game_detection::RunningProcess;
use sysinfo::System;
pub fn running_processes() -> Vec<RunningProcess> {
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());
}
}
+1
View File
@@ -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;
+17
View File
@@ -655,6 +655,20 @@ async function refreshClips() {
}
}
async function refreshStatus() {
if (!tauriInvoke) {
return;
}
try {
const status = await tauriInvoke<DesktopStatus>("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);
}