From 568c02495c7f33cc132695c8f21c38ab09d3a406 Mon Sep 17 00:00:00 2001 From: Tickbase Date: Thu, 30 Apr 2026 20:59:22 +0200 Subject: [PATCH] scream api settings dialog #93 --- .../dialogs/ScreamAPISettingsDialog.tsx | 209 ++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 src/components/dialogs/ScreamAPISettingsDialog.tsx diff --git a/src/components/dialogs/ScreamAPISettingsDialog.tsx b/src/components/dialogs/ScreamAPISettingsDialog.tsx new file mode 100644 index 0000000..8a984ef --- /dev/null +++ b/src/components/dialogs/ScreamAPISettingsDialog.tsx @@ -0,0 +1,209 @@ +import { useState, useEffect, useCallback } from 'react' +import { invoke } from '@tauri-apps/api/core' +import { + Dialog, + DialogHeader, + DialogBody, + DialogFooter, + DialogActions, +} from '@/components/dialogs' +import { Button, AnimatedCheckbox } from '@/components/buttons' +import { Dropdown, DropdownOption } from '@/components/common' + +interface ScreamAPIConfig { + $schema: string + $version: number + logging: boolean + log_eos: boolean + block_metrics: boolean + namespace_id: string + default_dlc_status: 'unlocked' | 'locked' | 'original' + override_dlc_status: Record + extra_graphql_endpoints: string[] + extra_entitlements: Record +} + +interface ScreamAPISettingsDialogProps { + visible: boolean + onClose: () => void + gamePath: string + gameTitle: string +} + +const DEFAULT_CONFIG: ScreamAPIConfig = { + $schema: + 'https://raw.githubusercontent.com/acidicoala/ScreamAPI/master/res/ScreamAPI.schema.json', + $version: 3, + logging: false, + log_eos: false, + block_metrics: false, + namespace_id: '', + default_dlc_status: 'unlocked', + override_dlc_status: {}, + extra_graphql_endpoints: [], + extra_entitlements: {}, +} + +const DLC_STATUS_OPTIONS: DropdownOption<'unlocked' | 'locked' | 'original'>[] = [ + { value: 'unlocked', label: 'Unlocked' }, + { value: 'locked', label: 'Locked' }, + { value: 'original', label: 'Original' }, +] + +const ScreamAPISettingsDialog = ({ + visible, + onClose, + gamePath, + gameTitle, +}: ScreamAPISettingsDialogProps) => { + const [enabled, setEnabled] = useState(false) + const [config, setConfig] = useState(DEFAULT_CONFIG) + const [isLoading, setIsLoading] = useState(false) + const [hasChanges, setHasChanges] = useState(false) + + const loadConfig = useCallback(async () => { + setIsLoading(true) + try { + const existingConfig = await invoke('read_screamapi_config', { + gamePath, + }) + if (existingConfig) { + setConfig(existingConfig) + setEnabled(true) + } else { + setConfig(DEFAULT_CONFIG) + setEnabled(false) + } + setHasChanges(false) + } catch (error) { + console.error('Failed to load ScreamAPI config:', error) + setConfig(DEFAULT_CONFIG) + setEnabled(false) + } finally { + setIsLoading(false) + } + }, [gamePath]) + + useEffect(() => { + if (visible && gamePath) { + loadConfig() + } + }, [visible, gamePath, loadConfig]) + + const handleSave = async () => { + setIsLoading(true) + try { + if (enabled) { + await invoke('write_screamapi_config', { gamePath, config }) + } else { + await invoke('delete_screamapi_config', { gamePath }) + } + setHasChanges(false) + onClose() + } catch (error) { + console.error('Failed to save ScreamAPI config:', error) + } finally { + setIsLoading(false) + } + } + + const handleCancel = () => { + setHasChanges(false) + onClose() + } + + const updateConfig = (key: K, value: ScreamAPIConfig[K]) => { + setConfig((prev) => ({ ...prev, [key]: value })) + setHasChanges(true) + } + + return ( + + +
+

ScreamAPI Settings

+
+

{gameTitle}

+
+ + +
+
+ { + setEnabled(!enabled) + setHasChanges(true) + }} + label="Enable ScreamAPI Configuration" + sublabel="Enable this to customise ScreamAPI settings for this game" + /> +
+ +
+
+

General Settings

+ + updateConfig('default_dlc_status', value)} + disabled={!enabled} + /> +
+ +
+

Logging

+ +
+ updateConfig('logging', !config.logging)} + label="Enable Logging" + sublabel="Enables logging to ScreamAPI.log.log file" + /> +
+ +
+ updateConfig('log_eos', !config.log_eos)} + label="Log EOS SDK" + sublabel="Intercept and log EOS SDK calls (requires logging enabled)" + /> +
+
+ +
+

Privacy

+ +
+ updateConfig('block_metrics', !config.block_metrics)} + label="Block Metrics" + sublabel="Block game analytics/usage reporting to Epic Online Services" + /> +
+
+
+
+
+ + + + + + + +
+ ) +} + +export default ScreamAPISettingsDialog \ No newline at end of file