Generate Valve GSI config templates
This commit is contained in:
1 parent
3e6a5695ee
commit
14bb5009c6
4 files changed
+157
No files matched your search
@@ -5,6 +5,7 @@ use clipforge::capture::{
|
|||||||
use clipforge::database::ClipDatabase;
|
use clipforge::database::ClipDatabase;
|
||||||
use clipforge::game_detection::{default_profiles, detect_game};
|
use clipforge::game_detection::{default_profiles, detect_game};
|
||||||
use clipforge::game_watcher::running_processes;
|
use clipforge::game_watcher::running_processes;
|
||||||
|
use clipforge::gsi_config::write_gsi_config_templates;
|
||||||
use clipforge::integrations::{
|
use clipforge::integrations::{
|
||||||
valve_gsi_raw_events, GameIntegration, IntegrationError, LeagueIntegration,
|
valve_gsi_raw_events, GameIntegration, IntegrationError, LeagueIntegration,
|
||||||
LeagueLiveClientPoller, RawGameEvent, ValveGsiIntegration,
|
LeagueLiveClientPoller, RawGameEvent, ValveGsiIntegration,
|
||||||
@@ -83,6 +84,12 @@ struct ClipDto {
|
|||||||
color_class: String,
|
color_class: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
struct GsiConfigDto {
|
||||||
|
game_id: String,
|
||||||
|
path: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn get_status(runtime: State<'_, AppRuntime>) -> Result<DesktopStatus, String> {
|
fn get_status(runtime: State<'_, AppRuntime>) -> Result<DesktopStatus, String> {
|
||||||
let recorder = runtime.recorder.lock().map_err(|error| error.to_string())?;
|
let recorder = runtime.recorder.lock().map_err(|error| error.to_string())?;
|
||||||
@@ -138,6 +145,21 @@ fn set_mic_enabled(enabled: bool, runtime: State<'_, AppRuntime>) -> Result<Desk
|
|||||||
Ok(status_from_recorder(&recorder, capture.as_ref()))
|
Ok(status_from_recorder(&recorder, capture.as_ref()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn write_gsi_configs(runtime: State<'_, AppRuntime>) -> Result<Vec<GsiConfigDto>, String> {
|
||||||
|
write_gsi_config_templates(&runtime.library_root)
|
||||||
|
.map_err(|error| format!("Could not write GSI configs: {error}"))
|
||||||
|
.map(|configs| {
|
||||||
|
configs
|
||||||
|
.into_iter()
|
||||||
|
.map(|config| GsiConfigDto {
|
||||||
|
game_id: config.game_id,
|
||||||
|
path: config.path.display().to_string(),
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn poll_auto_clip_events(runtime: State<'_, AppRuntime>) -> Result<Vec<ClipDto>, String> {
|
fn poll_auto_clip_events(runtime: State<'_, AppRuntime>) -> Result<Vec<ClipDto>, String> {
|
||||||
let (session_id, game_id, session_started_at) = {
|
let (session_id, game_id, session_started_at) = {
|
||||||
@@ -664,6 +686,7 @@ fn main() {
|
|||||||
list_clips,
|
list_clips,
|
||||||
set_replay_buffer,
|
set_replay_buffer,
|
||||||
set_mic_enabled,
|
set_mic_enabled,
|
||||||
|
write_gsi_configs,
|
||||||
poll_auto_clip_events,
|
poll_auto_clip_events,
|
||||||
save_manual_clip,
|
save_manual_clip,
|
||||||
start_capture,
|
start_capture,
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
use std::fs;
|
||||||
|
use std::io;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
pub const GSI_ENDPOINT: &str = "http://127.0.0.1:49321";
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct WrittenGsiConfig {
|
||||||
|
pub game_id: String,
|
||||||
|
pub path: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_gsi_config_templates(root: &Path) -> io::Result<Vec<WrittenGsiConfig>> {
|
||||||
|
let config_root = root.join("integrations").join("valve-gsi");
|
||||||
|
fs::create_dir_all(&config_root)?;
|
||||||
|
let cs2_path = config_root.join("gamestate_integration_clipforge_cs2.cfg");
|
||||||
|
let dota_path = config_root.join("gamestate_integration_clipforge_dota2.cfg");
|
||||||
|
fs::write(&cs2_path, cs2_config())?;
|
||||||
|
fs::write(&dota_path, dota2_config())?;
|
||||||
|
Ok(vec![
|
||||||
|
WrittenGsiConfig {
|
||||||
|
game_id: "counter-strike-2".to_string(),
|
||||||
|
path: cs2_path,
|
||||||
|
},
|
||||||
|
WrittenGsiConfig {
|
||||||
|
game_id: "dota-2".to_string(),
|
||||||
|
path: dota_path,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cs2_config() -> String {
|
||||||
|
format!(
|
||||||
|
r#""ClipForge"
|
||||||
|
{{
|
||||||
|
"uri" "{GSI_ENDPOINT}"
|
||||||
|
"timeout" "5.0"
|
||||||
|
"buffer" "0.1"
|
||||||
|
"throttle" "0.1"
|
||||||
|
"heartbeat" "30.0"
|
||||||
|
"data"
|
||||||
|
{{
|
||||||
|
"provider" "1"
|
||||||
|
"map" "1"
|
||||||
|
"round" "1"
|
||||||
|
"player_id" "1"
|
||||||
|
"player_state" "1"
|
||||||
|
"player_match_stats" "1"
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
"#
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn dota2_config() -> String {
|
||||||
|
format!(
|
||||||
|
r#""ClipForge"
|
||||||
|
{{
|
||||||
|
"uri" "{GSI_ENDPOINT}"
|
||||||
|
"timeout" "5.0"
|
||||||
|
"buffer" "0.1"
|
||||||
|
"throttle" "0.1"
|
||||||
|
"heartbeat" "30.0"
|
||||||
|
"data"
|
||||||
|
{{
|
||||||
|
"provider" "1"
|
||||||
|
"map" "1"
|
||||||
|
"player" "1"
|
||||||
|
"hero" "1"
|
||||||
|
"abilities" "1"
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
"#
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn templates_reference_local_receiver() {
|
||||||
|
assert!(cs2_config().contains(GSI_ENDPOINT));
|
||||||
|
assert!(dota2_config().contains(GSI_ENDPOINT));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn writes_templates() {
|
||||||
|
let root = std::env::temp_dir().join(format!(
|
||||||
|
"clipforge-gsi-{}",
|
||||||
|
std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.unwrap_or_default()
|
||||||
|
.as_millis()
|
||||||
|
));
|
||||||
|
|
||||||
|
let written = write_gsi_config_templates(&root).expect("write");
|
||||||
|
|
||||||
|
assert_eq!(written.len(), 2);
|
||||||
|
assert!(written.iter().all(|config| config.path.exists()));
|
||||||
|
let _ = fs::remove_dir_all(root);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ pub mod capture;
|
|||||||
pub mod database;
|
pub mod database;
|
||||||
pub mod game_detection;
|
pub mod game_detection;
|
||||||
pub mod game_watcher;
|
pub mod game_watcher;
|
||||||
|
pub mod gsi_config;
|
||||||
pub mod hotkeys;
|
pub mod hotkeys;
|
||||||
pub mod integrations;
|
pub mod integrations;
|
||||||
pub mod jobs;
|
pub mod jobs;
|
||||||
|
|||||||
@@ -66,6 +66,11 @@ type ClipDto = {
|
|||||||
color_class: string;
|
color_class: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type GsiConfigDto = {
|
||||||
|
game_id: string;
|
||||||
|
path: string;
|
||||||
|
};
|
||||||
|
|
||||||
type AppState = {
|
type AppState = {
|
||||||
activeView: "Library" | "Recording" | "Auto Clip" | "Uploads" | "Settings";
|
activeView: "Library" | "Recording" | "Auto Clip" | "Uploads" | "Settings";
|
||||||
recordingState: RecordingState;
|
recordingState: RecordingState;
|
||||||
@@ -82,6 +87,7 @@ type AppState = {
|
|||||||
uploadProvider: "catbox" | "litterbox" | "custom_http" | "lustful";
|
uploadProvider: "catbox" | "litterbox" | "custom_http" | "lustful";
|
||||||
customUploadEndpoint: string;
|
customUploadEndpoint: string;
|
||||||
customUploadResponsePath: string;
|
customUploadResponsePath: string;
|
||||||
|
gsiConfigStatus: string;
|
||||||
selectedClipId: string;
|
selectedClipId: string;
|
||||||
clips: Clip[];
|
clips: Clip[];
|
||||||
autoEvents: AutoEvent[];
|
autoEvents: AutoEvent[];
|
||||||
@@ -118,6 +124,7 @@ const state: AppState = {
|
|||||||
uploadProvider: "catbox",
|
uploadProvider: "catbox",
|
||||||
customUploadEndpoint: "",
|
customUploadEndpoint: "",
|
||||||
customUploadResponsePath: "url",
|
customUploadResponsePath: "url",
|
||||||
|
gsiConfigStatus: "",
|
||||||
selectedClipId: "clip-1",
|
selectedClipId: "clip-1",
|
||||||
clips: [
|
clips: [
|
||||||
{
|
{
|
||||||
@@ -403,6 +410,10 @@ function renderAutoClipView() {
|
|||||||
)
|
)
|
||||||
.join("")}
|
.join("")}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<button data-action="write-gsi-configs">Write GSI Configs</button>
|
||||||
|
</div>
|
||||||
|
${state.gsiConfigStatus ? `<p class="muted file-path">${state.gsiConfigStatus}</p>` : ""}
|
||||||
</section>
|
</section>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@@ -493,6 +504,10 @@ function bindEvents() {
|
|||||||
void uploadSelectedClip();
|
void uploadSelectedClip();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
appRoot.querySelector<HTMLButtonElement>("[data-action='write-gsi-configs']")?.addEventListener("click", () => {
|
||||||
|
void writeGsiConfigs();
|
||||||
|
});
|
||||||
|
|
||||||
appRoot.querySelector<HTMLButtonElement>("[data-action='delete']")?.addEventListener("click", () => {
|
appRoot.querySelector<HTMLButtonElement>("[data-action='delete']")?.addEventListener("click", () => {
|
||||||
void deleteSelectedClip();
|
void deleteSelectedClip();
|
||||||
});
|
});
|
||||||
@@ -677,6 +692,21 @@ async function uploadSelectedClip() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function writeGsiConfigs() {
|
||||||
|
if (!tauriInvoke) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const configs = await tauriInvoke<GsiConfigDto[]>("write_gsi_configs");
|
||||||
|
state.gsiConfigStatus = configs.map((config) => `${config.game_id}: ${config.path}`).join(" · ");
|
||||||
|
render();
|
||||||
|
} catch (error) {
|
||||||
|
state.gsiConfigStatus = `Could not write GSI configs: ${String(error)}`;
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function deleteSelectedClip() {
|
async function deleteSelectedClip() {
|
||||||
if (!tauriInvoke || !state.selectedClipId) {
|
if (!tauriInvoke || !state.selectedClipId) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in new issue
Block a user