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